Repository navigation
Expand file tree
/
Copy pathClassLoader.php
More file actions
76 lines (63 loc) · 2.2 KB
/
Copy pathClassLoader.php
File metadata and controls
76 lines (63 loc) · 2.2 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
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace Hyperf\Di;
use Dotenv\Dotenv;
use Dotenv\Repository\Adapter;
use Dotenv\Repository\RepositoryBuilder;
use Hyperf\Di\Annotation\ScanConfig;
use Hyperf\Di\Annotation\Scanner;
use Hyperf\Di\LazyLoader\LazyLoader;
use Hyperf\Di\ScanHandler\PcntlScanHandler;
use Hyperf\Di\ScanHandler\ScanHandlerInterface;
use Hyperf\Support\Composer;
use Hyperf\Support\DotenvManager;
class ClassLoader
{
public static function init(?string $proxyFileDirPath = null, ?string $configDir = null, ?ScanHandlerInterface $handler = null): void
{
if (! $proxyFileDirPath) {
// This dir is the default proxy file dir path of Hyperf
$proxyFileDirPath = BASE_PATH . '/runtime/container/proxy/';
}
if (! $configDir) {
// This dir is the default config file dir path of Hyperf
$configDir = BASE_PATH . '/config/';
}
if (! $handler) {
$handler = new PcntlScanHandler();
}
$composerLoader = Composer::getLoader();
if (file_exists(BASE_PATH . '/.env')) {
DotenvManager::load([BASE_PATH]);
}
// Scan by ScanConfig to generate the reflection class map
$config = ScanConfig::instance($configDir);
$composerLoader->addClassMap($config->getClassMap());
$scanner = new Scanner($config, $handler);
$composerLoader->addClassMap(
$scanner->scan($composerLoader->getClassMap(), $proxyFileDirPath)
);
// Initialize Lazy Loader. This will prepend LazyLoader to the top of autoload queue.
LazyLoader::bootstrap($configDir);
}
/**
* @see DotenvManager::load()
* @deprecated use DotenvManager instead
*/
protected static function loadDotenv(): void
{
$repository = RepositoryBuilder::createWithNoAdapters()
->addAdapter(Adapter\PutenvAdapter::class)
->immutable()
->make();
Dotenv::create($repository, [BASE_PATH])->load();
}
}