Add a new default route.

@param array $routeData The route data.
@return Route
359093
protected function _addDefaultRoute(array $routeData)
    {
        /** @var Connection $connection */
        $connection = $this->Routes->connection();
        $connection->begin();

        // Save the new default route.
        /** @var Route $defaultRoute */
        $defaultRoute = $this->Routes->newEntity($routeData);

        if ($this->Routes->save($defaultRoute)) {
            // Make all other routes for this model + foreignKey + languageId
            // redirect to the new default route.
            $otherRoutes = $this->Routes->getOtherRoutesExcept($defaultRoute->id, $defaultRoute->model, $defaultRoute->foreign_key, $defaultRoute->language_id);
            $this->Routes->redirectRoutesToId($otherRoutes, $defaultRoute->id);

            $connection->commit();
            $this->Flash->success(__d('wasabi_core', 'New default URL <strong>{0}</strong> has been added.', $defaultRoute->url), 'routes');
            $this->request->data = [];
        } else {
            $connection->rollback();
            $this->Flash->error($this->formErrorMessage, 'routes');
            $defaultRoute->set('type', RouteTypes::TYPE_DEFAULT_ROUTE);
        }

        return $defaultRoute;
    }
651337
private function addRoute(array $httpMethod, string $routePath, string $routeId): void
    {
        $routeDatas = $this->parser->parse($routePath);
        foreach ($httpMethod as $method) {
            foreach ($routeDatas as $routeData) {
                $this->generator->addRoute($method, $routeData, $routeId);
            }
        }
    }
1034395
public static function add_rule($ruledata) {
        global $DB;

        $now = time();
        $ruledata->timecreated = $now;
        $ruledata->timemodified = $now;

        $ruledata->id = $DB->insert_record('tool_monitor_rules', $ruledata);

        // Trigger a rule created event.
        if ($ruledata->id) {
            if (!empty($ruledata->courseid)) {
                $courseid = $ruledata->courseid;
                $context = \context_course::instance($ruledata->courseid);
            } else {
                $courseid = 0;
                $context = \context_system::instance();
            }

            $params = array(
                'objectid' => $ruledata->id,
                'courseid' => $courseid,
                'context' => $context
            );
            $event = \tool_monitor\event\rule_created::create($params);
            $event->trigger();
        }

        return new rule($ruledata);
    }
329208
public function setUriData($uriData)
    {
        if (!$uriData instanceof UriData) {
            $uriData = new UriData($uriData);
        }

        $this->uriData = $uriData;

        return $this;
    }
123016
public function handleRoute(RouteData $route): RouteData
    {
        $name   = $route->getName();
        $groups = $route->getGroups();

        // Set group data
        $keys = ['methods', 'actions', 'variables', 'requirements', 'scheme', 'port', 'sslPort', 'hooks'];

        foreach ($groups as $groupData) {
            foreach ($keys as $i => $key) {
                if (isset($groupData[$key])) {
                    $route->$key($groupData[$key]);

                    unset($groupData[$key]);
                }
            }

            if (isset($groupData['extra'])) {
                $route->extraValues($groupData['extra']);
            }
        }

        $options = $route->getOptions();

        if (!isset($options['pattern'])) {
            throw new \LogicException('Route: ' . $name . ' has no pattern.');
        }

        // Prefix
        $prefixes = array_filter(array_column($groups, 'prefix'), function ($v) {
            return strlen(trim($v, '/'));
        });

        $options['pattern'] = rtrim(implode('/', $prefixes) . $options['pattern'], '/');

        $options['extra']['controller']  = $options['controller'] ?? '';
        $options['extra']['action']      = $options['actions'] ?? [];
        $options['extra']['package']     = $options['package'] ?? '';
        $options['extra']['hook']        = $options['hooks'] ?? [];
        $options['extra']['middlewares'] = $options['middlewares'] ?? [];
//        $options['extra']['package']     = $options['package'];
        $options['extra']['groups']      = $groups;

        $route->setOptions($options);

        return $route;
    }
752293
protected function newRoute( $methods, $uri, $action )
	{
		return ( new Route( $methods, $uri, $action ) )->setRouter( $this );
	}
861404
public function addRoute(array $verbs, $pattern, $action, $name = null)
    {

        $pattern = $this->resolvePatternValue($pattern);

        $action  = $this->resolveActionValue($action);

        $name    = $this->resolveNameValue($name);

        $route   = new Route($pattern, $action, $verbs, $name);

        if ($filters = $this->getDefaultFilters()) {

            $route->setFilters($filters);
        }

        $this->routes->add($route);

        return $route;
    }
626197
public function addRoutes(array $routes)
    {
        foreach($routes as $name => $routeData)
            $this->addRoute($this->factory->createRoute($this, $name, $routeData));

        return $this;
    }
17409
public function addRoute($methods, $uri, $action)
    {
        if (\is_string($action)) {
            $action = ['uses' => $action, 'controller' => $action];
        } elseif ($action instanceof Closure) {
            $action = [$action];
        }

        $action = $this->mergeLastGroupAttributes($action);

        $action = $this->addControllerMiddlewareToRouteAction($action);

        $uri = $uri === '/' ? $uri : '/'.\trim($uri, '/');

        if (! empty($action['prefix'])) {
            $uri = '/'.\ltrim(\rtrim(\trim($action['prefix'], '/').'/'.\trim($uri, '/'), '/'), '/');

            unset($action['prefix']);
        }

        $action['uri'] = $uri;

        return $this->adapter->addRoute((array) $methods, $action['version'], $uri, $action);
    }
284696
public function setTemplateData(array $templateData)
    {
        if (!isset($this->templateData)) {
            $this->templateData = [];
        }

        $this->templateData = array_merge($this->templateData, $templateData);

        return $this;
    }
875399
public function resolveRoute(string $originalUrl): RouteDefinition
    {
        foreach ($this->routes as $route) {
            /** @var Url $routeOriginalUrl */
            $routeOriginalUrl = $route->originalUrl();

            if ($routeOriginalUrl->matches(Url::fromString($originalUrl))) {
                return $route;
            }
        }

        throw new RouteNotFound(\sprintf(
            'Route "%s" could not be found.',
            $originalUrl
        ));
    }
1083890
public function addUnique($unqdata)
    {
        if ($unqdata instanceof Unique) {
            $unique = $unqdata;
            $unique->setTable($this);
            $unique->getName(); // we call this method so that the name is created now if it doesn't already exist.
            $this->unices[] = $unique;

            return $unique;
        } else {
            $unique = new Unique($this);
            $unique->loadFromXML($unqdata);

            return $this->addUnique($unique);
        }
    }
665062
private function addRoute(RouteCollection $routeCollection, string $resourceClass, string $operationName, array $operation, ResourceMetadata $resourceMetadata, string $operationType): void
    {
        $resourceShortName = $resourceMetadata->getShortName();

        if (isset($operation['route_name'])) {
            return;
        }

        if (!isset($operation['method'])) {
            throw new RuntimeException(sprintf('Either a "route_name" or a "method" operation attribute must exist for the operation "%s" of the resource "%s".', $operationName, $resourceClass));
        }

        if (null === $controller = $operation['controller'] ?? null) {
            $controller = sprintf('%s%s_%s', self::DEFAULT_ACTION_PATTERN, strtolower($operation['method']), $operationType);

            if (!$this->container->has($controller)) {
                throw new RuntimeException(sprintf('There is no builtin action for the %s %s operation. You need to define the controller yourself.', $operationType, $operation['method']));
            }
        }

        $path = trim(trim($resourceMetadata->getAttribute('route_prefix', '')), '/');
        $path .= $this->operationPathResolver->resolveOperationPath($resourceShortName, $operation, $operationType, $operationName);

        $route = new Route(
            $path,
            [
                '_controller' => $controller,
                '_format' => null,
                '_api_resource_class' => $resourceClass,
                sprintf('_api_%s_operation_name', $operationType) => $operationName,
            ] + ($operation['defaults'] ?? []),
            $operation['requirements'] ?? [],
            $operation['options'] ?? [],
            $operation['host'] ?? '',
            $operation['schemes'] ?? [],
            [$operation['method']],
            $operation['condition'] ?? ''
        );

        $routeCollection->add(RouteNameGenerator::generate($operationName, $resourceShortName, $operationType), $route);
    }
1155224
public function get(string $name, ?string $pattern = null, array $options = []): RouteData
    {
        return $this->any($name, $pattern, $options)->methods('GET');
    }
1245053
protected function newRoute($methods, $uri, $action)
	{
		$route = new Route($methods, $uri, $action);
		$priority = Router::MEDIUM - $this->routes->count();
		$route->setPriority($priority);
		return $route;
	}
94729
public function addRoute(array $method, string $uri, $action): Route {
        if (is_string($action)) {
            $action = $this->addPackage($action);
        }
        $uri = $this->addPrefix($uri);
        $route = new Route($uri, is_callable($action) ? $action : function() use ($action) {
            return $this->makeResponse($action);
        }, $method, $this->globalFilters);
        foreach ($route->getMethods() as $item) {
            $this->staticRouteMap[$item][$uri] = $route;
        }
        return $route;
    }
44379
protected function createRoute($methods, $uri, $action)
	{
		// If the route is routing to a controller we will parse the route action into
		// an acceptable array format before registering it and creating this route
		// instance itself. We need to build the Closure that will call this out.
		if ($this->routingToController($action))
		{
			$action = $this->getControllerAction($action);
		}

		$route = $this->newRoute(
			$methods, $uri = $this->prefix($uri), $action
		);

		$route->where($this->patterns);

		// If we have groups that need to be merged, we will merge them now after this
		// route has already been created and is ready to go. After we're done with
		// the merge we will be ready to return the route back out to the caller.
		if (count($this->groupStack) > 0)
		{
			$this->mergeController($route);
		}

		return $route;
	}