diff --git a/system/Version/autoload.php b/system/Version/autoload.php index aed14d4..d4d84de 100644 --- a/system/Version/autoload.php +++ b/system/Version/autoload.php @@ -31,13 +31,15 @@ } /** - * Return Phacil Framework version + * Return Phacil Framework version or composer package version + * + * @param string $package (Optional) If empty, return the current framework version * * @return string|false */ - public function get() + public function get($package = null) { - return $this->framework; + return (!$package) ? $this->framework : $this->getPackageVersion($package); //return file_get_contents(\Phacil\Framework\Config::DIR_SYSTEM() . "engine/VERSION"); } @@ -58,7 +60,6 @@ } /** - * * @return string|false */ public function getPHPVersion() { @@ -74,7 +75,7 @@ /** * - * @param mixed $package + * @param string $package * @return string|null * @throws \Phacil\Framework\Exception\OutOfBoundsException */ diff --git a/system/engine/api/preactions.php b/system/engine/api/preactions.php new file mode 100644 index 0000000..397f224 --- /dev/null +++ b/system/engine/api/preactions.php @@ -0,0 +1,14 @@ +pre_action[] = $pre_action; + return $this; } diff --git a/system/engine/preactions.php b/system/engine/preactions.php new file mode 100644 index 0000000..aed0401 --- /dev/null +++ b/system/engine/preactions.php @@ -0,0 +1,43 @@ +preActions = $preActions; + $this->registry = $registry; + + $this->createPreActions(); + } + + protected function createPreActions() { + foreach ($this->preActions as $preAction){ + $this->handlers[] = $this->registry->create(\Phacil\Framework\Action::class, $preAction); + } + } + + /** {@inheritdoc} */ + public function getHandlers() { + return $this->handlers; + } +} \ No newline at end of file diff --git a/system/engine/registry.php b/system/engine/registry.php index f299d06..9df2d0d 100644 --- a/system/engine/registry.php +++ b/system/engine/registry.php @@ -147,8 +147,8 @@ final class Registry { if($onlyCheckInstances) return $return; if(is_string($class)) { - $classCreate = self::checkPreference($class); - return self::getInstance()->injectionClass($classCreate, $args, true); + //$classCreate = self::checkPreference($class); + return self::getInstance()->injectionClass($class, $args, true); } if (is_object($class)) { diff --git a/system/etc/preferences.json b/system/etc/preferences.json index a16a926..f34bd7e 100644 --- a/system/etc/preferences.json +++ b/system/etc/preferences.json @@ -4,6 +4,21 @@ "Phacil\\Framework\\Interfaces\\Url": "Phacil\\Framework\\Url", "Phacil\\Framework\\Databases\\Api\\Object\\ItemInterface": "Phacil\\Framework\\Databases\\Object\\Item", "Phacil\\Framework\\Api\\Database": "Phacil\\Framework\\Database", + "Phacil\\Framework\\Interfaces\\Front": { + "preference": "Phacil\\Framework\\Front" + }, + "Phacil\\Framework\\Api\\PreActions": { + "preference": "Phacil\\Framework\\PreActions", + "arguments": { + "preActions": [ + [ + "url/seo_url", + [], + "SYSTEM" + ] + ] + } + }, "Cm\\RedisSession\\Handler\\ConfigInterface": { "preference": "Phacil\\Framework\\Session\\Redis\\Config" }, diff --git a/system/system.php b/system/system.php index 4940bdb..a4dd2b8 100644 --- a/system/system.php +++ b/system/system.php @@ -331,11 +331,13 @@ final class startEngineExacTI { /** * Add controller system pre-actions - * @return array + * @return \Phacil\Framework\Action[] * @since 1.5.1 */ public function controllerPreActions() { - return (isset($this->preActions) && is_array($this->preActions)) ? $this->preActions : []; + /** @var \Phacil\Framework\Api\PreActions */ + $preactions = $this->registry->getInstance(\Phacil\Framework\Api\PreActions::class); + return $preactions->getHandlers(); } /** @@ -624,20 +626,21 @@ try { $engine->extraRegistrations(); // Front Controller - $frontController = new Front($engine->registry); + /** @var \Phacil\Framework\Interfaces\Front */ + $frontController = $engine->registry->getInstance(\Phacil\Framework\Interfaces\Front::class); //new Front($engine->registry); // SEO URL's - $frontController->addPreAction(new Action((string) 'url/seo_url', [], \Phacil\Framework\Interfaces\Action::SYSTEM)); + //$frontController->addPreAction($engine->registry->create(\Phacil\Framework\Action::class, array((string) 'url/seo_url', [], \Phacil\Framework\Interfaces\Action::SYSTEM))); //extraPreActions if ($engine->controllerPreActions()) { foreach ($engine->controllerPreActions() as $action) { - $frontController->addPreAction(new Action($action)); + $frontController->addPreAction($action); } } // Router - $action = new Action(startEngineExacTI::getRoute()); + $action = $engine->registry->create(\Phacil\Framework\Action::class, array(startEngineExacTI::getRoute())); // Dispatch $not_found = \Phacil\Framework\Config::NOT_FOUND() ?: \Phacil\Framework\Config::NOT_FOUND('error/not_found'); @@ -645,7 +648,7 @@ try { // Output $engine->response->output(); + } catch (\Exception $th) { $engine->terminate($th); - //throw new \Exception($th->getMessage(), $th->getCode(), $th); } \ No newline at end of file diff --git a/system/url/seo_url.php b/system/url/seo_url.php index 669fcff..5eb7f93 100644 --- a/system/url/seo_url.php +++ b/system/url/seo_url.php @@ -43,7 +43,10 @@ class SystemUrlSeoUrl extends ControllerController { } - /** @return Action|void */ + /** + * @return Action|void + * @todo + */ public function index() { // Add rewrite to url class if ($this->config->get('config_seo_url')) { @@ -58,24 +61,26 @@ class SystemUrlSeoUrl extends ControllerController { $parts = array(Request::GET('_route_')); foreach ($parts as $part) { - if(Config::USE_DB_CONFIG()) - $query = $this->db->query("SELECT * FROM url_alias WHERE keyword = '" . $this->db->escape($part) . "'"); - - if (isset($query) && $query != false && $query->num_rows === 1) { + if(Config::USE_DB_CONFIG()){ + $query = $this->db->query()->select()->setTable("url_alias"); + $query->where()->eq('keyword', $part); + $query = $query->load(); - //$url = explode('=', $query->row['query']); + if (isset($query) && $query != false && $query->getNumRows() === 1) { + $row = $query->getRow(); - if($query->row['get'] != "") { - $a = explode(',', $query->row['get']); + if(!empty($row->getValue('get'))) { + $a = explode(',', $row->getValue('get')); - foreach($a as $value) { - $b = explode('=', $value); - $_GET[$b[0]] = $b[1]; + foreach($a as $value) { + $b = explode('=', $value); + $_GET[$b[0]] = $b[1]; + Request::GET($b[0], $b[1]); + } } - } - - Request::GET('route', $query->row['query']); + Request::GET('route', $row->getValue('query')); + } } elseif (Config::ROUTES() && is_array(Config::ROUTES())) { $rotas = Config::ROUTES(); @@ -132,6 +137,7 @@ class SystemUrlSeoUrl extends ControllerController { /** * @param string $link * @return string + * @todo */ public function rewrite($link) { if ($this->config->get('config_seo_url')) {