1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Zemit Framework. |
5
|
|
|
* |
6
|
|
|
* (c) Zemit Team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE.txt |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Zemit\Cli; |
13
|
|
|
|
14
|
|
|
use Phalcon\Di\DiInterface; |
15
|
|
|
use Phalcon\Loader; |
16
|
|
|
use Phalcon\Mvc\ModuleDefinitionInterface; |
17
|
|
|
use Zemit\Bootstrap\Config; |
18
|
|
|
use Zemit\Utils; |
19
|
|
|
|
20
|
|
|
class Module implements ModuleDefinitionInterface |
21
|
|
|
{ |
22
|
|
|
public const NAME_CLI = 'cli'; |
23
|
|
|
|
24
|
|
|
public string $name; |
25
|
|
|
|
26
|
|
|
public Config $config; |
27
|
|
|
|
28
|
|
|
public Dispatcher $dispatcher; |
29
|
|
|
|
30
|
|
|
public Loader $loader; |
31
|
|
|
|
32
|
|
|
public Router $router; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Registers an autoloader related to the frontend module |
36
|
|
|
*/ |
37
|
|
|
public function registerAutoloaders(DiInterface $container = null): void |
38
|
|
|
{ |
39
|
|
|
$this->getServices($container); |
40
|
|
|
$this->loader->registerNamespaces($this->getNamespaces(), true); |
41
|
|
|
$this->loader->register(); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Registers services related to the module |
46
|
|
|
*/ |
47
|
|
|
public function registerServices(DiInterface $container): void |
48
|
|
|
{ |
49
|
|
|
$this->getServices($container); |
50
|
|
|
|
51
|
|
|
// dispatcher settings |
52
|
|
|
$defaultNamespace = $this->getDefaultNamespace(); |
53
|
|
|
$this->dispatcher->setDefaultNamespace($defaultNamespace); |
54
|
|
|
$this->dispatcher->setNamespaceName($defaultNamespace); |
55
|
|
|
|
56
|
|
|
// router settings |
57
|
|
|
$this->router->setDefaults([ |
58
|
|
|
'namespace' => $defaultNamespace, |
59
|
|
|
'module' => $this->name, |
60
|
|
|
'controller' => 'help', |
61
|
|
|
'action' => 'main', |
62
|
|
|
]); |
63
|
|
|
|
64
|
|
|
$this->setServices($container); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getNamespaces(): array |
68
|
|
|
{ |
69
|
|
|
$namespaces = []; |
70
|
|
|
|
71
|
|
|
// Caller namespace |
72
|
|
|
$namespace = $this->getNamespace(); |
73
|
|
|
$dirname = $this->getDirname(); |
74
|
|
|
|
75
|
|
|
// register the vendor module controllers |
76
|
|
|
$namespaces[$namespace . '\\Tasks'] = $dirname . '/Tasks/'; |
77
|
|
|
$namespaces[$namespace . '\\Models'] = $dirname . '/Models/'; |
78
|
|
|
|
79
|
|
|
// add zemit core models |
80
|
|
|
$corePath = dirname(__DIR__); |
81
|
|
|
$namespaces['Zemit\\Models'] = $corePath . '/Models/'; |
82
|
|
|
|
83
|
|
|
return $namespaces; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getServices(DiInterface $container = null): void |
87
|
|
|
{ |
88
|
|
|
$this->config ??= $container['config'] ??= new Config(); |
89
|
|
|
$this->loader ??= $container['loader'] ??= new Loader(); |
90
|
|
|
$this->router ??= $container['router'] ??= new Router(); |
91
|
|
|
$this->dispatcher ??= $container['dispatcher'] ??= new Dispatcher(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function setServices(DiInterface $container = null): void |
95
|
|
|
{ |
96
|
|
|
$container->set('config', $this->config); |
|
|
|
|
97
|
|
|
$container->set('dispatcher', $this->dispatcher); |
98
|
|
|
$container->set('loader', $this->loader); |
99
|
|
|
$container->set('router', $this->router); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function getDefaultNamespace(): string |
103
|
|
|
{ |
104
|
|
|
return $this->getNamespace() . '\\Tasks'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function getDirname(): string |
108
|
|
|
{ |
109
|
|
|
return Utils::getDirname($this); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function getNamespace(): string |
113
|
|
|
{ |
114
|
|
|
return Utils::getNamespace($this); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.