Generates PHP code representing an array of defined routes
together with the routes properties (e.g. requirements).

@return string PHP code
765043
private function generateDeclaredRoutes()
    {
        $routes = "[\n";
        foreach ($this->getRoutes()->all() as $name => $route) {
            $compiledRoute = $route->compile();

            $properties = [];
            $properties[] = $compiledRoute->getVariables();
            $properties[] = $route->getDefaults();
            $properties[] = $route->getRequirements();
            $properties[] = $compiledRoute->getTokens();
            $properties[] = $compiledRoute->getHostTokens();
            $properties[] = $route->getSchemes();

            $routes .= sprintf("        '%s' => %s,\n", $name, CompiledUrlMatcherDumper::export($properties));
        }
        $routes .= '    ]';

        return $routes;
    }
389641
public static function dispatch()
    {
        $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
        $method = $_SERVER['REQUEST_METHOD'];

        $searches = array_keys(static::$patterns);
        $replaces = array_values(static::$patterns);

        $found_route = false;

        self::$routes = preg_replace('/\/+/', '/', self::$routes);

        // Check if route is defined without regex
        if (in_array($uri, self::$routes)) {
            $route_pos = array_keys(self::$routes, $uri);
            foreach ($route_pos as $route) {

                // Using an ANY option to match both GET and POST requests
                if (self::$methods[$route] == $method || self::$methods[$route] == 'ANY' || in_array($method, self::$maps[$route])) {
                    $found_route = true;

                    // If route is not an object
                    if (!is_object(self::$callbacks[$route])) {

                        // Grab all parts based on a / separator
                        $parts = explode('/', self::$callbacks[$route]);

                        // Collect the last index of the array
                        $last = end($parts);

                        // Grab the controller name and method call
                        $segments = explode('@', $last);

                        // Instanitate controller
                        $controller = new $segments[0]();

                        // Call method
                        $controller->{$segments[1]}();

                        if (self::$halts) return;
                    } else {
                        // Call closure
                        call_user_func(self::$callbacks[$route]);

                        if (self::$halts) return;
                    }
                }
            }
        } else {
            // Check if defined with regex
            $pos = 0;
            foreach (self::$routes as $route) {
                if (strpos($route, ':') !== false) {
                    $route = str_replace($searches, $replaces, $route);
                }

                if (preg_match('#^' . $route . '$#', $uri, $matched)) {
                    if (self::$methods[$pos] == $method || self::$methods[$pos] == 'ANY' || in_array($method, self::$maps[$pos])) {
                        $found_route = true;

                        // Remove $matched[0] as [1] is the first parameter.
                        array_shift($matched);

                        if (!is_object(self::$callbacks[$pos])) {

                            // Grab all parts based on a / separator
                            $parts = explode('/', self::$callbacks[$pos]);

                            // Collect the last index of the array
                            $last = end($parts);

                            // Grab the controller name and method call
                            $segments = explode('@', $last);

                            // Instanitate controller
                            $controller = new $segments[0]();

                            // Fix multi parameters
                            if (!method_exists($controller, $segments[1])) {
                                echo "controller and action not found";
                            } else {
                                call_user_func_array(array($controller, $segments[1]), $matched);
                            }

                            if (self::$halts) return;
                        } else {
                            call_user_func_array(self::$callbacks[$pos], $matched);

                            if (self::$halts) return;
                        }
                    }
                }
                $pos++;
            }
        }

        // Run the error callback if the route was not found
        if ($found_route == false) {
            if (!self::$error_callback) {
                self::$error_callback = function () {
                    header($_SERVER['SERVER_PROTOCOL'] . " 404 Not Found");
                    throw new \Exception(Config::get('error_message'));
                };
            } else {
                if (is_string(self::$error_callback)) {
                    self::get($_SERVER['REQUEST_URI'], self::$error_callback);
                    self::$error_callback = null;
                    self::dispatch();
                    return;
                }
            }
            call_user_func(self::$error_callback);
        }
    }
871781
public function viewRoutes()
	{
		// variables
		$routes = \Route::getRoutes();
		$array  = [];
		foreach ($routes as /** @var Route */ $route)
		{
			// properties
			$methods = method_exists($route, 'getMethods') ? $route->getMethods() : $route->methods;
			$uri = method_exists($route, 'getUri') ? $route->getUri() : $route->uri;
			$action = $route->getAction()['uses'];

			// data
			$array[] =
			[
				'methods'   => implode('|', $methods),
				'uri'       => $uri,
				'name'      => $route->getName(),
				'action'    => $action instanceof \Closure ? 'Closure' : $action,
				'middleware'=> implode(', ', $route->middleware()),
			];
		}

		vue('sketchpad::help/tools/routes', $array);
	}
716090
private function generateRoutingKey()
    {
        $routeParts = explode('.', $this->request->get('_route'));
        $action = array_pop($routeParts);
        $baseRoute = implode('.', $routeParts);

        // find our route in the map
        $routingKey = null;

        foreach ($this->eventMap as $mapElement) {
            if ($mapElement['baseRoute'] == $baseRoute &&
                isset($mapElement['events'][$action])
            ) {
                $routingKey = $mapElement['events'][$action];
                break;
            }
        }

        return $routingKey;
    }
767017
public function loadRoutes()
    {
        $routesJsonFile = $this->configDir . '/routes.json';
        $routesPhpFile = $this->configDir . '/routes.php';
        
        if (file_exists($this->resourcesDir) && file_exists($this->configDir)) {
            if (file_exists($routesJsonFile))
                return json_decode(file_get_contents($routesJsonFile), true);
            elseif (file_exists($routesPhpFile))
                return require_once $routesPhpFile;
        } else {
            return array();
        }
    }
1015122
public function generate()
    {
        $indentation = $this->getIndentation();

        $code = $indentation . 'use ' . $this->traitClass;
        if (count($this->conflictsResolutions) > 0) {
            $conflictIndentation = $indentation . $this->indentationString;
            $code .= ' {' . $this->lineFeed;
            foreach ($this->conflictsResolutions as $conflict) {
                $code .= $conflictIndentation . rtrim($conflict, ';') . ';' . $this->lineFeed;
            }
            $code .= $indentation . '}';
        } else {
            $code .= ';';
        }

        return $code;
    }
373237
public function render(): string
    {
        $this->checkRoutesValidity($this->getAttribute('routes'));
        $this->checkIfAtLeastOneColumnIsDeclared();
        $this->checkDestroyAttributesDefinition();
        $this->handleRequest();
        $this->generateEntitiesListFromQuery();

        return view('tablelist::table', ['table' => $this]);
    }
286481
private function generateDeclaredRoutes(): string
    {
        $routes = '';
        foreach ($this->getCompiledRoutes() as $name => $properties) {
            $routes .= sprintf("\n    '%s' => %s,", $name, CompiledUrlMatcherDumper::export($properties));
        }

        return $routes;
    }
897663
protected function buildWebRequest()
    {
        $args = $_REQUEST;
        $params = array();

        $route = $_SERVER['REQUEST_URI'];
        $posQuestionMark = strpos($route, '?');
        if ($posQuestionMark !== false) {
            $route = substr($route, 0, $posQuestionMark);
        }
        
        $posIndex = strpos($route, 'index.php');
        if ($posIndex !== false) {
            $route = substr($route, $posIndex + strlen('index.php'));
        }
        
        // Transform the arguments
        foreach ($args as $key => $value) {
            if (is_numeric($value)) {
                // Transform the value into the correct data type
                $value = $value * 1;
            }
            
            $params[$key] = $value;
        }

        // Generate the full url and extract the base
        $scheme = $this->getScheme();
        $fullUrl = $scheme . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

        $isSsl = false;
        if ($scheme == 'https') {
            $isSsl = true;
        }
        
        $routePosition = strlen($fullUrl);
        if ($route !== '' && $route !== '/') {
            $routePosition = strpos($fullUrl, $route);
        }
        
        $method = $_SERVER['REQUEST_METHOD'];
        $requestedUrl = $this->getRequestedUrl();
        $base = substr($fullUrl, 0, $routePosition);
        $headers = $this->getHeaders($_SERVER);
        $protocol = $_SERVER['SERVER_PROTOCOL'];
        
        $locale = 'en_US';
        if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
            $locale = $this->getLocale($_SERVER['HTTP_ACCEPT_LANGUAGE']);
        }
        
        $operatingSystem = $this->getOperatingSystem();

        return new WebRequest($method, $requestedUrl, $route, $params, $base, $locale, $operatingSystem, $isSsl, $headers, $protocol);
    }
759519
public function generateUrlParams()
    {
        /* @var $class ActiveRecord */
        $class = $this->modelClass;
        $pks = $class::primaryKey();
        if (count($pks) === 1) {
            if (is_subclass_of($class, \yii\mongodb\ActiveRecord::class)) {
                return "'id' => (string)\$model->{$pks[0]}";
            }

            return "'id' => \$model->{$pks[0]}";
        }

        $params = [];
        foreach ($pks as $pk) {
            if (is_subclass_of($class, \yii\mongodb\ActiveRecord::class)) {
                $params[] = "'$pk' => (string)\$model->$pk";
            } else {
                $params[] = "'$pk' => \$model->$pk";
            }
        }

        return implode(', ', $params);
    }
1163864
public function generate(): string
    {
        $elements = [];
        foreach ($this->hiddens as $hidden) {
            $elements[] = $hidden;
        }
        foreach ($this->elements as $element) {
            /** @noinspection PhpUndefinedMethodInspection */
            $elements[] = $element->generate();
        }
        return Tags::form($elements, $this->attributes);
    }
907684
protected function generateRoutingData(): array
	{
		$parsedRoutes = [];
		$parser = new FR\RouteParser\Std();
		$dispatcherDataGenerator = new FR\DataGenerator\GroupCountBased();
		foreach ($this->routes as $routeName => $route)
		{
			$parsedRoute = $parser->parse($route->getPath());
			foreach ($route->getAllowedMethods() ?? ['*'] as $httpMethod)
			{
				foreach ($parsedRoute as $segments)
				{
					$dispatcherDataGenerator->addRoute($httpMethod, $segments, $routeName);
				}
			}
			$parsedRoutes[$routeName] = $parsedRoute;
		}
		return [$dispatcherDataGenerator->getData(), $parsedRoutes];
	}
585607
public function generateCode()
    {
        $refClass = new ReflectionClass($this->className);
        $this->finalClassesCanNotBeMocked($refClass);

        $this->methods = array();
        $this->makeAllAbstractMethodsThrowException($refClass);
        if (!$this->niceMock || $refClass->isInterface()) {
            $this->makeAllMethodsThrowException($refClass);
        }
        $this->renderRules();
        $this->renderConstructor();
        $this->renderClone();
        $this->exposeMethods();
        $this->setUpGetCallsForMethod();

        $code = $this->getNamespaceCode();
        $methods = implode("\n", $this->methods);
        $superWord = $this->getSuperWord($refClass);

        $class = "class {$this->getMockName()} $superWord \\{$this->className}";
        if ('implements' === $superWord) {
            $class .= ', ';
        } else {
            $class .= ' implements ';
        }
        $class .= '\Concise\Mock\MockInterface';

        return $code .
        "$class { public static \$_methodCalls = array(); $methods }";
    }
950671
public function getJavascripts()
    {
        $self = $this;
        $parse_javascripts = function ($params, $javascripts) use ($self) {
            foreach ($params as $js) {

                if (is_string($js)) {
                    $js = array(
                        'path'  => $js,
                    );
                } elseif (isset($js['route'])) {
                    $js = array(
                        'path'  => $self->getGenerator()
                                        ->getContainer()
                                        ->get('router')
                                        ->generate($js['route'], $js['routeparams'])
                    );
                }

                $javascripts[] = $js;
            }

            return $javascripts;
        };

        // From config.yml
        $javascripts = $parse_javascripts(
            $this->getGenerator()->getContainer()
                 ->getParameter('admingenerator.javascripts', array()), array()
        );

        // From generator.yml
        $javascripts = $parse_javascripts(
            $this->getVariable('javascripts', array()), $javascripts
        );

        return $javascripts;
    }
130290
public function generate() : string
    {
        if ($this->version === null) {
            $this->version = request()->route('version');
        }

        $routeName = $this->assembleRouteName();

        $routeParams = $this->assembleRouteParams();

        $url = config('app.url') . route($routeName, $routeParams, false);

        $this->reset();

        return $url;
    }
220556
private function generateUrl(): string
    {
        static $re = '/\%5B\d+\%5D/m';
        static $subst = '%5B%5D';

        $query = [];
        /**
         * @var IArgument
         */
        foreach ($this->arguments as $key => $value) {
            $query[$key] = $value->toPrimitive();
        }

        foreach ($this->mergeableArguments as $key => $value) {
            $query[$key] = $value->toPrimitive();
        }

        foreach ($this->stackableArguments as $key => $value) {
            $query[$key] = $value->toArray();
        }

        $queryArg = http_build_query($query, null, '&', PHP_QUERY_RFC3986);

        $fullUrl = $this->routeUrl() . '?' . preg_replace($re, $subst, $queryArg);

        return $fullUrl;
    }
186624
public function scripts()
	{
		$assets = array();
		
		foreach ($this->assets as $asset) {
			if ('js' !== $asset['ext']) {
				continue;
			}
			
			$assets[] = $this->route ? $asset : $this->process($asset);
		}
		
		if (empty($assets)) {
			return '';
		}
		
		if ($this->route) {
			return $this->prepareForController($assets, 'script');
		}
		
		if ($this->combine) {
			$assets = $this->combine($assets, 'script');
		}
		
		$links = array();
		foreach ($assets as $asset) {
			$url = $this->cdn ? $this->cdn . $asset['url'] : $asset['url'];
			$links[] = HTML::script($url, $asset['attributes']);
		}
		
		return implode('', $links);
	}