-
Notifications
You must be signed in to change notification settings - Fork 613
Expand file tree
/
Copy pathUrlProvider.php
More file actions
64 lines (54 loc) · 1.79 KB
/
Copy pathUrlProvider.php
File metadata and controls
64 lines (54 loc) · 1.79 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
<?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\Di\DiInterface;
use Phalcon\Di\ServiceProviderInterface;
use Phalcon\Url as UrlResolver;
class UrlProvider implements ServiceProviderInterface
{
/**
* @var string
*/
protected $providerName = 'url';
/**
* Registers a service provider.
*
* @param DiInterface $di
*/
public function register(DiInterface $di): void
{
$di->setShared($this->providerName, function () {
/** @var DiInterface $this */
$config = $this->getShared('config');
$url = new UrlResolver();
if ($config->get('application', new Config())->offsetExists('baseUri')) {
$baseUri = $config->get('application', new Config())->get('baseUri');
} elseif ($config->offsetExists('baseUri')) {
$baseUri = $config->get('baseUri');
} else {
// TODO: Log notice here
$baseUri = '/';
}
if ($config->get('application', new Config())->offsetExists('staticUri')) {
$staticUri = $config->get('application', new Config())->get('staticUri');
} elseif ($config->offsetExists('staticUri')) {
$staticUri = $config->get('staticUri');
} else {
// TODO: Log notice here
$staticUri = '/';
}
$url->setBaseUri($baseUri);
$url->setStaticBaseUri($staticUri);
return $url;
});
}
}