|
7 | 7 | use Phalcon\Mvc\View\Engine\Volt as VoltEngine; |
8 | 8 | use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter; |
9 | 9 | use Phalcon\Session\Adapter\Files as SessionAdapter; |
| 10 | +use Phalcon\Mvc\View\Engine\Php as PhpViewEngine; |
10 | 11 |
|
11 | 12 | /** |
12 | | - * The FactoryDefault Dependency Injector automatically register the right services providing a full stack framework |
| 13 | + * The FactoryDefault Dependency Injector automatically registers the right |
| 14 | + * services to provide a full stack framework |
13 | 15 | */ |
14 | 16 | $di = new FactoryDefault(); |
15 | 17 |
|
16 | 18 | /** |
17 | 19 | * The URL component is used to generate all kind of urls in the application |
18 | 20 | */ |
19 | | -$di->set('url', function () use ($config) { |
20 | | - $url = new UrlResolver(); |
21 | | - $url->setBaseUri($config->application->baseUri); |
22 | | - return $url; |
23 | | -}, true); |
| 21 | +$di->set( |
| 22 | + "url", |
| 23 | + function () use ($config) { |
| 24 | + $url = new UrlResolver(); |
| 25 | + |
| 26 | + $url->setBaseUri( |
| 27 | + $config->application->baseUri |
| 28 | + ); |
| 29 | + |
| 30 | + return $url; |
| 31 | + }, |
| 32 | + true |
| 33 | +); |
24 | 34 |
|
25 | 35 | /** |
26 | 36 | * Setting up the view component |
27 | 37 | */ |
28 | | -$di->set('view', function () use ($config) { |
29 | | - |
30 | | - $view = new View(); |
| 38 | +$di->set( |
| 39 | + "view", |
| 40 | + function () use ($config) { |
| 41 | + $view = new View(); |
31 | 42 |
|
32 | | - $view->setViewsDir($config->application->viewsDir); |
| 43 | + $view->setViewsDir( |
| 44 | + $config->application->viewsDir |
| 45 | + ); |
33 | 46 |
|
34 | | - $view->registerEngines(array( |
35 | | - '.volt' => function ($view, $di) use ($config) { |
| 47 | + $view->registerEngines( |
| 48 | + [ |
| 49 | + ".volt" => function ($view, $di) use ($config) { |
| 50 | + $volt = new VoltEngine($view, $di); |
36 | 51 |
|
37 | | - $volt = new VoltEngine($view, $di); |
| 52 | + $volt->setOptions( |
| 53 | + [ |
| 54 | + "compiledPath" => $config->application->cacheDir, |
| 55 | + "compiledSeparator" => "_", |
| 56 | + ] |
| 57 | + ); |
38 | 58 |
|
39 | | - $volt->setOptions(array( |
40 | | - 'compiledPath' => $config->application->cacheDir, |
41 | | - 'compiledSeparator' => '_', |
42 | | - )); |
| 59 | + return $volt; |
| 60 | + }, |
43 | 61 |
|
44 | | - return $volt; |
45 | | - }, |
46 | | - '.phtml' => 'Phalcon\Mvc\View\Engine\Php' // Generate Template files uses PHP itself as the template engine |
47 | | - )); |
| 62 | + // Generate Template files uses PHP itself as the template engine |
| 63 | + ".phtml" => PhpViewEngine::class |
| 64 | + ] |
| 65 | + ); |
48 | 66 |
|
49 | | - return $view; |
50 | | -}, true); |
| 67 | + return $view; |
| 68 | + }, |
| 69 | + true |
| 70 | +); |
51 | 71 |
|
52 | 72 | /** |
53 | | - * Database connection is created based in the parameters defined in the configuration file |
| 73 | + * Database connection is created based on the parameters defined in the |
| 74 | + * configuration file |
54 | 75 | */ |
55 | | -$di->set('db', function () use ($config) { |
56 | | - return new DbAdapter(array( |
57 | | - 'host' => $config->database->host, |
58 | | - 'username' => $config->database->username, |
59 | | - 'password' => $config->database->password, |
60 | | - 'dbname' => $config->database->dbname |
61 | | - )); |
62 | | -}); |
| 76 | +$di->set( |
| 77 | + 'db', |
| 78 | + function () use ($config) { |
| 79 | + return new DbAdapter( |
| 80 | + [ |
| 81 | + "host" => $config->database->host, |
| 82 | + "username" => $config->database->username, |
| 83 | + "password" => $config->database->password, |
| 84 | + "dbname" => $config->database->dbname, |
| 85 | + ] |
| 86 | + ); |
| 87 | + } |
| 88 | +); |
63 | 89 |
|
64 | 90 | /** |
65 | 91 | * If the configuration specify the use of metadata adapter use it or use memory otherwise |
66 | 92 | */ |
67 | | -$di->set('modelsMetadata', function () use ($config) { |
68 | | - return new MetaDataAdapter(); |
69 | | -}); |
| 93 | +$di->set( |
| 94 | + "modelsMetadata", |
| 95 | + function () use ($config) { |
| 96 | + return new MetaDataAdapter(); |
| 97 | + } |
| 98 | +); |
70 | 99 |
|
71 | 100 | /** |
72 | 101 | * Start the session the first time some component request the session service |
73 | 102 | */ |
74 | | -$di->set('session', function () { |
75 | | - $session = new SessionAdapter(); |
76 | | - $session->start(); |
77 | | - return $session; |
78 | | -}); |
| 103 | +$di->set( |
| 104 | + "session", |
| 105 | + function () { |
| 106 | + $session = new SessionAdapter(); |
| 107 | + |
| 108 | + $session->start(); |
| 109 | + |
| 110 | + return $session; |
| 111 | + } |
| 112 | +); |
0 commit comments