|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
declare(strict_types=1); |
|
8
|
|
|
|
|
9
|
|
|
namespace eZ\Publish\Core\Repository\ProxyFactory; |
|
10
|
|
|
|
|
11
|
|
|
use ProxyManager\Configuration; |
|
12
|
|
|
use ProxyManager\Factory\LazyLoadingValueHolderFactory as BaseLazyLoadingValueHolderFactory; |
|
13
|
|
|
use ProxyManager\FileLocator\FileLocator; |
|
14
|
|
|
use ProxyManager\GeneratorStrategy\FileWriterGeneratorStrategy; |
|
15
|
|
|
use RuntimeException; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @internal |
|
19
|
|
|
*/ |
|
20
|
|
|
final class LazyLoadingValueHolderFactory extends BaseLazyLoadingValueHolderFactory |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Use LazyLoadingValueHolderFactory::create method instead. |
|
24
|
|
|
*/ |
|
25
|
|
|
private function __construct(Configuration $options) |
|
26
|
|
|
{ |
|
27
|
|
|
parent::__construct($options); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function registerAutoloader(): void |
|
31
|
|
|
{ |
|
32
|
|
|
spl_autoload_register($this->configuration->getProxyAutoloader()); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function warmUp(iterable $classes): void |
|
36
|
|
|
{ |
|
37
|
|
|
foreach ($classes as $class) { |
|
38
|
|
|
$this->createProxy($class, function () {}); |
|
39
|
|
|
} |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public static function create(string $proxyCacheDir): self |
|
43
|
|
|
{ |
|
44
|
|
|
$config = new Configuration(); |
|
45
|
|
|
|
|
46
|
|
|
// Proxy cache directory needs to be created before |
|
47
|
|
|
if (!is_dir($proxyCacheDir)) { |
|
48
|
|
|
if (false === @mkdir($proxyCacheDir, 0777, true)) { |
|
49
|
|
|
throw new RuntimeException(sprintf( |
|
50
|
|
|
'Unable to create the Repository Proxy directory "%s".', |
|
51
|
|
|
$proxyCacheDir |
|
52
|
|
|
)); |
|
53
|
|
|
} |
|
54
|
|
|
} elseif (!is_writable($proxyCacheDir)) { |
|
55
|
|
|
throw new RuntimeException(sprintf( |
|
56
|
|
|
'The Repository Proxy directory "%s" is not writeable for the current system user.', |
|
57
|
|
|
$proxyCacheDir |
|
58
|
|
|
)); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$config->setGeneratorStrategy(new FileWriterGeneratorStrategy(new FileLocator($proxyCacheDir))); |
|
62
|
|
|
$config->setProxiesTargetDir($proxyCacheDir); |
|
63
|
|
|
|
|
64
|
|
|
return new self($config); |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|