FilesystemCacheForceUmaskPass::process()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 5
eloc 8
c 1
b 1
f 0
nc 5
nop 1
dl 0
loc 11
rs 9.6111
1
<?php
2
/**
3
 * @author Gerard van Helden <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Bundle\FrameworkExtraBundle\DependencyInjection\Compiler;
8
9
use Doctrine\Common\Cache\FilesystemCache;
10
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
11
use Symfony\Component\DependencyInjection\ContainerBuilder;
12
13
/**
14
 * Finds the definitions and force them to honour the system's umask() setting.
15
 */
16
class FilesystemCacheForceUmaskPass implements CompilerPassInterface
17
{
18
    /**
19
     * @{inheritDoc}
20
     */
21
    public function process(ContainerBuilder $container)
22
    {
23
        if ($container->hasDefinition('annotations.filesystem_cache')) {
24
            foreach ($container->getDefinitions() as $def) {
25
                if ($def->getClass() === FilesystemCache::class) {
26
                    $args = $def->getArguments();
27
                    if (!isset($args[1])) {
28
                        $args[1] = (new \ReflectionClass(FilesystemCache::class))->getConstructor()->getParameters()[1]->getDefaultValue();
29
                    }
30
                    $args[2] = umask();
31
                    $def->setArguments($args);
32
                }
33
            }
34
        }
35
    }
36
}