Completed
Pull Request — master (#102)
by Arnaud
07:20 queued 04:48
created

anonymous()

Size

Total Lines 2
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
nc 1
nop 1
dl 0
loc 2
c 0
b 0
f 0
1
#!/usr/bin/env php
2
<?php
3
4
use JK\Sam\Event\NotificationEvent;
5
use JK\Sam\File\Locator;
6
use JK\Sam\File\Normalizer;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Normalizer. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use JK\Sam\Filter\FilterBuilder;
8
use JK\Sam\Task\TaskBuilder;
9
use JK\Sam\Task\TaskRunner;
10
use Symfony\Component\EventDispatcher\EventDispatcher;
11
12
require 'vendor/autoload.php';
13
14
$configuration = [
15
    'compass' => [],
16
    'merge' => [],
17
    'minify' => [],
18
    'copy' => [],
19
];
20
$eventDispatcher = new EventDispatcher();
21
$eventDispatcher->addListener(NotificationEvent::NAME, function(NotificationEvent $event) {
22
    echo $event->getMessage()."\n";
23
});
24
25
$builder = new FilterBuilder($eventDispatcher);
26
$filters = $builder->build($configuration);
27
28
$tasks = [
29
    'admin.css' => [
30
        'filters' => [
31
            'compass',
32
            'minify',
33
            'merge',
34
        ],
35
        'sources' => [
36
            'vendor/twbs/bootstrap/dist/css/bootstrap.min.css',
37
            'src/Resources/assets/scss/main.scss',
38
        ],
39
        'destinations' => [
40
            'src/Resources/public/css/admin.css',
41
        ],
42
    ],
43
    'admin.js' => [
44
        'filters' => [
45
            'minify',
46
            'merge',
47
        ],
48
        'sources' => [
49
            'vendor/components/jquery/jquery.min.js',
50
            'vendor/twbs/bootstrap/dist/js/bootstrap.min.js',
51
            'src/Resources/assets/js/*',
52
        ],
53
        'destinations' => [
54
            'src/Resources/public/js/admin.js',
55
        ],
56
    ],
57
    'fonts' => [
58
        'filters' => null,
59
        'sources' => [
60
            'vendor/components/font-awesome/fonts/'
61
        ],
62
        'destinations' => [
63
            'src/Resources/public/fonts/',
64
        ],
65
    ],
66
];
67
$builder = new TaskBuilder();
68
$tasks = $builder->build($tasks);
69
70
$normalizer = new Normalizer(realpath(__DIR__.'/AdminBundle'));
71
$locator = new Locator($normalizer);
72
73
$runner = new TaskRunner(
74
    $filters,
75
    $locator,
76
    false
77
);
78
79
// run your task
80
foreach ($tasks as $task) {
81
    $runner->run($task);
82
}
83