/** * Parse URI text elements to transform them into parameters, feature name and controller name * * @example $uri = ['order', 148, 'form') will result on controller 'Order_Form' with parameter 'Order' = 148 * @param $uri string[] */ private function parseUri($uri) { // get main object = controller name $key = 0; $controller_element = ''; foreach ($uri as $key => $controller_element) { if (ctype_lower($controller_element[0]) || is_numeric($controller_element)) { break; } } if ($controller_element && ctype_upper($controller_element[0])) { $key++; } $this->controller_name = join(BS, array_slice($uri, 0, $key)); $uri = array_splice($uri, $key); // get main object (as first parameter) and feature name $this->feature_name = array_shift($uri); $this->parameters = new Parameters($this); if (is_numeric($this->feature_name)) { $this->parameters->set($this->controller_name, intval($this->feature_name)); $this->feature_name = array_shift($uri); if (!$this->feature_name) { $this->feature_name = Feature::F_OUTPUT; } } elseif ($this->controller_name && !$this->feature_name) { if (@class_exists($this->controller_name)) { $this->feature_name = Feature::F_ADD; } elseif (@class_exists(Names::setToClass($this->controller_name))) { $this->feature_name = Feature::F_LIST; } else { $this->feature_name = Feature::F_DEFAULT; } } // get main parameters $controller_elements = []; foreach ($uri as $uri_element) { if (ctype_upper($uri_element[0])) { $controller_elements[] = $uri_element; } else { if (is_numeric($uri_element)) { $this->parameters->set(join(BS, $controller_elements), intval($uri_element)); } else { if ($controller_elements) { $this->parameters->addValue(join(BS, $controller_elements)); } $this->parameters->addValue($uri_element); } $controller_elements = []; } } if ($controller_elements) { $this->parameters->addValue(join(BS, $controller_elements)); } }