Create a Bootstrap class and move bootstrap code from public/index.php
This commit is contained in:
parent
b3254e1f6c
commit
e85d935734
4 changed files with 61 additions and 26 deletions
|
|
@ -1,15 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
$loader = new \Phalcon\Loader();
|
|
||||||
|
|
||||||
$loader->registerNamespaces(array(
|
|
||||||
'App\Controller' => $config->application->controllersDir,
|
|
||||||
'App\Listener' => $config->application->listenersDir,
|
|
||||||
'App\Model' => $config->application->modelsDir,
|
|
||||||
'App\Form' => $config->application->formsDir,
|
|
||||||
'Httpcb' => $config->application->libraryDir,
|
|
||||||
));
|
|
||||||
|
|
||||||
$loader->register();
|
|
||||||
|
|
||||||
require_once __DIR__ . '/../../vendor/autoload.php';
|
|
||||||
33
app/library/Bootstrap.php
Normal file
33
app/library/Bootstrap.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Httpcb;
|
||||||
|
|
||||||
|
use Phalcon\Di\FactoryDefault as DiDefault;
|
||||||
|
use Phalcon\Di\Injectable;
|
||||||
|
use Phalcon\DiInterface;
|
||||||
|
use Phalcon\Mvc\Application;
|
||||||
|
|
||||||
|
class Bootstrap extends Injectable
|
||||||
|
{
|
||||||
|
public function __construct(DiInterface $di = null)
|
||||||
|
{
|
||||||
|
if ($di === null) {
|
||||||
|
$di = new DiDefault();
|
||||||
|
}
|
||||||
|
$this->setDI($di);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$app = new Application($this->getDI());
|
||||||
|
|
||||||
|
// Force autoloader if registered.
|
||||||
|
// Should be needed by almost all other services.
|
||||||
|
$di = $this->getDI();
|
||||||
|
if ($di->has('loader')) {
|
||||||
|
$di->get('loader');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $app->handle()->getContent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -69,6 +69,25 @@ class Services extends DiDefault
|
||||||
return $config;
|
return $config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function _initSharedLoader()
|
||||||
|
{
|
||||||
|
$config = $this->get('config');
|
||||||
|
$loader = new \Phalcon\Loader();
|
||||||
|
|
||||||
|
$loader->registerNamespaces(array(
|
||||||
|
'App\Controller' => $config->application->controllersDir,
|
||||||
|
'App\Listener' => $config->application->listenersDir,
|
||||||
|
'App\Model' => $config->application->modelsDir,
|
||||||
|
'App\Form' => $config->application->formsDir,
|
||||||
|
'Httpcb' => $config->application->libraryDir,
|
||||||
|
));
|
||||||
|
|
||||||
|
$loader->registerFiles(array(APP_PATH . '/vendor/autoload.php'));
|
||||||
|
$loader->register();
|
||||||
|
|
||||||
|
return $loader;
|
||||||
|
}
|
||||||
|
|
||||||
protected function _initSharedDispatcher()
|
protected function _initSharedDispatcher()
|
||||||
{
|
{
|
||||||
$config = $this->get('config');
|
$config = $this->get('config');
|
||||||
|
|
|
||||||
|
|
@ -2,22 +2,20 @@
|
||||||
|
|
||||||
defined('APP_PATH') || define('APP_PATH', realpath('..'));
|
defined('APP_PATH') || define('APP_PATH', realpath('..'));
|
||||||
|
|
||||||
/**
|
require_once APP_PATH . "/app/library/Bootstrap.php";
|
||||||
* Read the configuration
|
require_once APP_PATH . "/app/library/Services.php";
|
||||||
*/
|
|
||||||
$config = include APP_PATH . "/app/config/config.php";
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bootstrap the application.
|
||||||
|
*/
|
||||||
|
$bootstrap = new \Httpcb\Bootstrap(new Httpcb\Services());
|
||||||
|
|
||||||
|
$config = $bootstrap->getDI()->get('config');
|
||||||
if ($config->application->debug) {
|
if ($config->application->debug) {
|
||||||
(new Phalcon\Debug)->listen();
|
(new Phalcon\Debug)->listen();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Read auto-loader
|
|
||||||
*/
|
|
||||||
include APP_PATH . "/app/config/loader.php";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the request
|
* Handle the request
|
||||||
*/
|
*/
|
||||||
$app = new Phalcon\Mvc\Application(new Httpcb\Services());
|
echo $bootstrap->run();
|
||||||
echo $app->handle()->getContent();
|
|
||||||
|
|
|
||||||
Reference in a new issue