|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Gacela\Framework; |
|
6
|
|
|
|
|
7
|
|
|
use Closure; |
|
8
|
|
|
use Gacela\Framework\Bootstrap\GacelaConfig; |
|
9
|
|
|
use Gacela\Framework\Bootstrap\SetupGacela; |
|
10
|
|
|
use Gacela\Framework\Bootstrap\SetupGacelaInterface; |
|
11
|
|
|
use Gacela\Framework\ClassResolver\AbstractClassResolver; |
|
12
|
|
|
use Gacela\Framework\ClassResolver\Cache\GacelaFileCache; |
|
13
|
|
|
use Gacela\Framework\ClassResolver\Cache\InMemoryCache; |
|
14
|
|
|
use Gacela\Framework\ClassResolver\ClassResolverCache; |
|
15
|
|
|
use Gacela\Framework\ClassResolver\GlobalInstance\AnonymousGlobal; |
|
16
|
|
|
use Gacela\Framework\Config\Config; |
|
17
|
|
|
use Gacela\Framework\Config\ConfigFactory; |
|
18
|
|
|
use Gacela\Framework\DocBlockResolver\DocBlockResolverCache; |
|
19
|
|
|
|
|
20
|
|
|
final class Gacela |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Define the entry point of Gacela. |
|
24
|
|
|
* |
|
25
|
|
|
* @param null|Closure(GacelaConfig):void $configFn |
|
26
|
|
|
*/ |
|
27
|
84 |
|
public static function bootstrap(string $appRootDir, Closure $configFn = null): void |
|
28
|
|
|
{ |
|
29
|
84 |
|
$setup = self::processConfigFnIntoSetup($appRootDir, $configFn); |
|
30
|
|
|
|
|
31
|
84 |
|
if ($setup->shouldResetInMemoryCache()) { |
|
32
|
45 |
|
AbstractFacade::resetCache(); |
|
33
|
45 |
|
AnonymousGlobal::resetCache(); |
|
34
|
45 |
|
AbstractFactory::resetCache(); |
|
35
|
45 |
|
GacelaFileCache::resetCache(); |
|
36
|
45 |
|
DocBlockResolverCache::resetCache(); |
|
37
|
45 |
|
ClassResolverCache::resetCache(); |
|
38
|
45 |
|
InMemoryCache::resetCache(); |
|
39
|
45 |
|
AbstractClassResolver::resetCache(); |
|
40
|
45 |
|
ConfigFactory::resetCache(); |
|
41
|
45 |
|
Config::resetInstance(); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
84 |
|
Config::createWithSetup($setup) |
|
45
|
84 |
|
->setAppRootDir($appRootDir) |
|
46
|
84 |
|
->init(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* @param null|Closure(GacelaConfig):void $configFn |
|
51
|
|
|
*/ |
|
52
|
84 |
|
private static function processConfigFnIntoSetup(string $appRootDir, Closure $configFn = null): SetupGacelaInterface |
|
53
|
|
|
{ |
|
54
|
84 |
|
if ($configFn !== null) { |
|
55
|
56 |
|
return SetupGacela::fromCallable($configFn); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
28 |
|
$gacelaFilePath = $appRootDir . '/gacela.php'; |
|
59
|
|
|
|
|
60
|
28 |
|
if (is_file($gacelaFilePath)) { |
|
61
|
|
|
return SetupGacela::fromFile($gacelaFilePath); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
28 |
|
return new SetupGacela(); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|