larriereguichet /
AdminBundle
| 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
|
|||
| 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 |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/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: