Associate controller with the object.

@param string|object $controller Class or instance of controller
@param string|array  $name       Name or property for new controller

@return AbstractController Newly added controller
973453
public function setController($controller, $name = null)
    {
        $controller = $this->app->normalizeClassName($controller, 'Controller');

        return $this->add($controller, $name);
    }
523685
public function get($name, $path, $controller = null)
    {
        $this->add('GET', $name, $path, $controller);
        return $this;
    }
734842
public function getView($name)
    {
        if (!isset(self::$_controllers['view.'.$name])) {
            $view = $this->getController($name)->setView($name)->getView();
            self::$_controllers['view.'.$name] = $view;
        }

        return self::$_controllers['view.'.$name];
    }
553048
public function controller($controller = null)
    {
        if (!is_null($controller)) {
            $this->controller = $controller;
            return $this;
        } else {
            return $this->controller ?: '';
        }
    }
381681
protected function prepareCallController($controller, $newRequest)
    {
        $controller = parent::prepareCallController($controller, $newRequest);
        $controller->setView($this->getView());

        return $controller;
    }
1211508
public function findController($name)
	{
	    $allControllers = array_keys($this->controllers);
	    
	    $expr        = preg_replace_callback('{([^:]+|)}', function ($matches) {
	        return preg_quote($matches[1]) . '[^:]*';
	    }, $name);
	    
	    $controllers = preg_grep('{^' . $expr . '}', $allControllers);
	    
        if (empty($controllers) || count(preg_grep('{^' . $expr . '$}', $controllers)) < 1) {
            if (false !== $pos = strrpos($name, ':')) {
                $this->findControllerNamespace(substr($name, 0, $pos));
            }
            
            $message = sprintf('Controller "%s" is not defined.', $name);
            
            if ($alternatives = $this->findAlternatives($name, $allControllers)) {
                if (1 == count($alternatives)) {
                    $message .= "\n\nDid you mean this?\n    ";
                } else {
                    $message .= "\n\nDid you mean one of these?\n    ";
                }
                $message .= implode("\n    ", $alternatives);
            }
            
            throw new \InvalidArgumentException($message);
        }
        
        if (count($controllers) > 1) {
            $controllerList = $this->controllers;
            $controllers    = array_filter($controllers, function ($nameOrAlias) use ($controllerList, $controllers) {
                $controllerName = $controllerList[$nameOrAlias]->getName();
                
                return $controllerName === $nameOrAlias || !in_array($controllerName, $controllers);
            });
        }
        
        $exact = in_array($name, $controllers, true);
        if (count($controllers) > 1 && !$exact) {
            $suggestions = $this->getAbbreviationSuggestions(array_values($controllers));
            
            throw new \InvalidArgumentException(sprintf('Controller "%s" is ambiguous (%s).', $name, $suggestions));
        }
        
        return $this->getController($exact ? $name : reset($controllers));
	}
1322961
public function controller($controller)
    {

        // Instantiate a string controller
        if (is_string($controller)
            && class_exists($controller)
            && is_subclass_of($controller, 'Bkwld\Decoy\Controllers\Base')) {
            $this->controller_name = $controller;
            $this->controller = new $controller;

            // Apply the parent if one was set
            if ($this->parent_item && $this->controller) {
                $this->controller->parent($this->parent_item);
            }

        // Or, validate a passed controller instance
        } elseif (is_object($controller)
            && is_a($controller, 'Bkwld\Decoy\Controllers\Base')) {
            $this->controller_name = get_class($controller);
            $this->controller = $controller;
        }

        // Chain
        return $this;
    }
556099
protected function configureController(Controller $controller)
    {
        parent::configureController($controller);
        $controller[] = new Entity($this->entityName);
    }
166099
public function create(array $parameters, $controller = null) {
        $parameters = $this->parseParameters($parameters, $controller);

        $action = new Action(
            $parameters['name'],
            $parameters['pattern'],
            $parameters['uses'],
            $parameters['group']
        );

        $this->setProperties($action, $parameters);

        return $action;
    }
657485
public function getController($name)
    {
        $names = explode('_', $name);
        array_unshift($names, 'Controller');

        foreach ($this->application->config('controller.namespaces') as $ns) {
            $class = $ns . '\\' . join('\\', array_map('ucfirst', $names)) . 'Controller';
            if (class_exists($class)) {
                $controller = new $class();
                $controller->setContainer($this->getContainer());
                $this->getContainer()->injectDependency($controller);
                $controller->setName($name);
                return $controller;
            }
        }

        // not found.
        throw new NotFoundException();
    }
741929
public function findController(string $name)
    {
        foreach ($this->controllers as $controller) {
            if ($controller->getName() === $name) {
                return $controller;
            }
        }

        return null;
    }
826801
public function initController($controller, $path)
    {
        if($path)
        {
            $controller = $this->name . '\\Controller\\' . $path . '\\' . $controller;
        }
        else
        {
            $controller = $this->name . '\\Controller\\' . $controller;
        }

        return new $controller();
    }
628224
private function _controllerFor($name)
	{
		if(isset($this->_controllers[$name]) && is_string($this->_controllers[$name]))
		{
			return $this->_controllerFor($this->_controllers[$name]);
		}
		else if(isset($this->_controllers[$name]) && is_object($this->_controllers[$name]))
		{
			return $this->_controllers[$name];
		}
		else if(isset($this->_controllerFactory))
		{
			return $this->_controllerFactory->resolve($name);
		}
		else
		{
			throw new Exception("No controller found for $name");
		}
	}
640427
protected function createController($controller)
    {
        $this->checkClass($controller);
        $handler = Application::container()->make($controller);
        if (! $handler instanceof ControllerInterface) {
            throw new InvalidControllerException(
                "The class '{$controller}' does not implement ControllerInterface."
            );
        }
        return $handler;
    }
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);
	}
569770
public function setController($controller)
        {
            if (null !== $controller && !is_string($controller)) {
                throw new Exception(
                    'Invalid argument: $controller must be a string or null'
                );
            }

            $this->_controller = $controller;
            $this->_hrefCache  = null;

            return $this;
        }
1058073
protected function setAddRoute($controller, $action): Controller
    {
        $callTo = Inflector::classify($controller) . '@' . $action;

        $this->routes['get'] = array_merge($this->routes['get'], [
            "/$controller/$action/" => $callTo,
        ]);

        $this->routes['post'] = [
            "/$controller/$action/" => $callTo,
        ];

        return $this;
    }