Example #1
0
 /**
  * Returns url matched with given slug
  * @param $slug
  * @param array $args
  * @return mixed
  * @throws \Exception
  */
 public static function get($slug, array $args = array())
 {
     $instance = new self();
     $routingCollection = new RoutingCollection();
     if (!($routingItem = $routingCollection->getRoutingItem($slug))) {
         throw new \Exception('Couldn\'t find routing definition for slug "' . $slug . '"');
     }
     if (!$routingItem->isParent()) {
         if ($routingItem->urlFullPattern() !== null) {
             return $routingItem->urlFullPattern()->getReplacedStringWithArgs($args);
         } else {
             return '/' . $routingItem->getController() . $instance->generateUrlPatternFromActionArgs($routingItem->getController(), $routingItem->getAction());
         }
     } else {
         throw new \Exception('Routing definition shouldn\'t be parent to generate url; slug "' . $routingItem->getSlug() . '" is a parent definition');
     }
 }