-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathModule.php
82 lines (71 loc) · 2.13 KB
/
Module.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
<?php
/**
* Phanbook : Delightfully simple forum and Q&A software
*
* Licensed under The GNU License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @link http://phanbook.com Phanbook Project
* @since 1.0.0
* @author Phanbook <[email protected]>
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
*/
namespace Phanbook\Demo;
use Phalcon\Loader;
use Phalcon\DiInterface;
use Phanbook\Common\Module as BaseModule;
use Phanbook\Common\Library\Events\UserLogins;
use Phanbook\Common\Library\Events\ViewListener;
/**
* \Phanbook\Demo\Module
*
* @package Phanbook\Demo
*/
class Module extends BaseModule
{
/**
* {@inheritdoc}
*
* @return string
*/
public function getHandlersNamespace()
{
return 'Phanbook\Demo\Controllers';
}
/**
* Registers an autoloader related to the module.
*
* @param DiInterface $di
*/
public function registerAutoloaders(DiInterface $di = null)
{
$loader = new Loader();
$namespaces = [
$this->getHandlersNamespace() => __DIR__ . '/controllers/',
'Phanbook\Demo\Forms' => __DIR__ . '/forms/',
];
$loader->registerNamespaces($namespaces, true);
$loader->register();
}
/**
* Registers services related to the module.
*
* @param DiInterface $di
*/
public function registerServices(DiInterface $di)
{
// Read configuration
$moduleConfig = require_once __DIR__ . '/config/config.php';
$eventsManager = $di->getShared('eventsManager');
$eventsManager->attach('user', new UserLogins($di));
// Tune Up the URL Component
$url = $di->getShared('url');
$url->setBaseUri($moduleConfig->application->baseUri);
$eventsManager = $di->getShared('eventsManager');
$eventsManager->attach('view:notFoundView', new ViewListener($di));
// Setting up the View Component
$view = $di->getShared('view');
$view->setViewsDir($moduleConfig->application->viewsDir);
}
}