Skip to content

Commit 6fc9ebe

Browse files
committed
Tidied up the Simple Volt example.
1 parent 5e14183 commit 6fc9ebe

File tree

4 files changed

+105
-64
lines changed

4 files changed

+105
-64
lines changed

simple-volt/app/config/config.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
<?php
22

3-
return new \Phalcon\Config(array(
4-
'database' => array(
5-
'adapter' => 'Mysql',
6-
'host' => 'localhost',
7-
'username' => 'root',
8-
'password' => '',
9-
'dbname' => 'test',
10-
),
11-
'application' => array(
12-
'controllersDir' => __DIR__ . '/../../app/controllers/',
13-
'modelsDir' => __DIR__ . '/../../app/models/',
14-
'viewsDir' => __DIR__ . '/../../app/views/',
15-
'pluginsDir' => __DIR__ . '/../../app/plugins/',
16-
'libraryDir' => __DIR__ . '/../../app/library/',
17-
'cacheDir' => __DIR__ . '/../../app/cache/',
18-
'baseUri' => '/mvc/simple-volt/',
19-
)
20-
));
3+
use Phalcon\Config;
4+
5+
return new Config(
6+
[
7+
"database" => [
8+
"adapter" => "Mysql",
9+
"host" => "localhost",
10+
"username" => "root",
11+
"password" => "",
12+
"dbname" => "test",
13+
],
14+
"application" => [
15+
"controllersDir" => __DIR__ . "/../../app/controllers/",
16+
"modelsDir" => __DIR__ . "/../../app/models/",
17+
"viewsDir" => __DIR__ . "/../../app/views/",
18+
"pluginsDir" => __DIR__ . "/../../app/plugins/",
19+
"libraryDir" => __DIR__ . "/../../app/library/",
20+
"cacheDir" => __DIR__ . "/../../app/cache/",
21+
"baseUri" => "/mvc/simple-volt/",
22+
],
23+
]
24+
);

simple-volt/app/config/loader.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
<?php
22

3-
$loader = new \Phalcon\Loader();
3+
use Phalcon\Loader;
4+
5+
$loader = new Loader();
46

57
/**
68
* We're a registering a set of directories taken from the configuration file
79
*/
810
$loader->registerDirs(
9-
array(
11+
[
1012
$config->application->controllersDir,
11-
$config->application->modelsDir
12-
)
13-
)->register();
13+
$config->application->modelsDir,
14+
]
15+
);
16+
17+
$loader->register();

simple-volt/app/config/services.php

Lines changed: 74 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,72 +7,106 @@
77
use Phalcon\Mvc\View\Engine\Volt as VoltEngine;
88
use Phalcon\Mvc\Model\Metadata\Memory as MetaDataAdapter;
99
use Phalcon\Session\Adapter\Files as SessionAdapter;
10+
use Phalcon\Mvc\View\Engine\Php as PhpViewEngine;
1011

1112
/**
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
1315
*/
1416
$di = new FactoryDefault();
1517

1618
/**
1719
* The URL component is used to generate all kind of urls in the application
1820
*/
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+
);
2434

2535
/**
2636
* Setting up the view component
2737
*/
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();
3142

32-
$view->setViewsDir($config->application->viewsDir);
43+
$view->setViewsDir(
44+
$config->application->viewsDir
45+
);
3346

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);
3651

37-
$volt = new VoltEngine($view, $di);
52+
$volt->setOptions(
53+
[
54+
"compiledPath" => $config->application->cacheDir,
55+
"compiledSeparator" => "_",
56+
]
57+
);
3858

39-
$volt->setOptions(array(
40-
'compiledPath' => $config->application->cacheDir,
41-
'compiledSeparator' => '_',
42-
));
59+
return $volt;
60+
},
4361

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+
);
4866

49-
return $view;
50-
}, true);
67+
return $view;
68+
},
69+
true
70+
);
5171

5272
/**
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
5475
*/
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+
);
6389

6490
/**
6591
* If the configuration specify the use of metadata adapter use it or use memory otherwise
6692
*/
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+
);
7099

71100
/**
72101
* Start the session the first time some component request the session service
73102
*/
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+
);

simple-volt/app/controllers/IndexController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
class IndexController extends ControllerBase
44
{
5-
65
public function indexAction()
76
{
87
}

0 commit comments

Comments
 (0)