Issues (117)

DependencyInjection/DtcGridExtension.php (3 issues)

1
<?php
2
3
namespace Dtc\GridBundle\DependencyInjection;
4
5
use Dtc\GridBundle\Grid\Renderer\DataTablesRenderer;
6
use Dtc\GridBundle\Grid\Renderer\JQGridRenderer;
7
use Dtc\GridBundle\Grid\Renderer\TableGridRenderer;
8
use Symfony\Component\Config\Definition\Processor;
0 ignored issues
show
The type Symfony\Component\Config\Definition\Processor was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Symfony\Component\Config\FileLocator;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
0 ignored issues
show
The type Symfony\Component\Depend...n\Loader\YamlFileLoader was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Symfony\Component\Finder\Finder;
0 ignored issues
show
The type Symfony\Component\Finder\Finder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
14
15
class DtcGridExtension extends Extension
16
{
17
    public function load(array $configs, ContainerBuilder $container)
18
    {
19
        $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
20
        $loader->load('grid.yml');
21
22
        $configuration = new Configuration();
23
        $processor = new Processor();
24
25
        $config = $processor->processConfiguration($configuration, $configs);
26
        $this->setReflection($config, $container);
27
        $this->setJqGrid($config, $container);
28
        $this->setTheme($config, $container);
29
        $this->setDatatables($config, $container);
30
        $this->setJquery($config, $container);
31
        $this->setPurl($config, $container);
32
        $container->setParameter('dtc_grid.page_div_style', isset($config['page_div_style']) ? $config['page_div_style'] : null);
33
        $container->setParameter('dtc_grid.table_options', isset($config['table']['options']) ? $config['table']['options'] : TableGridRenderer::$defaultOptions);
34
    }
35
36
    public function setReflection(array $config, ContainerBuilder $container)
37
    {
38
        $container->setParameter('dtc_grid.reflection.allowed_entities', isset($config['reflection']['allowed_entities']) ? $config['reflection']['allowed_entities'] : null);
39
    }
40
41
    public function setPurl(array $config, ContainerBuilder $container)
42
    {
43
        $purl = isset($config['purl']) ? $config['purl'] : [];
44
        $container->setParameter('dtc_grid.purl', $purl);
45
    }
46
47
    public function setJquery(array $config, ContainerBuilder $container)
48
    {
49
        $jquery = isset($config['jquery']) ? $config['jquery'] : [];
50
        $container->setParameter('dtc_grid.jquery', $jquery);
51
    }
52
53
    public function setJqGrid(array $config, ContainerBuilder $container)
54
    {
55
        $css = isset($config['jq_grid']['css']) ? $config['jq_grid']['css'] : [];
56
        $js = isset($config['jq_grid']['js']) ? $config['jq_grid']['js'] : [];
57
        $options = isset($config['jq_grid']['options']) ? $config['jq_grid']['options'] : JQGridRenderer::$defaultOptions;
58
59
        $container->setParameter('dtc_grid.jq_grid.css', $css);
60
        $container->setParameter('dtc_grid.jq_grid.js', $js);
61
        $container->setParameter('dtc_grid.jq_grid.options', $options);
62
        $this->setLocal($config, $container, 'jq_grid', 'css');
63
        $this->setLocal($config, $container, 'jq_grid', 'js');
64
    }
65
66
    public function setDataTables(array $config, ContainerBuilder $container)
67
    {
68
        $class = isset($config['datatables']['class']) ? $config['datatables']['class'] : [];
69
        $css = isset($config['datatables']['css']) ? $config['datatables']['css'] : [];
70
        $js = isset($config['datatables']['js']) ? $config['datatables']['js'] : [];
71
        $options = isset($config['datatables']['options']) ? $config['datatables']['options'] : DataTablesRenderer::$defaultOptions;
72
73
        $container->setParameter('dtc_grid.datatables.class', $class);
74
        $container->setParameter('dtc_grid.datatables.css', $css);
75
        $container->setParameter('dtc_grid.datatables.js', $js);
76
        $container->setParameter('dtc_grid.datatables.options', $options);
77
78
        $this->setLocal($config, $container, 'datatables', 'css');
79
        $this->setLocal($config, $container, 'datatables', 'js');
80
    }
81
82
    public function setLocal(array $config, ContainerBuilder $container, $directory, $type)
83
    {
84
        if (!empty($config[$directory]['local'][$type])) {
85
            $container->setParameter('dtc_grid.'.$directory.'.local.'.$type, $config[$directory]['local'][$type]);
86
87
            return;
88
        }
89
90
        $path = __DIR__.\DIRECTORY_SEPARATOR.'..'.\DIRECTORY_SEPARATOR.'Resources'.\DIRECTORY_SEPARATOR.'public'.\DIRECTORY_SEPARATOR.$type.\DIRECTORY_SEPARATOR.$directory;
91
        if (!is_dir($path)) {
92
            $container->setParameter('dtc_grid.'.$directory.'.local.'.$type, []);
93
94
            return;
95
        }
96
        $finder = new Finder();
97
        $finder->files()->in(str_replace(\DIRECTORY_SEPARATOR, '/', $path));
98
        $localCss = [];
99
        $files = [];
100
        foreach ($finder as $fileInfo) {
101
            $fileUrlpath = '/bundles/dtcgrid/'.$type.'/'.$directory.'/'.$fileInfo->getFilename();
102
            $filepath = $path.\DIRECTORY_SEPARATOR.$fileInfo->getFilename();
103
            $files[] = $filepath;
104
            $mtime = filemtime($filepath);
105
            $localCss[] = $fileUrlpath.'?v='.$mtime;
106
        }
107
        $container->setParameter('dtc_grid.'.$directory.'.local.'.$type, $localCss);
108
        $container->setParameter('dtc_grid.'.$directory.'.local.files.'.$type, $files);
109
    }
110
111
    public function setTheme(array $config, ContainerBuilder $container)
112
    {
113
        $css = isset($config['theme']['css']) ? $config['theme']['css'] : [];
114
        $js = isset($config['theme']['js']) ? $config['theme']['js'] : [];
115
116
        $container->setParameter('dtc_grid.theme.css', $css);
117
        $container->setParameter('dtc_grid.theme.js', $js);
118
    }
119
120
    public function getAlias()
121
    {
122
        return 'dtc_grid';
123
    }
124
}
125