Completed
Pull Request — 3.1 (#8)
by David
08:26 queued 07:15
created

WebLibraryManagerServiceProvider::loadFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
4
namespace Mouf\Html\Utils\WebLibraryManager;
5
6
use Mouf\Html\HtmlElement\HtmlFromFile;
7
use Mouf\Html\HtmlElement\Scopable;
8
use Mouf\Html\Renderer\RendererInterface;
9
use Psr\Container\ContainerInterface;
10
use TheCodingMachine\Funky\Annotations\Factory;
11
use TheCodingMachine\Funky\Annotations\Tag;
12
use TheCodingMachine\Funky\ServiceProvider;
13
14
class WebLibraryManagerServiceProvider extends ServiceProvider implements Scopable
15
{
16
    /**
17
     * @Factory()
18
     */
19
    public static function createWebLibraryManager(ContainerInterface $container, RendererInterface $renderer): WebLibraryManager
20
    {
21
        return new WebLibraryManager($renderer, \iterator_to_array($container->get('webLibraries')));
22
    }
23
24
    /**
25
     * @Factory(name="webLibraries")
26
     */
27
    public static function createWebLibraries(): \SplPriorityQueue
28
    {
29
        return new \SplPriorityQueue();
30
    }
31
32
    private $rootUrl;
33
34
    /**
35
     * @Factory(name="rootUrlInlineWebLibrary", tags={@Tag(name="webLibraries", priority=0.0)})
36
     */
37
    public static function createRootUrlWebLibrary(ContainerInterface $container): InlineWebLibrary
38
    {
39
        $scope = new self();
40
        $scope->rootUrl = $container->get('ROOT_URL');
41
42
        $webLibrarayManagerDir = \ComposerLocator::getPath('mouf/html.utils.weblibrarymanager');
43
        $htmlFromFile = new HtmlFromFile($webLibrarayManagerDir.'/javascript/rootUrl.php', $scope);
44
        return new InlineWebLibrary($htmlFromFile);
45
    }
46
47
    /**
48
     * Loads the file.
49
     *
50
     * @param string $file
51
     */
52
    public function loadFile($file)
53
    {
54
        require $file;
55
    }
56
}
57