示例#1
0
 function testAutoCreateCD()
 {
     $tree = \arc\tree::expand();
     $tree->cd('foo')->nodeValue = 'bar';
     $collapsed = \arc\tree::collapse($tree);
     $this->assertTrue($collapsed == array('/foo/' => 'bar'));
 }
示例#2
0
文件: config.php 项目: poef/ariadne
 public static function getConfiguration()
 {
     $context = \arc\context::$context;
     if (!$context->arcConfig) {
         $context->arcConfig = new config\Configuration(\arc\tree::expand()->cd($context->arcPath));
     }
     return $context->arcConfig;
 }
示例#3
0
文件: events.php 项目: poef/ariadne
 /**
  *	Factory method for the static stack. Returns the shared stack only. Use new \arc\events\Stack
  *	or your own factory method to create a seperate Stack instance.
  */
 public static function getEventsTree()
 {
     $context = \arc\context::$context;
     if (!$context->arcEvents) {
         $context->arcEvents = new events\EventsTree(\arc\tree::expand()->cd($context->arcPath));
     }
     return $context->arcEvents;
 }
示例#4
0
文件: grants.php 项目: poef/ariadne
 public static function getGrantsTree()
 {
     $context = \arc\context::$context;
     if (!$context->arcUser) {
         $context->arcUser = '******';
     }
     if (!$context->arcGroups) {
         $context->arcGroups = ['public'];
     }
     if (!$context->arcGrants) {
         $context->arcGrants = new grants\GrantsTree(\arc\tree::expand()->cd($context->arcPath), $context->arcUser, $context->arcGroups);
     }
     return $context->arcGrants;
 }
示例#5
0
文件: route.php 项目: poef/ariadne
 /**
  * Matches a path or url to a list of routes and calls the best matching route handler.
  * @param string $path
  * @param mixed $routes A tree of routes with handlers as nodeValue.
  * @return array|bool
  */
 public static function match($path, $routes)
 {
     $routes = \arc\tree::expand($routes);
     $controller = \arc\tree::dive($routes->cd($path), function ($node) {
         if (isset($node->nodeValue)) {
             return $node;
         }
     });
     if ($controller) {
         $remainder = substr($path, strlen($controller->getPath()));
         if (is_callable($controller->nodeValue)) {
             $result = call_user_func($controller->nodeValue, $remainder);
         } else {
             $result = $controller->nodeValue;
         }
         return ['path' => $controller->getPath(), 'remainder' => $remainder, 'result' => $result];
     }
     return false;
 }
示例#6
0
文件: hash.php 项目: poef/ariadne
 /**
  * Converts a hash to a \arc\tree\NamedNode
  * @param $hash
  * @param null $parent
  * @return tree\NamedNode|null
  */
 public static function tree($hash, $parent = null)
 {
     if (!isset($parent)) {
         $parent = \arc\tree::expand();
     }
     if (is_array($hash) || $hash instanceof \Traversable) {
         foreach ($hash as $index => $value) {
             $child = $parent->appendChild(self::escape($index));
             if (is_array($value)) {
                 self::tree($value, $child);
             } else {
                 $child->nodeValue = $value;
             }
         }
     } else {
         $parent->nodeValue = $hash;
     }
     return $parent;
 }
示例#7
0
 public function unserialize($data)
 {
     return \arc\tree::expand(unserialize($data));
 }