-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObjRefRemoteBundle.php
More file actions
47 lines (36 loc) · 1.43 KB
/
ObjRefRemoteBundle.php
File metadata and controls
47 lines (36 loc) · 1.43 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
<?php
/*
* This file is part of the ObjRef package.
*
* (c) Uwe Mueller <uwe@namez.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace ObjRef\RemoteBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class ObjRefRemoteBundle extends Bundle {
private $autoloader;
public function boot() {
$namespace = $this->container->getParameter('objref.proxy_namespace');
$gen = $this->container->get('objref.proxy_generator');
$env = $this->container->getParameter('kernel.environment');
$this->autoloader = function($class) use ($namespace, $gen, $env) {
if (substr($class, 0, strlen($namespace)) === $namespace) {
$originalClass = substr($class, strlen($namespace));
$originalClass = str_replace('__', '_', $originalClass);
$originalClass = str_replace('_', '\\', $originalClass);
$file = $gen->getFullProxyPath($originalClass);
if(!is_file($file) || $env == 'dev') {
$gen->generate($originalClass);
clearstatcache(true, $file);
}
if(file_exists($file)) {
/** @noinspection PhpIncludeInspection */
require $file;
}
}
};
spl_autoload_register($this->autoloader);
}
}