/** *This method checks for the existance of a defined route * *@param string $name The name of the defined route to match *@return (bool) true|false True if route exists and false if not */ private function match($name) { //check if this route index exists $match = array_key_exists($name, $this->routes) ? true : false; //if this match is true, set the controller and method if ($match) { //get metaData for this route $routeMeta = $this->routes[$name]; //explode the metaData into controller and method $routeMetaArray = explode('@', $routeMeta); //procede if array has elements if (sizeof($routeMetaArray) > 0) { //sanitize routeMetaArray $routeMetaArray = ArrayUtility::trim(ArrayUtility::clean($routeMetaArray)); } //check if a controller is defined for this route try { if (!(int) array_key_exists(0, $routeMetaArray) || empty($routeMetaArray[0])) { throw new RouteControllerNotDefinedException("There is no controller associated with this route! -> " . $name); } //set the controller for this route $this->controller = $routeMetaArray[0]; } catch (RouteControllerNotDefinedException $error) { $error->show(); exit; } //set the method $this->method = isset($routeMetaArray[1]) ? $routeMetaArray[1] : null; //set the parameters array $this->parameters = @array_slice($routeMetaArray, 2); return true; } return false; }
/** * * */ public function first() { //get the limit clause value $limit = $this->limits; //get the offset value $limitOffset = $this->offset; //set the limit to 1 $this->limit(1); //get all $all = $this->all(); //get the first $first = ArrayUtility::first($all); //if limit is defined if ($limit) { //set the limit property $this->limits = $limit; } //if limit offset is set if ($limitOffset) { //set the offset $this->offset = $limitOffset; } //return the first query row return $first; }
/** *This method loops through the array of template segments generated by the array() method. *It organizes them into a hierachichal structure.Plain text nodes are simply assigned as-is to *the tree, while additional metadata is generated and assigned with the tags. * *@param array $array The deconstructed source string into array *@return array The composed hierachichal structure of tags */ protected function tree($array) { //define the root array $root = array('children' => array()); $current =& $root; //loop through the array of string segments foreach ($array as $i => $node) { //check if node has template tag in it $result = $this->tag($node); //process if a valid tag was found if ($result) { //get the tag itself $tag = isset($result['tags']) ? $result['tags'] : ''; //get the arguments for this tag $arguments = isset($result['arguments']) ? $result['arguments'] : ''; //if there was a valid tag, process if ($tag) { //check the type of tag if (!$result['closer']) { //get the last tag in this hierachy $last = ArrayUtility::last($current['children']); //check if this tag is isolated type if ($result['isolated'] && is_string($last)) { //remove this last item from the array array_pop($current['children']); } //populate metadata for this tag $current['children'][] = array('index' => $i, 'parent' => &$current, 'children' => array(), 'raw' => $result['source'], 'tag' => $tag, 'arguments' => $arguments, 'delimiter' => $result['delimiter'], 'number' => sizeof($current['children'])); //update the $current variable $current =& $current['children'][sizeof($current['children']) - 1]; } else { if (isset($current['tag']) && $result['tag'] == $current['tag']) { //get the start index $start = $current['index'] + 1; //get the lenght $length = $i - $start; //get the current source $current['source'] = implode(array_slice($array, $start, $length)); //get the current parent $current =& $current['parent']; } } } else { //add to current children $current['children'][] = array('index' => $i, 'parent' => &$current, 'children' => array(), 'raw' => $result['source'], 'tag' => $tag, 'arguments' => $arguments, 'delimiter' => $result['delimiter'], 'number' => sizeof($current['children'])); } } else { //add to the children array $current['children'][] = $node; } } //return the resultant root/current array return $root; }