From f9050181d0702e0950c676037c61d93dc091c141 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Mon, 18 Jun 2018 16:46:40 +0200 Subject: [PATCH] app/library/Bootstrap.php: revove "Application" and add "Services" class with the services definitions. Had some wierd problem with closures an $this when being defined in one class and used in another (defined in Application, used in Phalcon\Di\FactoryDefault). So we move all of this to "Services" class that directly extends FactoryDefault DI. And therefore, we don't need a Application class anymore. --- app/library/{Application.php => Services.php} | 40 +++---------------- public/index.php | 4 +- 2 files changed, 8 insertions(+), 36 deletions(-) rename app/library/{Application.php => Services.php} (93%) diff --git a/app/library/Application.php b/app/library/Services.php similarity index 93% rename from app/library/Application.php rename to app/library/Services.php index a517fb7..2dea742 100644 --- a/app/library/Application.php +++ b/app/library/Services.php @@ -2,7 +2,7 @@ namespace Httpcb; -use Phalcon\Di\DiInterface, +use Phalcon\DiInterface, Phalcon\Di\FactoryDefault as DiDefault, Phalcon\Config\Adapter\Yaml as Config, Phalcon\Mvc\View, @@ -32,25 +32,12 @@ use App\Listener\AclListener, App\Listener\DispatchListener, App\Listener\ActivityLog; - -class Application extends \Phalcon\Mvc\Application +class Services extends DiDefault { - public function __construct(\Phalcon\DiInterface $di = null) + public function __construct() { - if ($di === null) { - $di = new DiDefault(); - } + parent::__construct(); - parent::__construct($di); - } - - /** - * Bootstrap the application (register services) - * - * @return Application - */ - public function bootstrap() - { $reflection = new \ReflectionObject($this); $methods = $reflection->getMethods(\ReflectionMethod::IS_PROTECTED); @@ -58,28 +45,13 @@ class Application extends \Phalcon\Mvc\Application if (substr($method->getName(),0, 11) == '_initShared') { $service = lcfirst(substr($method->getName(), 11)); - $this->di->setShared($service, $method->getClosure($this)); + $this->setShared($service, $method->getClosure($this)); } else if (substr($method->getName(),0, 5) == '_init') { $service = lcfirst(substr($method->getName(), 5)); - $this->di->set($service, $method->getClosure($this)); + $this->set($service, $method->getClosure($this)); } } - - return $this; - } - - /** - * @return string - */ - public function run() - { - return $this->handle()->getContent(); - } - - public function get($service, $parameters = null) - { - return $this->di->get($service, $parameters); } protected function _initSharedConfig() diff --git a/public/index.php b/public/index.php index f87dc1c..6862c0a 100644 --- a/public/index.php +++ b/public/index.php @@ -19,5 +19,5 @@ include APP_PATH . "/app/config/loader.php"; /** * Handle the request */ -$app = new Httpcb\Application(); -echo $app->bootstrap()->run(); +$app = new Phalcon\Mvc\Application(new Httpcb\Services()); +echo $app->handle()->getContent();