/** *This constructor initializes the $url string variable * *@param string $url The url request string *@return Object \UrlParser */ public function __construct($url) { //assign the input string value to the $urlString property $this->urlString = StringHelper::removeTags($url); //call the helper class to split the url string to array components and assign value to $urlComponentsArray property $this->urlComponentsArray = ArrayHelper::parts($this->urlSeparator, $this->urlString)->clean()->trim()->get(); //return this object instance return $this; }
/** *This method sets the value of the method name * *@param null *@return Object \RouteParser */ public function setMethod() { //check if method metadata is null if (is_null($this->methodMetaData)) { //if there was no method metaData check if there are names url param keys in the controller name $requestParamKeys = ArrayHelper::parts($this->urlParameterSeparator, $this->controller)->clean()->trim()->get(); //check if there are parameter found if (count($requestParamKeys) > 1) { //set the new value of the controller $this->controller = $requestParamKeys[0]; //set a value for the methodMetaData $this->methodMetaDataArray = $requestParamKeys; } //there is no method frm the routes, get the route from the UrlParser instance $this->method = $this->UrlParserObjectInstance->getMethod(); return $this; } else { //get the methodMetaDataArray $methodMetaDataArray = ArrayHelper::parts($this->urlParameterSeparator, $this->methodMetaData)->clean()->trim()->get(); //put this in a try...catch block to enhance error handlign try { if (count($methodMetaDataArray) > 0) { //set the value of the method property $this->method = $methodMetaDataArray[0]; //check if the value of method from url parse is not null if ($this->UrlParserObjectInstance->getMethod() !== null) { //if the method name can be got from the methodMetaData, then lets prepend the value of method to the urlParser parameters $this->UrlParserObjectInstance->setParameters($this->UrlParserObjectInstance->getMethod(), false); } //set the methodMetaDataArray property $this->methodMetaDataArray = $methodMetaDataArray; //returnt this class instance return $this; } else { //throw an exception throw new RouteException(get_class(new RouteException()) . " : The method name specified after this named route " . $this->routeName . " => " . $this->controller . "@" . $this->methodMetaData . " is invalid format", 1); } } catch (RouteException $RouteExceptionObjectInstance) { //display the error message $RouteExceptionObjectInstance->errorShow(); } } }