Factory for fetching the Presenter

@param   string  Presenter classname without View_ prefix or full classname
@param   string  Method to execute
@return  Presenter
430775
public static function forge($presenter, $method = 'view', $auto_filter = null, $view = null)
	{
		// if no custom view is given, make it equal to the presenter name
		is_null($view) and $view = $presenter;

		// strip any extensions from the view name to determine the presenter to load
		$presenter = \Inflector::words_to_upper(str_replace(
			array('/', DS),
			'_',
			strpos($presenter, '.') === false ? $presenter : substr($presenter, 0, -strlen(strrchr($presenter, '.')))
		));

		// determine the presenter namespace from the current request context
		$namespace = \Request::active() ? ucfirst(\Request::active()->module) : '';

		// list of possible presenter classnames, start with the namespaced one
		$classes = array($namespace.'\\'.static::$ns_prefix.$presenter);

		// add the global version if needed
		empty($namespace) or $classes[] = static::$ns_prefix.$presenter;

		/**
		 * Add non prefixed classnames to the list, for BC reasons
		 *
		 * @deprecated 1.6
		 */
		$classes[] = $namespace.'\\'.$presenter;

		// and add the global version of that if needed
		empty($namespace) or $classes[] = $presenter;

		// check if we can find one
		foreach ($classes as $class)
		{
			if (class_exists($class))
			{
				return new $class($method, $auto_filter, $view);
			}
		}

		throw new \OutOfBoundsException('Presenter "'.reset($classes).'" could not be found.');
	}
1023282
public static function getClassMethodArgs($class, string $method)
    {
        static $cache = null;

        if (null !== $cache && isset($cache[$class][$method])) {
            return $cache[$class][$method];
        }

        $reflector = new \ReflectionMethod($class, $method);
        $params = $reflector->getParameters();
        if (empty($params)) {
            $cache[$class][$method] = [];
            return [];
        }
        $args = [];
        foreach ($params as $param) {
            $args[$param->name] = [
                'optional' => $param->isOptional(),
                'variadic' => $param->isVariadic(),
            ];
            if ($param->isOptional() && $param->isDefaultValueAvailable()) {
                $args[$param->name]['default'] = $param->getDefaultValue();
            }
            if ($param->hasType()) {
                $args[$param->name]['type'] = (string)$param->getType();
            }
        }
        $cache[$class][$method] = $args;
        return $args;
    }
1234500
protected function getClassFromMethod($method)
    {
        // Look for a studly class
        $class = Str::singular(Str::studly($method));

        foreach ($this->repositories as $repository) {
            if (class_exists($repository.$class)) {
                return $repository.$class;
            }
        }

        // Resume normal functioning
        return parent::getClassFromMethod($method);
    }
642300
private function getHttpMethodAndResourcesFromMethod(\ReflectionMethod $method, $resource)
    {
        // if method doesn't match regex - skip
        if (!preg_match('/([a-z][_a-z0-9]+)(.*)Action/', $method->getName(), $matches)) {
            return false;
        }

        $httpMethod = strtolower($matches[1]);
        $resources = preg_split(
            '/([A-Z][^A-Z]*)/', $matches[2], -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE
        );
        $isCollection = false;
        $isInflectable = true;

        if (0 === strpos($httpMethod, self::COLLECTION_ROUTE_PREFIX)
            && in_array(substr($httpMethod, 1), $this->availableHTTPMethods)
        ) {
            $isCollection = true;
            $httpMethod = substr($httpMethod, 1);
        } elseif ('options' === $httpMethod) {
            $isCollection = true;
        }

        if ($isCollection && !empty($resource)) {
            $resourcePluralized = $this->generateResourceName(end($resource));
            $isInflectable = ($resourcePluralized != $resource[count($resource) - 1]);
            $resource[count($resource) - 1] = $resourcePluralized;
        }

        $resources = array_merge($resource, $resources);

        return [$httpMethod, $resources, $isCollection, $isInflectable];
    }
537437
static function getAnnotation($name, $class, $method = NULL, $nullable = TRUE)
	{
		try {
			NULL === $method or $annotation = self::getMethodAnnotation($method, $name, $class);
			isset($annotation) or $annotation = self::getClassAnnotation($class, $name);
		} catch (ReflectionException $e) {
			$annotation = NULL;
		}

		return !$nullable && NULL === $annotation
			? self::annotationClass($name)
			: $annotation;
	}
652182
public function method($method)
    {
        if (!$this->isString($method) && !$this->isStringObject($method)) {
            throw new EventManagerException(EventManagerException::MSG_INVALID_ARG, [
                    '$method',
                    'string|StringObject'
                ]
            );
        }
        $this->method = StdObjectWrapper::toString($method);

        return $this;
    }
908161
public static function initClientScript($view, $method = self::METHOD_POLL)
    {
        $asset = NfyAsset::register($view);
        return $asset->baseUrl;
    }
1313187
public function get($name, $presenter = null)
    {
        return $this->has($name) ? $this->menus[$name]->render($presenter) : null;
    }
164474
protected function getViewStub($method = null, $name = null)
    {
        if (in_array($name, [ $this->qualifyClass('ModelController'), $this->qualifyClass('Model/ChildController') ])) {
            if ($this->option('parent')) {
                return __DIR__.'/stubs/view.nested.model.'.$method.'.stub';
            } elseif ($this->option('model') || $this->option('resource')) {
                return __DIR__.'/stubs/view.model.'.$method.'.stub';
            }
        }

        if ($this->option('parent')) {
            return __DIR__.'/stubs/view.nested.'.$method.'.stub';
        } elseif ($this->option('model') || $this->option('resource')) {
            return __DIR__.'/stubs/view.'.$method.'.stub';
        }

        return __DIR__.'/stubs/view.stub';
    }
161765
public function getMethodAnnotation(\ReflectionMethod $method, $annotationName)
    {
        return $this->findReader($method->getDeclaringClass())
            ->getMethodAnnotation($method, $annotationName);
    }
724358
public function formatPresenterClass(string $presenter): string
    {
        if (isset($this->presenterMapping[$presenter])) {
            return $this->presenterMapping[$presenter];
        }

        $parts = explode(':', $presenter);
        $presenterName = (string) array_pop($parts);
        $modules = [];
        while (!isset($this->moduleMapping[implode(':', $parts)])) {
            array_unshift($modules, (string) array_pop($parts));
        }
        $mapping = $this->moduleMapping[implode(':', $parts)];

        $class = $mapping[0];
        foreach ($modules as $module) {
            $class .= str_replace('*', $module, $mapping[1]);
        }
        $class .= str_replace('*', $presenterName, $mapping[2]);

        return $class;
    }
1039345
public function call($className, $method, $arguments = null)
    {
        $callable = [$className, $method];
        if ($arguments === null) {
            return call_user_func($callable);
        } else {
            return call_user_func_array($callable, $arguments);
        }
    }
961816
function getMethodParams($class, $method) {
        if(!is_callable([$class, $method])){
            return self::NOT_CALLABLE;
        }
        $reflectMethod = new \ReflectionMethod($class, $method);
        $params        = [];
        foreach ($reflectMethod->getParameters() as $param) {
            $_param = '$' . $param->getName();
            if ($param->isDefaultValueAvailable()) {
                $default = $param->getDefaultValue();
                switch (mb_strtolower(gettype($default))) {
                    case 'null':
                        $default = 'null';
                        break;
                    case 'array':
                        $default = '[]';
                        break;
                    case 'string':
                        $default = '\'' . $default . '\'';
                        break;
                    case 'boolean':
                        $default = $default ? 'true' : 'false';
                        break;
                    default:
                        $default = $default;
                        break;
                }
                $_param .= ' = ' . $default;
            }
            $params[] = $_param;
        }
        return implode(', ', $params);

    }
556581
private function getRouteDocBlock($class, $method)
    {
        $reflector = new ReflectionClass($class);

        $title = implode(' ', $this->splitCamelCaseToWords($method));
        $title = ucfirst(strtolower($title));
        $description = '';
        $params = [];

        $reflectorMethod = $reflector->getMethod($method);
        $docs = explode("\n", $reflectorMethod->getDocComment());
        $docs = array_filter($docs);
        if (!$docs) {
            return [$title, $description, $params];
        }
        
        $docs = $this->filterDocBlock($docs);
        
        $title = array_shift($docs);
        
        $checkForLongDescription = true;
        foreach ($docs as $line) {
            if ($checkForLongDescription && !preg_match('~^@\w+~', $line)) {
                $description .= trim($line) .' ';
            } elseif (preg_match('~^@\w+~', $line)) {
                $checkForLongDescription = false;
                if (preg_match('~^@param~', $line)) {
                    $paramChunks = $this->getParamChunksFromLine($line);
                    
                    $paramType = array_shift($paramChunks);
                    $paramName = substr(array_shift($paramChunks), 1);
                    $params[$paramName] = [
                        'type'        => $paramType,
                        'name'        => $paramName,
                        'description' => implode(' ', $paramChunks),
                        'template'    => $this->getParamTemplateByType($paramType),
                    ];
                }
            }
        }

        // TODO:
        $rules = [];
        foreach($reflectorMethod->getParameters() as $reflectorParam) {
            $paramClass = $reflectorParam->getClass();
            if ($paramClass instanceof ReflectionClass) {
                $name = $paramClass->getName();
                $paramClassInstance = new $name;
                if (is_a($paramClassInstance, Request::class) && method_exists($paramClassInstance, 'rules')) {
                    $paramClassInstance->__apidocs = true;
                    $rules = $paramClassInstance->rules();
                }
            }
        }

        $params = $this->fillParamsWithRequestRules($params, $rules);

        foreach ($params as $name => $param) {
            $params[$name]['rules'] = $rules[$name] ?? [];
            if (is_string($params[$name]['rules'])) {
                $params[$name]['rules'] = explode('|', $params[$name]['rules']);
            } elseif (is_array($params[$name]['rules'])) {
                $params[$name]['rules'] = $params[$name]['rules'];
            }
        }

        return [$title, $description, $params];
    }
941629
public function present($name = null)
    {
        if (!$this->presenterInstance) {
            $class = $this->getPresenter();
            $this->presenterInstance = app($class, ['entity' => $this]);
        }

        if ($name) {
            return $this->presenterInstance->$name;
        }

        return $this->presenterInstance;
    }
488799
public function call(string $method)
    {
        $args = $this->getArgs($method);

        $return = call_user_func_array([$this, $method], $args);

        $out = $this->renderer->render($this->statusCode, $this->headers, $return);

        self::response()->addHeader('Content-Type', $this->renderer->getContentType());
        if ($this->renderer->sendHeader()) {
            foreach ($this->headers as $name => $value) {
                self::response()->addHeader('x-' . ucfirst($name), $value);
            }

            self::response()->setStatus($this->statusCode);
        }

        return $out;
    }
359525
private function createCode($name, \ReflectionMethod $method)
    {
        return function (InputInterface $input, OutputInterface $output) use ($name, $method) {
            $client = new Client([], null, $output);

            if ($input->getOption('token')) {
                $client->authorize($input->getOption('token'));
            }

            $methodName = $method->getName();
            $api = $client->api(strtolower($name));
            $args = (new NamedArgumentsResolver($method))->resolve(array_merge($input->getOptions(), $input->getArguments()));
            $outputClass = $this->generateOutputClassFromApiClass($api);

            $response = call_user_func_array([$api, $methodName], $args);

            if (method_exists($outputClass, $methodName) && false === $input->getOption('debug') && $response->getStatusCode() < 400) {
                (new $outputClass())->{$methodName}($output, $response);
            } elseif (!method_exists($outputClass, $methodName) || true === $input->getOption('debug')) {
                $output->writeln("Headers:\n" . print_r($response->getHeaders(), true) . "Body:\n" . print_r((string) $response->getBody(), true));
            }
        };
    }