예제 #1
0
파일: tree.Test.php 프로젝트: poef/ariadne
 function testAutoCreateCD()
 {
     $tree = \arc\tree::expand();
     $tree->cd('foo')->nodeValue = 'bar';
     $collapsed = \arc\tree::collapse($tree);
     $this->assertTrue($collapsed == array('/foo/' => 'bar'));
 }
예제 #2
0
 public function acquire($name)
 {
     return \arc\tree::dive($this->tree, function ($node) use($name) {
         return $this->getValueIfRoot($name, $node->nodeValue);
     }, function ($node, $result) use($name) {
         return $this->mergeValue($result, $this->getValue($name, $node->nodeValue));
     });
 }
예제 #3
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;
 }
예제 #4
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;
 }
예제 #5
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;
 }
예제 #6
0
파일: tree.php 프로젝트: poef/ariadne
 /**
  * Calls the first callback method on each successive parent until a non-null value is returned. Then
  * calls all the parents from that point back to this node with the second callback in reverse order.
  * The first callback (dive) must accept one parameter, the node.
  * The second callback (rise) must accept two parameters, the nde and the result up to that point.
  * @param  \arc\tree\Node $node         A tree node, must have traversable childNodes property and a parentNode property
  * @param  callable       $diveCallback The callback for the dive phase.
  * @param  callable       $riseCallback The callback for the rise phase.
  * @return mixed
  */
 public static function dive($node, $diveCallback = null, $riseCallback = null)
 {
     $result = null;
     if (is_callable($diveCallback)) {
         $result = call_user_func($diveCallback, $node);
     }
     if (!isset($result) && $node->parentNode) {
         $result = \arc\tree::dive($node->parentNode, $diveCallback, $riseCallback);
     }
     if (is_callable($riseCallback)) {
         return call_user_func($riseCallback, $node, $result);
     } else {
         return $result;
     }
 }
예제 #7
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;
 }
예제 #8
0
파일: GrantsTree.php 프로젝트: poef/ariadne
 /**
  * @return string
  */
 private function fetchGrants()
 {
     $user = $this->user;
     $groups = array_fill_keys($this->groups, 1);
     $grants = (string) \arc\tree::dive($this->tree, function ($node) use($user) {
         if (isset($node->nodeValue['users'][$user])) {
             return $node->nodeValue['users'][$user];
         }
     }, function ($node, $grants) use(&$user, $groups) {
         if (!$user) {
             // don't do this for user grants the first time
             $grants = preg_replace(array('/\\=[^ ]*/', '/\\>([^ ]*)/'), array('', '$1'), $grants);
         }
         $user = false;
         foreach ($groups as $group) {
             if (isset($node->nodeValue['groups'][$group])) {
                 $grants .= $node->nodeValue['groups'][$group];
             }
         }
         return $grants;
     });
     return $grants;
 }
예제 #9
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;
 }
예제 #10
0
파일: NamedNode.php 프로젝트: poef/ariadne
 /**
  *  Calls a callback method on each child of this node, returns an array with name => result pairs.
  *  The callback method must accept two parameters, the name of the child and the child node itself.
  *  @param callable $callback The callback method to run on each child.
  *  @return array An array of result values with the name of each child as key.
  */
 public function ls($callback)
 {
     return \arc\tree::ls($this, $callback);
 }
예제 #11
0
파일: EventsTree.php 프로젝트: poef/ariadne
 /**
  *	Calls each listener with the given event untill a listener returns false.
  */
 private function walkListeners($event)
 {
     $callListeners = function ($listeners) use($event) {
         foreach ((array) $listeners as $listener) {
             $result = call_user_func($listener['method'], $event);
             if ($result === false) {
                 return false;
                 // this will stop \arc\path::walk, so other event handlers won't be called
             }
         }
     };
     $result = \arc\tree::parents($this->tree, function ($node, $result) use($callListeners, $event) {
         if ($result !== false && isset($node->nodeValue['capture.' . $event->name])) {
             return call_user_func($callListeners, $node->nodeValue['capture.' . $event->name]);
         }
     });
     if (!isset($result)) {
         $result = \arc\tree::dive($this->tree, function ($node) use($callListeners, $event) {
             if (isset($node->nodeValue['listen.' . $event->name])) {
                 return call_user_func($callListeners, $node->nodeValue['listen.' . $event->name]);
             }
         });
     }
     return !isset($result) ? true : false;
 }