/**
  * The internal _parse() method uses a fairly simple regular expression to match key/value pairs
  * within the Doc Comment string returned by any of our _get…Meta() methods
  * 
  * @param type $comment
  * @return type
  */
 protected function _parse($comment)
 {
     $meta = array();
     $pattern = '(@[a-zá-žA-ZÁ-Ž]+\\s*[a-zá-žA-ZÁ-Ž0-9, ()_]*)';
     $matches = StringMethods::match($comment, $pattern);
     if ($matches != null) {
         foreach ($matches as $match) {
             $parts = ArrayMethods::clean(ArrayMethods::trim(StringMethods::split($match, '[\\s]', 2)));
             $meta[$parts[0]] = true;
             if (count($parts) > 1) {
                 $meta[$parts[0]] = ArrayMethods::clean(ArrayMethods::trim(StringMethods::split($parts[1], ',')));
             }
         }
     }
     return $meta;
 }
 /**
  * 
  * @return type
  */
 public function first()
 {
     $limit = $this->_limit;
     $offset = $this->_offset;
     $this->limit(1);
     $all = $this->all();
     $first = ArrayMethods::first($all);
     if ($limit) {
         $this->_limit = $limit;
     }
     if ($offset) {
         $this->_offset = $offset;
     }
     return $first;
 }
 /**
  * The _tree() method loops through the array of template segments, 
  * generated by the _array() method, and organizes them into a hierarchical structure. 
  * Plain text nodes are simply assigned as-is to the tree, while additional metadata is 
  * generated and assigned with the tags. One important thing to note is that certain 
  * statements have an isolated property. This specifies whether text is allowed before the statement. 
  * When the loop gets to an isolated tag, it removes the preceding segment 
  * (as long as it is a plain text segment), so that the resultant function 
  * code is syntactically correct. The last bit of template processing we need to do is 
  * convert the template tree into a PHP function. This will allow us to reuse 
  * the template without having to recompile it.
  * 
  * @param array $array
  * @return array
  */
 protected function _tree($array)
 {
     $root = array("children" => array());
     $current =& $root;
     foreach ($array as $i => $node) {
         $result = $this->_tag($node);
         if ($result) {
             $tag = isset($result["tag"]) ? $result["tag"] : "";
             $arguments = isset($result["arguments"]) ? $result["arguments"] : "";
             if ($tag) {
                 if (!$result["closer"]) {
                     $last = ArrayMethods::last($current["children"]);
                     if ($result["isolated"] && is_string($last)) {
                         array_pop($current["children"]);
                     }
                     $current["children"][] = array("index" => $i, "parent" => &$current, "children" => array(), "raw" => $result["source"], "tag" => $tag, "arguments" => $arguments, "delimiter" => $result["delimiter"], "number" => count($current["children"]));
                     $current =& $current["children"][count($current["children"]) - 1];
                 } else {
                     if (isset($current["tag"]) && $result["tag"] == $current["tag"]) {
                         $start = $current["index"] + 1;
                         $length = $i - $start;
                         $current["source"] = implode(array_slice($array, $start, $length));
                         $current =& $current["parent"];
                     }
                 }
             } else {
                 $current["children"][] = array("index" => $i, "parent" => &$current, "children" => array(), "raw" => $result["source"], "tag" => $tag, "arguments" => $arguments, "delimiter" => $result["delimiter"], "number" => count($current["children"]));
             }
         } else {
             $current["children"][] = $node;
         }
     }
     return $root;
 }
示例#4
0
 /**
  * Extends configuration loaded from config file for configuration loaded
  * form database
  */
 public function extendForDbConfig()
 {
     $ca = Config::all();
     if ($ca !== null) {
         foreach ($ca as $key => $value) {
             $this->_configArrMerged[$value->xkey] = $value->value;
         }
         $this->_parsed = ArrayMethods::toObject($this->_configArrMerged);
         Registry::set('configuration', $this->_parsed);
     }
 }