/** *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; }
/** *This method deconstructs the source string into array of tags, text and a combination of all. * *@param string $source The source content to parse *@return array Array containing all the deconstructed parts in one multidimensional array */ protected function getArray($source) { //define the parts array $parts = array(); //define the tags array $tags = array(); //define the all array $all = array(); //set the type to null $type = null; //set the delimiter to null $delimiter = null; //loop through the source string performing actions while ($source) { //search for a tag match $match = $this->getImplementation->match($source); //get the type $type = $match['type']; //get the delimiter $delimiter = $match['delimiter']; //get the opener string position $opener = strpos($source, $type['opener']); //get the closer string position $closer = strpos($source, $type['closer']) + strlen($type['closer']); //check if the opener was found if ($opener != false) { //get the string before the opening tags $parts[] = substr($source, 0, $opener); //get the string from opening and closing tags $tags[] = substr($source, $opener, $closer - $opener); //remove part of source that has already been processed $source = substr($source, $closer); } else { //assign whole string to parts $parts[] = $source; //set the source to empty $source = ''; } } //start processing the parts collected foreach ($parts as $i => $part) { //add the parts together $all[] = $part; //check if tag with this index is present if (isset($tags[$i])) { //add the tags to array $all[] = $tags[$i]; } } //clean the tags, parts and full source string array and return return array('text' => ArrayUtility::clean($parts), 'tags' => ArrayUtility::clean($tags), 'all' => ArrayUtility::clean($all)); }