/** * Configure the routing in a function * @param array $config */ public function configRouting(array $config) { if (!empty($config['error']) || !empty($config['start'])) { PWEL_ROUTING::$error_controller = $config['error']; PWEL_ROUTING::$start_controller = $config['start']; } else { $this->autoConfigRouting(); } if (!empty($config['autosearch'])) { PWEL_ROUTING::$autoSearch = $config['autosearch']; } if (!empty($config['namespace'])) { PWEL_ROUTING::$namespace = $config['namespace']; } if (!empty($config['namespacerange'])) { PWEL_ROUTING::$namespaceRange = $config['namespacerange']; } self::$configured = true; }
/** * Returns the path to the displayed file * @param string $filename * @return string */ private function getDisplayPath($filename) { if (preg_match_all('/(.*)\\.(php|html|phtml)/i', $filename, $result)) { if (isset($result[2])) { $filename = $result[1][0]; $extension = "." . $result[2][0]; } else { $extension = ".php"; } } else { $extension = ".php"; } PWEL_ROUTING::correctNamespace(); if (PWEL_ROUTING::$autoSearch == true) { if (isset($extension)) { $searchname = $filename . $extension; } else { $searchname = $filename; } PWEL_ROUTING::autoSearch('app/views/', $searchname); PWEL_ROUTING::$searchResult = str_replace('app/views/', '', PWEL_ROUTING::$searchResult); $namespace = null; } else { $namespace = PWEL_ROUTING::$namespace; } //Set & Correct path $path = PWEL_ROUTING::$relative_path . 'app/views/' . PWEL_ROUTING::$searchResult . $namespace . "{$filename}{$extension}"; return str_replace('//', '/', $path); }
/** * Function which will be automaticly loaded * Execute the component */ public function _execute() { $routing = new PWEL_ROUTING(); $relativePath = $routing->requestRelativePath(); if (self::$visible == true && PWEL_ROUTING::$controllerNotFound == false) { PWEL_ROUTING::autoSearch('app/views/', self::$file); #var_dump(PWEL_ROUTING::$searchResult); $path = $relativePath . PWEL_ROUTING::$searchResult . self::$file; if (file_exists($path)) { $this->display(self::$file, (array) self::$variables); } else { throw new Exception("File: <i>{$path}</i> doenst exist.<br /> <strong>Using '" . "PWEL_ROUTING::\$namespaceRange' and missing adding " . "directory to file?</strong>"); } } }