Example #1
0
 /**
  * @param $controllerName
  * @param $actionName
  * @param array $args
  * @return mixed
  */
 public static function getByAction($controllerName, $actionName, array $args = array())
 {
     $instance = new self();
     $routingCollection = new RoutingCollection();
     /*
      * controller url prefix
      */
     if ($phpDocUrlPrefix = $instance->getUrlPrefixDefinitionOverController($controllerName)) {
         $urlPrefix = $phpDocUrlPrefix;
     } else {
         if ($parentRoutingItem = $routingCollection->getParentItemByController($controllerName)) {
             $urlPrefix = $parentRoutingItem->getUrlPrefix();
         } else {
             if ($routingItem = $routingCollection->find($controllerName, $actionName)) {
                 return $routingItem->urlPattern()->getReplacedStringWithArgs($args);
             } else {
                 $urlPrefix = '/' . $controllerName;
             }
         }
     }
     /*
      * if a url prefix has been found, continue with find action url pattern
      * action url pattern
      */
     if ($urlPrefix) {
         if ($phpDocUrlPattern = $instance->getUrlPatternDefinitionOverActionMethod($controllerName, $actionName)) {
             $urlPattern = $phpDocUrlPattern;
         } else {
             if (isset($parentRoutingItem)) {
                 foreach ($routingCollection->getChilds($parentRoutingItem->getSlug()) as $childRoutingItem) {
                     if ($childRoutingItem->getAction() == $actionName) {
                         $urlPattern = $childRoutingItem->urlPattern()->getString();
                         break;
                     }
                 }
             }
         }
     }
     if (isset($urlPattern)) {
         return (new UrlPattern($urlPrefix . $urlPattern))->getReplacedStringWithArgs($args);
     } else {
         return (new UrlPattern($urlPrefix . $instance->generateUrlPatternFromActionArgs($controllerName, $actionName)))->getReplacedStringWithArgs($args);
     }
 }