Obtain controller.

@param $controllername
@return string
347631
protected function controller($controllername)
    {
        if (str_contains($controllername, '/')) {
            $controllername = str_replace('/', '\\', $controllername);
        }

        if (str_contains($controllername, '@')) {
            return ucfirst($controllername);
        }
        return ucfirst($controllername . '@index');
    }
506956
public function getActionDescription($controllerClassName, $actionName) {

        if (!class_exists($controllerClassName) || !method_exists($controllerClassName, $actionName)) {
            throw new ActionNotFoundException('Unknown '.$controllerClassName.'@'.$actionName);
        }

        $reflector = new \ReflectionMethod($controllerClassName, $actionName);
        return new ActionDescription($reflector);
    }
434251
public function canAccessController(string $controllerName): bool
    {
        if (!isset($this->controllerDefaults[$controllerName])) {
            return false;
        }
        $requiredRoles = $this->controllerDefaults[$controllerName];
        if (!$requiredRoles) {
            return true;
        }

        if (!$this->user) {
            return false;
        }

        foreach ($requiredRoles as $role) {
            if ($this->hasRoleWithName($role)) {
                return true;
            }
        }

        return false;
    }
931049
protected function controllerWithoutMethod($controllername)
    {
        if (str_contains($controller = $controllername, '@')) {
            return ucfirst(substr($controllername, 0, strpos($controllername, '@')));
        }
        return ucfirst($controllername);
    }
1305191
public function makeController($controllerName = null)
  {
    $controllerName = ucwords($_POST['command']);
    $this->controllerName = $controllerName;
    
    if (file_exists("App/Controllers/{$this->controllerName}Controller.php")) {
      $this->errors[] = "The {$this->controllerName}Controller already exists!";
    } elseif (strripos($this->controllerName, '_') == 0) {
      $this->controllerName = ucwords(str_replace('_', '', $this->controllerName));
    }
    
    if (!empty($this->errors)) {
      echo array_shift($this->errors);
    } else {
      $newControllerTemplate = file_get_contents(__DIR__ . '/templates/makeController.txt');
      $newController = str_replace('ControllerName', $this->controllerName, $newControllerTemplate);
      file_put_contents("App/Controllers/{$this->controllerName}Controller.php", $newController);
    }
  }
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));
	}
881928
public function getController()
    {
        if (isset($this->uris[0]) && '' !== $this->uris[0]) {
            $_controller = $this->uris[0];
        } else {
            throw new NotFoundException('Cannot dispatch controller name.');
        }

        return strip_tags($_controller);
    }
63058
protected function _controllerName()
    {
        $inflections = [
            'underscore',
            'humanize',
        ];

        if ($this->_action()->scope() === 'entity') {
            $inflections[] = 'singularize';
        }

        $baseName = $this->_controller()->getName();
        foreach ($inflections as $inflection) {
            $baseName = Inflector::$inflection($baseName);
        }

        return $baseName;
    }
741929
public function findController(string $name)
    {
        foreach ($this->controllers as $controller) {
            if ($controller->getName() === $name) {
                return $controller;
            }
        }

        return null;
    }
179568
public static function getControllerName($qualifiedControllerName)
    {
        $nsComponents = explode('\\', $qualifiedControllerName);
        $ctrlName = str_replace('Controller', '', end($nsComponents));

        return $ctrlName;
    }
1036757
protected function _getControllerClassName($controllerName)
    {
        if ($this->alias->has('@ns.cli')) {
            $controllerClassName = $this->alias->resolveNS('@ns.cli\\' . Text::camelize($controllerName)) . 'Controller';
            if (class_exists($controllerClassName)) {
                return $controllerClassName;
            }
        }

        return 'ManaPHP\\Cli\\Controllers\\' . Text::camelize($controllerName) . 'Controller';
    }
734398
private function getController()
    {
        if (empty($this->controllerName)) {
            return null;
        }

        if (isset($this->controller)) {
            return $this->controller;
        }

        $this->controller = $this->createControllerFromClassName($this->controllerName);

        return $this->controller;
    }
1370662
public function getController()
    {
        list($controller) = explode('@', $this->getAction());

        if (! $this->controller) {
            $this->setController($this->makeController($controller));
        }

        return $this->controller;
    }
876983
public function getController() {
        $router = new Router($this);
        $router->setCurrentRoute();
        $controllerObject = $this->GetControllerObject($router);
        $this->controller = $controllerObject;
        return $controllerObject;
    }
655360
public function getController()
    {
        if ($this->controller) {
            return $this->controller;
        }

        $controllerClass = self::config()->controller_class;

        if (!class_exists($controllerClass)) {
            throw new Exception(
                'Could not find controller class ' . $controllerClass . ' as defined in ' . static::class
            );
        }

        $this->controller = Injector::inst()->create($controllerClass, $this);
        $this->controller->doInit();

        return $this->controller;
    }
391637
protected function getController($controller)
	{
		$stub = $this->files->get(__DIR__.'/stubs/controller.stub');

		// We will explode out the controller name on the naemspace delimiter so we
		// are able to replace a namespace in this stub file. If no namespace is
		// provided we'll just clear out the namespace place-holder locations.
		$segments = explode('\\', $controller);

		$stub = $this->replaceNamespace($segments, $stub);

		return str_replace('{{class}}', last($segments), $stub);
	}
5870
public function getControllerName()
        {
            if (null === $this->_controller) {
                $this->_controller = $this->getParam($this->getControllerKey());
            }

            return $this->_controller;
        }