-
Notifications
You must be signed in to change notification settings - Fork 613
Expand file tree
/
Copy pathRegistryProvider.php
More file actions
98 lines (81 loc) · 3.04 KB
/
Copy pathRegistryProvider.php
File metadata and controls
98 lines (81 loc) · 3.04 KB
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
<?php
declare(strict_types=1);
/**
* This file is part of the Phalcon Developer Tools.
*
* (c) Phalcon Team <team@phalcon.io>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Phalcon\DevTools\Providers;
use Phalcon\Config\Config;
use Phalcon\DevTools\Bootstrap;
use Phalcon\DevTools\Utils\FsUtils;
use Phalcon\Di\DiInterface;
use Phalcon\Di\ServiceProviderInterface;
use Phalcon\Registry;
class RegistryProvider implements ServiceProviderInterface
{
/**
* @var string
*/
protected $providerName = 'registry';
/**
* Registers a service provider.
*
* @param DiInterface $di
*/
public function register(DiInterface $di): void
{
/** @var Bootstrap $bootstrap */
$bootstrap = $di->getShared('application');
$basePath = $bootstrap->getBasePath();
$ptoolsPath = $bootstrap->getPtoolsPath();
$templatesPath = $bootstrap->getTemplatesPath();
$di->setShared($this->providerName, function () use ($basePath, $ptoolsPath, $templatesPath) {
/**
* @var DiInterface $this
*/
$registry = new Registry;
/* @var Config $config */
$config = $this->getShared('config');
/* @var FsUtils $fs */
$fs = $this->getShared('fs');
$basePath = $fs->normalize(rtrim($basePath, '\\/'));
$ptoolsPath = $fs->normalize(rtrim($ptoolsPath, '\\/'));
$templatesPath = $fs->normalize(rtrim($templatesPath, '\\/'));
$requiredDirectories = [
'modelsDir',
'controllersDir',
'migrationsDir',
];
$directories = [
'modelsDir' => null,
'controllersDir' => null,
'migrationsDir' => null,
'basePath' => $basePath,
'ptoolsPath' => $ptoolsPath,
'templatesPath' => $templatesPath,
'webToolsViews' => $fs->normalize($ptoolsPath . '/src/Web/Tools/Views'),
'resourcesDir' => $fs->normalize($ptoolsPath . '/resources'),
'elementsDir' => $fs->normalize($ptoolsPath . '/resources/elements')
];
if (($application = $config->get('application')) instanceof Config) {
foreach ($requiredDirectories as $name) {
if ($possiblePath = $application->get($name)) {
if (!$fs->isAbsolute($possiblePath)) {
$possiblePath = $basePath . DS . $possiblePath;
}
$possiblePath = $fs->normalize($possiblePath);
if (is_readable($possiblePath) && is_dir($possiblePath)) {
$directories[$name] = $possiblePath;
}
}
}
}
$registry->offsetSet('directories', (object)$directories);
return $registry;
});
}
}