Passed
Branch entity_code_generation (017b91)
by Gerrit
14:35
created

symfony_rdm_composer_hook()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 11
c 0
b 0
f 0
nc 4
nop 2
dl 0
loc 22
rs 9.9
1
<?php
2
/**
3
 * Copyright (C) 2019 Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 *
8
 * @license GPL-3.0
9
 *
10
 * @author Gerrit Addiks <[email protected]>
11
 */
12
13
namespace Addiks\SymfonyRDM;
14
15
use Composer\Autoload\ClassLoader;
16
use Symfony\Component\HttpKernel\KernelInterface;
17
use Psr\Container\ContainerInterface;
18
use Addiks\RDMBundle\AddiksRDMBundle;
19
20
function symfony_rdm_composer_hook(ClassLoader $classLoader, KernelInterface $kernel): void
21
{
22
    AddiksRDMBundle::registerClassLoader($classLoader);
23
    
24
    $cacheDir = $kernel->getCacheDir();
25
    
26
    $classmapFilePath = $cacheDir . '/symfony_rdm_entities/classmap';
27
    
28
    if (file_exists($classmapFilePath)) {
29
        $classMap = array();
30
        
31
        foreach (explode("\n", file_get_contents($classmapFilePath)) as $classmapLine) {
32
            if (empty($classmapLine)) {
33
                continue;
34
            }
35
            
36
            [$className, $filePath] = explode(":", $classmapLine);
37
            
38
            $classMap[$className] = $filePath;
39
        }
40
        
41
        $classLoader->addClassMap($classMap);
42
    }
43
}
44