示例#1
0
 public function add_route(BaseRoute $route)
 {
     // validate the method
     $method = $route->get_method();
     if (!in_array($method, self::$_whitelisted_http_methods)) {
         trigger_error('Unsupported HTTP method; "' . $method . '" is not supported by the router', E_USER_ERROR);
     }
     // finally, push this route onto the stack
     $this->_routes[] = $route;
 }
 /**
  * Поиск объекта на сайте.
  */
 public static function on_locate(Context $ctx)
 {
     if (!($nid = $ctx->get('node'))) {
         throw new BadRequestException(t('Не указан идентификатор объекта (GET-параметр node).'));
     }
     $map = BaseRoute::load($ctx);
     foreach ($map as $k => $v) {
         if (false === strpos($k, '*')) {
             unset($map[$k]);
         }
     }
     if (empty($map)) {
         throw new RuntimeException(t('Не удалось найти маршрут, пригодный для отображения документа.'));
     }
     // Выбираем первый маршрут.
     list($path) = array_keys($map);
     // Заменяем звезду на код документа.
     $path = str_replace('*', $ctx->get('node'), $path);
     // Заменяем localhost на имя текущего домена.
     if (0 === strpos($path, 'localhost/')) {
         $path = MCMS_HOST_NAME . '/' . substr($path, 10);
     }
     // Формируем полноценный путь.
     $path = 'http://' . $path;
     // Готово.
     $ctx->redirect($path, Redirect::OTHER);
 }
示例#3
0
 /**
  * Returns a peer instance associated with this om.
  *
  * Since Peer classes are not to have any instance attributes, this method returns the
  * same instance for all member of this class. The method could therefore
  * be static, but this would prevent one from overriding the behavior.
  *
  * @return     RoutePeer
  */
 public function getPeer()
 {
     if (self::$peer === null) {
         self::$peer = new RoutePeer();
     }
     return self::$peer;
 }
示例#4
0
 public static function on_post_delete(Context $ctx)
 {
     $map = BaseRoute::load($ctx);
     foreach ((array) $ctx->post('delete') as $path) {
         if (array_key_exists($key = $path, $map)) {
             unset($map[$key]);
         } else {
             throw new PageNotFoundException(t('Путь <tt>%path</tt> не найден.', array('%path' => $path)));
         }
     }
     BaseRoute::save($map);
     return $ctx->getRedirect(self::listurl);
 }
示例#5
0
 private static function get_pages_for(Context $ctx, $name)
 {
     $pages = array();
     foreach (BaseRoute::load($ctx) as $k => $v) {
         if (isset($v['widgets']) and in_array($name, (array) $v['widgets'])) {
             $pages[] = $k;
         }
     }
     return $pages;
 }