Bakes the JS file

@param string $controllerName Controller Name
@param string $actionName Action Name
@param string $content File Content
@return string
485083
public function bake($controllerName, $actionName, $content = '')
    {
        if ($content === true) {
            $content = $this->getContent($action);
        }
        if (empty($content)) {
            return false;
        }
        $this->out("\n" . sprintf('Baking `%s%s/%s` JS controller file...', ($this->plugin ? $this->plugin . '.' : ''), $controllerName, $actionName), 1, Shell::QUIET);
        $path = $this->getPath();
        $filename = $path . Inflector::underscore($controllerName) . '/' . Inflector::underscore($actionName) . '_controller.js';
        $this->createFile($filename, $content);
        return $content;
    }
830180
public function generatePath($controllerClassName, $action)
    {
        $controllerClassName = str_replace('\\', '/', $controllerClassName);
        $action = Text::underscore($action);

        if (preg_match('#Areas/([^/]+)/Controllers/(.*)Controller$#', $controllerClassName, $match)) {
            $area = Text::underscore($match[1]);
            $controller = Text::underscore($match[2]);

            if ($action === 'index') {
                if ($controller === 'index') {
                    return $area === 'index' ? '/' : "/$area";
                } else {
                    return "/$area/$controller";
                }
            } else {
                return "/$area/$controller/$action";
            }
        } elseif (preg_match('#/Controllers/(.*)Controller#', $controllerClassName, $match)) {
            $controller = Text::underscore($match[1]);

            if ($action === 'index') {
                return $controller === 'index' ? '/' : "/$controller";
            } else {
                return "/$controller/$action";
            }
        } else {
            throw new MisuseException(['invalid controller `:controller`', 'controller' => $controllerClassName]);
        }
    }
116170
private static function caching($actionContext) {
        $cacheKey = InternalHelper::getPropertyValue($actionContext, 'cacheKey');

        // no key, no cache
        if (empty($cacheKey)) {
            return;
        }

        $cacheSettings = InternalHelper::getStaticPropertyValue('\\PhpMvc\\OutputCache', 'settings');
        $actionName = $actionContext->getActionName();
        $httpContext = $actionContext->getHttpContext();
        $response = $httpContext->getResponse();
        $cache = $httpContext->getCache();

        // cache duration
        if (!empty($cacheSettings[$actionName]['duration'])) {
            $duration = intval($cacheSettings[$actionName]['duration']);
        }
        elseif (!empty($cacheSettings['.']['duration'])) {
            $duration = intval($cacheSettings['.']['duration']);
        }
        else {
            $duration = 0;
        }

        // TODO: regionName
        $regionName = null;

        $dataToCache = array();

        // add response to cache
        if (($cachePartSeq = $cache->get($cacheKey . '_part_seq')) === null) {
            $dataToCache['statusCode'] = $response->getStatusCode();
            $dataToCache['statusDescription'] = $response->getStatusDescription();
            $dataToCache['headers'] = $response->getHeaders();
            $dataToCache['cookies'] = $response->getCookies();
            $dataToCache['files'] = InternalHelper::getPropertyValue($response, 'files');
            $dataToCache['output'] = InternalHelper::getPropertyValue($response, 'output');
        }
        else {
            $dataToCache['statusCode'] = $response->getStatusCode();
            $dataToCache['statusDescription'] = $response->getStatusDescription();
            $dataToCache['headers'] = $response->getHeaders();
            $dataToCache['cookies'] = $response->getCookies();
            $dataToCache['files'] = array();
            $dataToCache['output'] = '';

            for ($i = 0; $i < $cachePartSeq; ++$i) {
                $part = $cache->get($cacheKey . '_part_' . $i);

                if ($part !== null) {
                    $dataToCache['output'] .= $part['output'];
                    $dataToCache['files'] = array_merge($dataToCache['files'], $part['files']);
                    $cache->remove($cacheKey . '_part_' . $i);
                }
            }

            $cache->remove($cacheKey . '_part_seq');
        }

        $cache->add($cacheKey, $dataToCache, $duration, $regionName);
    }
593522
public function contentTag($name, $content, array $options = array(), $escape = false)
    {
        if ($content instanceof \Closure) {
            ob_start();
            $ret     = $content();
            $content = ob_get_clean();
            if ($ret !== null) {
                $content = $ret;
            }
        }
        return $this->contentTagString($name, $content, $options, $escape);
    }
673712
public function reverseRoute( $controllerName, $actionName )
    {
        // Create a temp route because formatting
        $tempRoute = new Route( ["controllerName" => $controllerName, "actionName" => $actionName] );

        foreach ( $this->_routeDefinitions as $routeDefinition )
        {
            $route = call_user_func($routeDefinition);

            if ( $tempRoute->getControllerName() == $route->getControllerName() && $tempRoute->getActionName() == $route->getActionName() )
            {
                return $route->getUri();
            }
        }
    }
165417
protected function getControllerMiddleware($actionName)
	{
		Controller::setRouter($this->laravel['router']);

		$segments = explode('@', $actionName);

		return $this->getControllerMiddlewareFromInstance(
			$this->laravel->make($segments[0]), $segments[1]
		);
	}
228588
public function explainAction($actionName, $format)
    {
        $adapter = $this->getAdapter($format);
        $action = $this->getExecutor($actionName);

        if (!$action->supports($format)) {
            throw new \Exception('This action is not supported for the '.$format.' format.');
        }

        $schema = $action->getSchema();

        if (array_key_exists('$root', $schema)) {
            $jsonSchema = $this->serializer->getSchema($schema['$root']);

            if ($jsonSchema) {
                return $adapter->explainSchema($jsonSchema, $action->getMode());
            }
        }

        $identifiersSchema = [];

        foreach ($schema as $prop => $value) {
            if ($this->serializer->has($value)) {
                $identifiersSchema[$prop] = $this->serializer->getSchema($value);
            } else {
                $identifiersSchema[$prop] = $value;
            }
        }

        return $adapter->explainIdentifiers($identifiersSchema);
    }
978439
protected function controllerMethod($controllername)
    {
        if (str_contains($controller = $controllername, '@')) {
            return substr($controllername, strpos($controllername, '@')+1, strlen($controllername));
        }
        return 'index';
    }
1020452
public function getActionRequestByName($actionName)
    {
        // If action name level separator is in the string, we split
        $actionNameFirstPart = $actionNameSecondPart = "";
        if (strpos($actionName, self::API_NAME_LEVEL_SEPARATOR) === 0) {
            throw new BadApiConfigurationException(
                sprintf(
                    '[%s] Action name \'%s\' is not well formed. It should contain two parts separated by \'%s\'.',
                    $actionName,
                    self::API_NAME_LEVEL_SEPARATOR,
                    $this->getApiName()
                )
            );
        } else {
            $actionParts = explode(self::API_NAME_LEVEL_SEPARATOR, $actionName);
            if (isset($actionParts[0]) && isset($actionParts[1])) {
                $actionNameFirstPart  = $actionParts[0];
                $actionNameSecondPart = $actionParts[1];
            }
        }

        // Action is configured?
        if (!isset($this->actions[$actionNameFirstPart][$actionNameSecondPart])) {
            if ($this->getInitAllActions()) {
                throw new NotConfiguredActionException(
                    sprintf(
                        '[%s] No action configured with the following name: %s%s%s. Given action name was: %s',
                        $this->getApiName(),
                        $actionNameFirstPart,
                        self::API_NAME_LEVEL_SEPARATOR,
                        $actionNameSecondPart,
                        $actionName
                    ),
                    $actionName
                );
            } else {
                // We check if the requested action has a configuration
                if (!isset($this->actionsConfig[$actionNameFirstPart])
                    && !isset($this->actionsConfig[$actionNameFirstPart][$actionNameSecondPart])
                ) {
                    throw new NotConfiguredActionException(
                        sprintf(
                            '[%s] No action configuration found for the following action name: %s',
                            $this->getApiName(),
                            $actionName
                        ),
                        $actionName
                    );
                }

                // If configuration is found, then we create the action
                $this->setActionRequest(
                    $this->actionsConfig[$actionNameFirstPart][$actionNameSecondPart],
                    $actionNameFirstPart,
                    $actionNameSecondPart,
                    $this->actionsCommonConfig
                );
            }
        }

        // Returning action object
        return $this->actions[$actionNameFirstPart][$actionNameSecondPart];
    }
314102
public static function getControllerPublicMethods(string $controllerName): array
    {
        $actions = [];

        if (!class_exists($controllerName)) {
            return $actions;
        }

        $refClass = new \ReflectionClass($controllerName);
        foreach ($refClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
            $actions[] = $method->name;
        }

        return $actions;
    }
883541
protected function writeToCache($fileName, $content)
    {
        if ($this->cachePath === null || !is_dir($this->cachePath) || !is_writable($this->cachePath)) {
            return;
        }
        $encoder    = new \Riimu\Kit\PHPEncoder\PHPEncoder();
        $contentPHP = $encoder->encode($content, [
            'whitespace' => false,
            'recursion.detect' => false
        ]);
        $cache      = '<?php $crudlexCacheContent = '.$contentPHP.';';
        file_put_contents($this->getCacheFile($fileName), $cache);
    }
255218
public function output($filename, $content)
    {
        if (!class_exists('Patchwork\JSqueeze')) {
            throw new \Exception(sprintf('Cannot not load filter class "%s".', 'Patchwork\JSqueeze'));
        }

        $jz = new JSqueeze();

        return $jz->squeeze(
            $content,
            $this->_settings['singleLine'],
            $this->_settings['keepImportantComments'],
            $this->_settings['specialVarRx']
        );
    }
456021
private function determineControllerAndAction(&$controller, &$actionName)
    {
        $request = $this->getRequest();
        $this->invokePluginsHook(
            'beforeControllerSelected',
            array($this, $request)
        );

        $controllerDiKey = $request->getController();
        try {
            $controller = $this->getServiceProvider()->getServiceInstance($controllerDiKey);
        } catch (Exception $e) {
            throw new ResourceNotFoundException(sprintf(
                'No such controller found "%s".',
                $this->getRequest()->getController()
            ));
        }
        $actionName = $request->getAction();
        if (!method_exists($controller, $actionName)) {
            throw new ResourceNotFoundException(sprintf(
                '%s does not have method %s',
                $controllerDiKey,
                $actionName
            ));
        }
        $this->invokePluginsHook(
            'afterControllerSelected',
            array($this, $request, $controller, $actionName)
        );
        $controller->initialize($request, $this);
    }
440645
private function createPublicCacheFile(string $fileName, string $content): string
    {
        $extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
        if (empty($extension)) {
            $extension = 'cache';
        }

        $name = pathinfo($fileName, PATHINFO_FILENAME);
        $checksum = sha1($fileName . $content);
        $cacheFile = $this->directory . '/' . $name . '.' . $checksum . '.' . $extension;

        file_put_contents($cacheFile, $content);

        if ($this->chmod > -1) {
            chmod($cacheFile, $this->chmod);
        }

        return $cacheFile;
    }
1011633
private function bakeController(string $name) : void
    {
        $this->pathFragment = 'Controller/';

        $this->bake($name, 'Controller/controller', ['name' => $name], 'Controller');
    }
671364
private function addAction($actionName)
    {
        $template         = $this->templates[$actionName];
        $command          = preg_filter('/^/', '    ', explode(PHP_EOL, strtr($template, ['$actionName' => $actionName])));
        $command          = array_filter($command, function($var){return strlen(trim($var));});
        $command          = implode(PHP_EOL, $command);
        $this->commands[] = $command;
    }
867274
protected function _getCommands($controllerName)
    {
        $commands = [];

        foreach (get_class_methods($controllerName) as $method) {
            if (preg_match('#^(.*)Command$#', $method, $match) === 1 && $match[1] !== 'help') {
                $commands[] = $match[1];
            }
        }

        return $commands;
    }