Example #1
0
    /**
     * {@inheritdoc}
     */
    protected function describeRoute(Route $route, array $options = array())
    {
        $requirements = $route->getRequirements();
        unset($requirements['_scheme'], $requirements['_method']);

        // fixme: values were originally written as raw
        $description = array(
            '<comment>Path</comment>         '.$route->getPath(),
            '<comment>Host</comment>         '.('' !== $route->getHost() ? $route->getHost() : 'ANY'),
            '<comment>Scheme</comment>       '.($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY'),
            '<comment>Method</comment>       '.($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY'),
            '<comment>Class</comment>        '.get_class($route),
            '<comment>Defaults</comment>     '.$this->formatRouterConfig($route->getDefaults()),
            '<comment>Requirements</comment> '.$this->formatRouterConfig($requirements) ?: 'NO CUSTOM',
            '<comment>Options</comment>      '.$this->formatRouterConfig($route->getOptions()),
            '<comment>Path-Regex</comment>   '.$route->compile()->getRegex(),
        );

        if (isset($options['name'])) {
            array_unshift($description, '<comment>Name</comment>         '.$options['name']);
            array_unshift($description, $this->formatSection('router', sprintf('Route "%s"', $options['name'])));
        }

        if (null !== $route->compile()->getHostRegex()) {
            $description[] = '<comment>Host-Regex</comment>   '.$route->compile()->getHostRegex();
        }

        $this->writeText(implode("\n", $description)."\n", $options);
    }
 /**
  * {@inheritdoc}
  */
 protected function describeRoute(Route $route, array $options = array())
 {
     $requirements = $route->getRequirements();
     unset($requirements['_scheme'], $requirements['_method']);
     $output = '- Path: ' . $route->getPath() . "\n" . '- Host: ' . ('' !== $route->getHost() ? $route->getHost() : 'ANY') . "\n" . '- Scheme: ' . ($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY') . "\n" . '- Method: ' . ($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY') . "\n" . '- Class: ' . get_class($route) . "\n" . '- Defaults: ' . $this->formatRouterConfig($route->getDefaults()) . "\n" . '- Requirements: ' . $this->formatRouterConfig($requirements) ?: 'NONE' . "\n" . '- Options: ' . $this->formatRouterConfig($route->getOptions()) . "\n" . '- Path-Regex: ' . $route->compile()->getRegex();
     $this->write(isset($options['name']) ? $options['name'] . "\n" . str_repeat('-', strlen($options['name'])) . "\n\n" . $output : $output);
     $this->write("\n");
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 protected function describeRoute(Route $route, array $options = array())
 {
     $tableHeaders = array('Property', 'Value');
     $tableRows = array(array('Route Name', $options['name']), array('Path', $route->getPath()), array('Path Regex', $route->compile()->getRegex()), array('Host', '' !== $route->getHost() ? $route->getHost() : 'ANY'), array('Host Regex', '' !== $route->getHost() ? $route->compile()->getHostRegex() : ''), array('Scheme', $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY'), array('Method', $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY'), array('Requirements', $route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM'), array('Class', get_class($route)), array('Defaults', $this->formatRouterConfig($route->getDefaults())), array('Options', $this->formatRouterConfig($route->getOptions())));
     $table = new Table($this->getOutput());
     $table->setHeaders($tableHeaders)->setRows($tableRows);
     $table->render();
 }
 /**
  * @param Route $route the route we're tried to add
  * @param int $name the name given to the route we tried to add
  * @param Route $routeWithSameName the existing route with the same name
  */
 public function __construct(Route $route, $name, Route $routeWithSameName)
 {
     // host to string
     if (!($host = $route->getHost())) {
         $host = 'any';
     }
     if (!($hostRouteWithSameName = $routeWithSameName->getHost())) {
         $hostRouteWithSameName = 'any';
     }
     // methods to string
     if ($methods = $route->getMethods()) {
         $methods = implode($methods, ', ');
     } else {
         $methods = 'any';
     }
     if ($methodsRouteWithSameName = $routeWithSameName->getMethods()) {
         $methodsRouteWithSameName = implode($methodsRouteWithSameName, ', ');
     } else {
         $methodsRouteWithSameName = 'any';
     }
     $message = sprintf("Cannot add the route [path: %s, host: %s, methods: %s] with the name '%s'\n                as it is already used by the route [path: %s, host: %s, methods: %s].", $route->getPath(), $host, $methods, $name, $routeWithSameName->getPath(), $hostRouteWithSameName, $methodsRouteWithSameName);
     parent::__construct($message);
 }
Example #5
0
 public function testHost()
 {
     $route = new Route('/');
     $route->setHost('{locale}.example.net');
     $this->assertEquals('{locale}.example.net', $route->getHost(), '->setHost() sets the host pattern');
 }
Example #6
0
 /**
  * Get the route information for a given route.
  *
  * @param  string  $name
  * @param  \Symfony\Component\Routing\Route  $route
  * @return array
  */
 protected function getRouteInformation($name, Route $route)
 {
     $uri = head($route->getMethods()) . ' ' . $route->getPath();
     $action = $route->getAction() ?: 'Closure';
     return array('host' => $route->getHost(), 'uri' => $uri, 'name' => $this->getRouteName($name), 'action' => $action, 'before' => $this->getBeforeFilters($route), 'after' => $this->getAfterFilters($route));
 }
Example #7
0
 /**
  * @param Route $route
  *
  * @return array
  */
 protected function getRouteData(Route $route)
 {
     return array('path' => $route->getPath(), 'pathRegex' => $route->compile()->getRegex(), 'host' => '' !== $route->getHost() ? $route->getHost() : 'ANY', 'hostRegex' => '' !== $route->getHost() ? $route->compile()->getHostRegex() : '', 'scheme' => $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY', 'method' => $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY', 'class' => get_class($route), 'defaults' => $route->getDefaults(), 'requirements' => $route->getRequirements() ?: 'NO CUSTOM', 'options' => $route->getOptions());
 }
Example #8
0
 /**
  * Sets the pattern for the host.
  *
  * This method implements a fluent interface.
  *
  * @param string $pattern The host pattern
  *
  * @return Route The current Route instance
  */
 public function setHost($pattern)
 {
     parent::setHost($pattern);
     $this->host = parent::getHost();
     return $this;
 }
 /**
  * Makes a clone of the given Route object.
  *
  * @param Route $route
  *
  * @return Route
  */
 public function cloneRoute(Route $route)
 {
     return new Route($route->getPath(), $route->getDefaults(), $route->getRequirements(), $route->getOptions(), $route->getHost(), $route->getSchemes(), $route->getMethods());
 }
 public function addPageRoute($admin_name, $action_name, \Symfony\Component\Routing\Route $route, \ReflectionMethod $m, \Symforce\AdminBundle\Compiler\Annotation\Route $annot)
 {
     if (null === $this->route_page_collection) {
         throw new \Exception('should call getRouteCollection first');
     }
     $_path = array('s' => $route->getSchemes(), 'h' => $route->getHost(), 'p' => $route->getPath(), 'm' => $route->getMethods());
     $path = json_encode($_path);
     $admin_action = $admin_name . ':' . $action_name;
     if (isset($this->page_path_map[$path])) {
         $_admin_action = $this->page_path_map[$path];
         throw new \Exception(sprintf("web page path:`%s` duplicate(%s,%s)", $route->getPath(), $this->page_actions_map[$admin_action], $this->page_actions_map[$_admin_action]));
     }
     $this->page_path_map[$path] = $admin_action;
     if (isset($this->page_route_map[$annot->name])) {
         $_admin_action = $this->page_route_map[$annot->name];
         throw new \Exception(sprintf("web page route name:`%s` duplicate method(%s,%s), action(%s,%s)", $annot->name, $this->page_actions_map[$admin_action], $this->page_actions_map[$_admin_action], $admin_action, $_admin_action));
     }
     $this->page_route_map[$annot->name] = $admin_action;
     $this->route_page_collection->add($annot->name, $route);
     $this->page_dispatch_map[$admin_action] = array('name' => $annot->name, 'path' => $route->getPath(), 'requirements' => $route->getRequirements(), 'entity' => $annot->entity, 'template' => $annot->template, 'generator' => null, 'dispatcher' => null);
 }
 /**
  * Returns a descriptive string for a Route.
  *
  * @param Route  $route           A BackBee Route instance
  * @param string $routeName       The Route name (the associated index in a RouteCollection)
  * @param bool   $showControllers If true, display the Controller information
  *
  * @return string The text description of a Route
  */
 private function describeRoute(Route $route, $routeName, $showControllers)
 {
     $description = array('<comment>Name</comment>         ' . $routeName, '<comment>Path</comment>         ' . $route->getPath(), '<comment>Path Regex</comment>   ' . $route->compile()->getRegex(), '<comment>Host</comment>         ' . ('' !== $route->getHost() ? $route->getHost() : 'ANY'), '<comment>Host Regex</comment>   ' . ('' !== $route->getHost() ? $route->compile()->getHostRegex() : ''), '<comment>Scheme</comment>       ' . ($route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY'), '<comment>Method</comment>       ' . ($route->getMethods() ? implode('|', $route->getMethods()) : 'ANY'), '<comment>Class</comment>        ' . get_class($route), '<comment>Defaults</comment>     ' . $this->formatRouterConfig($route->getDefaults()), '<comment>Requirements</comment> ' . ($route->getRequirements() ? $this->formatRouterConfig($route->getRequirements()) : 'NO CUSTOM'), '<comment>Options</comment>      ' . $this->formatRouterConfig($route->getOptions()));
     if (isset($showControllers)) {
         array_unshift($description, '<comment>Controller</comment>   ' . $this->convertController($route));
     }
     return implode("\n", $description) . "\n";
 }