示例#1
0
 private function checkConflicts(RouteEntity $routeEntity)
 {
     $newPath = $routeEntity->getPathWithBundlePrefix();
     $router = $this->view->getContainer()->get('router');
     /** @var RouteCollection $routeCollection */
     $routeCollection = $router->getRouteCollection();
     $errors = array();
     foreach ($routeCollection->all() as $route) {
         $path = $route->getPath();
         if ($path === '/{url}') {
             continue;
         }
         if ($path === $newPath) {
             $errors[] = array('type' => 'SAME', 'path' => $path);
             continue;
         }
         $pathRegExp = preg_quote(preg_replace("/{(.+)}/", "____DUMMY____", $path), '/');
         $pathRegExp = "#^" . str_replace('____DUMMY____', '(.+)', $pathRegExp) . "\$#";
         $matches = array();
         preg_match($pathRegExp, $newPath, $matches);
         if (count($matches)) {
             $errors[] = array('type' => 'SIMILAR', 'path' => $path);
         }
     }
     foreach ($errors as $error) {
         if ($error['type'] == 'SAME') {
             $message = $this->__('It looks like you created or updated a route with a path which already exists. This is an error in most cases.');
         } else {
             $message = $this->__f('The path of the route you created or updated looks similar to the following already existing path: %s Are you sure you haven\'t just introduced a conflict?', $error['path']);
         }
         \LogUtil::registerError($message);
     }
 }
function smarty_modifier_zikularoutesmodulePathToString($path, \Zikula\RoutesModule\Entity\RouteEntity $route)
{
    $options = $route->getOptions();
    $prefix = '';
    if (isset($options['i18n_prefix'])) {
        $prefix = '/' . $options['i18n_prefix'];
    }
    if (!isset($options['i18n']) || $options['i18n']) {
        $languages = ZLanguage::getInstalledLanguages();
        $isRequiredLangParam = ZLanguage::isRequiredLangParam();
        if (!$isRequiredLangParam) {
            $defaultLanguage = System::getVar('language_i18n');
            unset($languages[array_search($defaultLanguage, $languages)]);
        }
        if (count($languages) > 0) {
            $prefix = ($isRequiredLangParam ? "/" : "{/") . implode('|', $languages) . ($isRequiredLangParam ? "" : "}");
        }
    }
    $prefix = \DataUtil::formatForDisplay($prefix);
    $path = \DataUtil::formatForDisplay($route->getPathWithBundlePrefix());
    $container = \ServiceUtil::getManager();
    $path = preg_replace_callback('#%(.*?)%#', function ($matches) use($container) {
        return "<abbr title=\"" . \DataUtil::formatForDisplay($matches[0]) . "\">" . \DataUtil::formatForDisplay($container->getParameter($matches[1])) . "</abbr>";
    }, $path);
    $defaults = $route->getDefaults();
    $requirements = $route->getRequirements();
    $dom = ZLanguage::getModuleDomain('ZikulaRoutesModule');
    $path = preg_replace_callback('#{(.*?)}#', function ($matches) use($container, $defaults, $requirements, $dom) {
        $title = "";
        if (isset($defaults[$matches[1]])) {
            $title .= __f('Default: %s', array(\DataUtil::formatForDisplay($defaults[$matches[1]])), $dom);
        }
        if (isset($requirements[$matches[1]])) {
            if ($title != "") {
                $title .= " | ";
            }
            $title .= __f('Requirement: %s', array(\DataUtil::formatForDisplay($requirements[$matches[1]])), $dom);
        }
        if ($title == "") {
            return $matches[0];
        }
        return "<abbr title=\"{$title}\">" . $matches[0] . "</abbr>";
    }, $path);
    return "{$prefix}<strong>{$path}</strong>";
}
示例#3
0
文件: Route.php 项目: rmaiwald/core
 public function addRouteCollection(AbstractModule $module, RouteCollection $routeCollection)
 {
     $workflowHelper = new WorkflowUtil(\ServiceUtil::getManager(), \ModUtil::getModule('ZikulaRoutesModule'));
     $routingHelper = new RoutingUtil();
     foreach ($routeCollection->all() as $name => $route) {
         $routeEntity = new RouteEntity();
         $routeEntity->setPath($route->getPath());
         $routeEntity->setDefaults($route->getDefaults());
         $routeEntity->setRequirements($route->getRequirements());
         $routeEntity->setOptions($route->getOptions());
         $routeEntity->setHost($route->getHost());
         $routeEntity->setSchemes($route->getSchemes());
         $routeEntity->setMethods($route->getMethods());
         $routeEntity->setCondition($route->getCondition());
         if ($route->getOption('zkDescription') !== null) {
             $routeEntity->setDescription($route->getOption('zkDescription'));
         }
         $routeEntity->setWorkflowState('approved');
         $routeEntity->setUserRoute(false);
         $position = $route->getOption('zkPosition');
         switch ($position) {
             case 'top':
                 $routeEntity->setGroup(RouteEntity::POSITION_FIXED_TOP);
                 break;
             case 'bottom':
                 $routeEntity->setGroup(RouteEntity::POSITION_FIXED_BOTTOM);
                 break;
             case null:
                 $routeEntity->setGroup(RouteEntity::POSITION_MIDDLE);
                 break;
             default:
                 $dom = \ZLanguage::getModuleDomain('ZikulaRoutesModule');
                 throw new \RuntimeException(__f('Route option "zkPosition" must either be null, "top", or "bottom" for route %s', array($route->getPath()), $dom));
                 break;
         }
         $modname = $module->getName();
         list(, $type, $func, $numericSuffix) = $routingHelper->getParametersFromRouteName($name);
         $routeEntity->setBundle($modname);
         $routeEntity->setController($type);
         $routeEntity->setAction($func);
         $routeEntity->setName(strtolower($modname . "_{$type}" . "_{$func}" . $numericSuffix));
         $workflowHelper->executeAction($routeEntity, 'submit');
     }
 }