Rename a file
@param \gplcart\core\Controller $controller
@return array
178948
public function submit($controller)
    {
        set_time_limit(0);

        $submitted = $controller->getSubmitted();
        $file = reset($submitted['files']);

        $path = $file->getRealPath();
        $destination = $controller->getSubmitted('destination');

        $query = array(
            'cmd' => 'list',
            'path' => $this->getRelativeDirectory($path)
        );

        $errors = $success = 0;
        $this->move($path, $destination, $errors, $success);

        $vars = array('@num_success' => $success, '@num_errors' => $errors);

        return array(
            'redirect' => $controller->url('', $query),
            'severity' => empty($errors) ? 'success' : 'warning',
            'message' => $this->translation->text('Renamed @num_success, errors: @num_errors', $vars)
        );
    }
553558
public function startup(Controller $controller) {
        if ($controller instanceof CakeErrorController) {
            return;
        }

        // Backwards support
        if (isset($this->settings)) {
            $this->_set($this->settings);
        }

        // Detect cookie or login
        $cookie = $this->read();
        $user = $this->Auth->user();

        if (!$this->active || !empty($user) || !$controller->request->is('get')) {
            return;

        } else if ($cookie === null) {
            $this->debug('cookieFail', $this->Cookie, $user);
            $this->delete();
            return;

        } else if (empty($cookie['hash']) || $cookie['hash'] !== $this->Auth->password($cookie['username'] . $cookie['time'])) {
            $this->debug('hashFail', $this->Cookie, $user);
            $this->delete();
            return;
        }

        // Set the data to identify with
        $controller->request->data[$this->model][$this->username] = $cookie['username'];
        $controller->request->data[$this->model][$this->password] = $cookie['password'];

        if ($this->Auth->login()) {
            $this->debug('login', $this->Cookie, $this->Auth->user());

            if (in_array('_autoLogin', get_class_methods($controller))) {
                call_user_func(array($controller, '_autoLogin'), $this->Auth->user());
            }

            if ($this->redirect) {
                $controller->redirect($controller->referer($this->Auth->redirect()), 302);
            }
        } else {
            $this->debug('loginFail', $this->Cookie, $this->Auth->user());

            if (in_array('_autoLoginError', get_class_methods($controller))) {
                call_user_func(array($controller, '_autoLoginError'), $this->read());
            }
        }
    }
660431
public function rename($newFilename, $context = null)
    {
        $params[] = $this->getRealPath();
        $params[] = dirname($this->getRealPath()) . DIRECTORY_SEPARATOR . $newFilename;
        $params[] = $context;

        return call_user_func_array('rename', $params);
    }
1304169
protected function _getCommands($controller)
    {
        $commands = [];
        try {
            $controllerClassName = $this->_getControllerClassName($controller);

            if (!class_exists($controllerClassName)) {
                return [];
            }

            foreach ((new \ReflectionClass($controllerClassName))->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
                if (!$method->isStatic() && $method->isPublic() && preg_match('#^(.*)Command$#', $method->getShortName(), $matches) === 1) {
                    $commands[] = Text::underscore($matches[1]);
                }
            }
        } catch (\Exception $e) {

        }

        return $commands;
    }
490677
protected function makeDirectory($controller, $path)
	{
		$directory = $this->getDirectory($controller);

		if ( ! $this->files->isDirectory($full = $path.'/'.$directory))
		{
			$this->files->makeDirectory($full, 0777, true);
		}
	}
1124240
public function resolveController($controller)
    {
        $callable = false;

        if (false !== strpos($controller, '::')) {
            list($controller_class, $method) = explode('::', $controller, 2);

            if (class_exists($controller_class)) {

                // Create controller class, and make sure method is callable
                $callable = array(new $controller_class(), $method);
                $callable = (is_callable($callable)) ? $callable : false;
            }
        }

        return($callable);
    }
908898
private function cleanController($controller, $class)
  {
    if ($class == '') {
      if ($this->resource == true) {
        $contents = str_replace('
use Modulus\Http\Request;
use App\Http\Controllers\Controller;
', '
use Modulus\Http\Request;
', file_get_contents($controller));

        return file_put_contents($controller, $contents);
      }

      $contents = str_replace('

use App\Http\Controllers\Controller;', '', file_get_contents($controller));

      return file_put_contents($controller, $contents);
    }
  }
254965
public function rename($name)
    {
        $name = Str::slug($name);
        if ($this->isFile()) {
            return $this->renameFile($name, $this->getMetaData()->getExtension());
        }

        return $this->renameFolder($name);
    }
504487
protected function makeController($controller)
    {
        Controller::setRouter($this->router);

        $controller = $this->container->make($controller);

        if ( ! $controller instanceof AdminPageController)
        {
            if ($this->container->isShared('post'))
            {
                $controller->setPost($this->container['post']);
            }

            $controller->setQuery($this->container['query']);
        }

        if (method_exists($controller, 'boot'))
        {
            $this->container->call([$controller, 'boot']);
        }

        return $controller;
    }
891221
protected function createController($controller)
    {
        if (false === strpos($controller, '::')) {
            throw new \InvalidArgumentException(sprintf('Unable to find controller "%s".', $controller));
        }

        list($class, $method) = explode('::', $controller, 2);

        if (!class_exists($class)) {
            throw new \InvalidArgumentException(sprintf('Class "%s" does not exist.', $class));
        }

        $controller = new $class();
        if ($controller instanceof ContainerAwareInterface) {
            $controller->setContainer($this->container);
        }

        if ($this->container->has('dashboard.view')) {
            $view = $this->container->get('dashboard.view');
            $loader = $view->getLoader();

            if ($path = $this->getViewsPath($controller, $this->container->getParameter('dashboard.widgets_dir'))) {
                $loader->addPath($path);
                $view->setLoader($loader);
                $this->container->set('view', $view);
            }
        }

        return array($controller, $method);
    }
1001953
public function initialize(Controller $controller) {
		$this->_controller = $controller;
		$isAppInstalled = $this->isAppInstalled();
		if (($this->_controller->request->param('plugin') !== 'cake_installer') ||
			($this->_controller->request->param('controller') !== 'check') ||
			($this->_controller->request->param('action') !== 'index')) {
			if (!$isAppInstalled) {
				$urlRedirect = ['controller' => 'check', 'action' => 'index', 'plugin' => 'cake_installer'];
				$this->_controller->redirect($urlRedirect);
			}
		}
	}
722532
protected function _getArgumentNames($controller, $command)
    {
        $controllerClassName = $this->_getControllerClassName($controller);
        if (!class_exists($controllerClassName)) {
            return [];
        }

        $command = Text::camelize($command) . 'Command';
        if (!method_exists($controllerClassName, $command)) {
            return [];
        }

        $arguments = [];
        foreach ((new \ReflectionMethod($controllerClassName, $command))->getParameters() as $parameter) {
            $arguments[] = '--' . strtr($parameter->name, '_', '-');
        }

        return $arguments;
    }
854038
protected function setAssets(Controller $controller)
    {
        $controller->addAssetLibrary('jquery_ui');
        $controller->addAssetLibrary('bootstrap');
        $controller->addAssetLibrary('html5shiv', array('condition' => 'if lt IE 9'));
        $controller->addAssetLibrary('respond', array('condition' => 'if lt IE 9'));
        $controller->addAssetLibrary('font_awesome');

        $controller->setJs(__DIR__ . '/js/common.js');
        $controller->setCss(__DIR__ . '/css/common.css');
    }
1144860
public function initialize(Controller $controller) {
		$this->_controller = $controller;
		if (!$this->_controller->Components->loaded('RequestHandler')) {
			$this->_controller->RequestHandler = $this->_controller->Components->load('RequestHandler');
			$this->_controller->RequestHandler->initialize($this->_controller);
		}
		if (!$this->_controller->Components->loaded('Session')) {
			$this->_controller->Session = $this->_controller->Components->load('Session');
			$this->_controller->Session->initialize($this->_controller);
		}
		if ($this->_controller->Auth->loggedIn() ||
			$this->_controller->RequestHandler->prefers('json')) {
			return;
		}

		$isAuthCfg = $this->_modelSetting->isAuthGroupConfigured();
		if ($isAuthCfg) {
			if ($this->_controller->Session->read('Settings.FirstLogon')) {
				$this->_controller->Session->delete('Settings.FirstLogon');

				return $this->_controller->redirect($this->_controller->Auth->logout());
			}

			return;
		}

		$pluginName = $this->_controller->request->param('plugin');
		$controllerName = $this->_controller->request->param('controller');
		$actionName = $this->_controller->request->param('action');
		if (($pluginName !== 'cake_settings_app') ||
			($controllerName !== 'settings') ||
			($actionName !== 'index')) {
			return;
		}

		$this->_controller->Auth->allow('index');
		$this->_controller->Session->write('Settings.FirstLogon', true);
	}
1088456
public function setUrl($pageName, $controller)
    {
        $params = [
            'id'   => $this->id,
            'slug' => $this->slug
        ];

        return $this->url = $controller->pageUrl($pageName, $params, false);
    }
1236764
public function startup(Controller $controller) {
		if ($this->settings['isTest']) {
			return;
		}

		foreach ($this->routes as $route) {
			if (!$this->_parse($route['route'])) {
				continue;
			}

			if (!$this->_execute($route)) {
				break;
			}

			$this->Session->write('Sanction.referer', $this->request->here());
			return $this->redirect($controller, $route);
		}
	}
59258
private function models($controller)
    {
        $properties = $controller::$properties;
        $module = $this->name($controller);

        $models = [];

        foreach ((array) U::array_value($properties, 'models') as $model) {
            $modelClassName = '\\app\\'.$module.'\\models\\'.$model;

            $info = $modelClassName::metadata();

            $models[ $model ] = array_replace($info, [
                'route_base' => '/'.$module.'/'.$info[ 'plural_key' ], ]);
        }

        return $models;
    }