forked from phalcon/incubator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication.php
112 lines (94 loc) · 3.26 KB
/
Application.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/*
+------------------------------------------------------------------------+
| Phalcon Framework |
+------------------------------------------------------------------------+
| Copyright (c) 2011-2016 Phalcon Team (https://www.phalconphp.com) |
+------------------------------------------------------------------------+
| This source file is subject to the New BSD License that is bundled |
| with this package in the file LICENSE.txt. |
| |
| If you did not receive a copy of the license and are unable to |
| obtain it through the world-wide-web, please send an email |
| to [email protected] so we can send you a copy immediately. |
+------------------------------------------------------------------------+
| Authors: Andres Gutierrez <[email protected]> |
| Eduar Carvajal <[email protected]> |
| Nikita Vershinin <[email protected]> |
+------------------------------------------------------------------------+
*/
namespace Phalcon\Error;
use Phalcon\Config;
use Phalcon\DI\FactoryDefault;
use Phalcon\DiInterface;
use Phalcon\Error\Handler as ErrorHandler;
use Phalcon\Loader;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Mvc\View;
class Application extends \Phalcon\Mvc\Application
{
const ENV_PRODUCTION = 'production';
const ENV_STAGING = 'staging';
const ENV_TEST = 'test';
const ENV_DEVELOPMENT = 'development';
/**
* Class constructor registers autoloading and error
* handler.
*
* @param mixed $dependencyInjector
* @return \Phalcon\Error\Application
*/
public function __construct(DiInterface $dependencyInjector = null)
{
$this->registerAutoloaders();
ErrorHandler::register();
parent::__construct($dependencyInjector);
}
/**
* Registers the services and dispatches the application.
*
* @return \Phalcon\Http\Response
*/
public function main()
{
$this->registerServices();
return $this->handle()->send();
}
/**
* Registers autoloading.
*
* @return void
*/
private function registerAutoloaders()
{
$loader = new Loader();
$loader->registerNamespaces(['Phalcon\Error' => '.']);
$loader->register();
}
/**
* Registers the services in di container.
*
* @return void
*/
private function registerServices()
{
$di = new FactoryDefault();
$di->set('config', function () {
ob_start();
$config = include APPLICATION_ENV . '.php';
ob_end_clean();
return new Config($config);
});
$di->set('dispatcher', function () {
$dispatcher = new Dispatcher();
$dispatcher->setDefaultNamespace('Application\Controllers\\');
return $dispatcher;
});
$di->set('view', function () {
$view = new View();
$view->setViewsDir(ROOT_PATH . '/application/views/');
return $view;
});
$this->setDI($di);
}
}