Archived
1
0
Fork 0

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.
This commit is contained in:
Henrik Hautakoski 2018-06-18 16:46:40 +02:00
parent e591c79133
commit f9050181d0
2 changed files with 8 additions and 36 deletions

View file

@ -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()

View file

@ -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();