bytic /
assets
| 1 | <?php |
||
| 2 | |||
| 3 | namespace ByTIC\Assets; |
||
| 4 | |||
| 5 | use ByTIC\Assets\Encore\EntrypointLookupFactory; |
||
| 6 | use ByTIC\Assets\Encore\EntrypointsCollection; |
||
| 7 | use Nip\Container\ServiceProviders\Providers\AbstractSignatureServiceProvider; |
||
| 8 | use Symfony\Component\Asset\Package; |
||
| 9 | use Symfony\Component\Asset\Packages; |
||
| 10 | use Symfony\Component\Asset\VersionStrategy\EmptyVersionStrategy; |
||
| 11 | use Symfony\WebpackEncoreBundle\Asset\EntrypointLookupCollection; |
||
| 12 | use Symfony\WebpackEncoreBundle\Asset\TagRenderer; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Class AssetsServiceProvider |
||
| 16 | * @package ByTIC\Assets |
||
| 17 | */ |
||
| 18 | class AssetsServiceProvider extends AbstractSignatureServiceProvider |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @inheritDoc |
||
| 22 | */ |
||
| 23 | public function provides() |
||
| 24 | { |
||
| 25 | return [ |
||
| 26 | 'assets.manager', |
||
| 27 | 'assets.packages', |
||
| 28 | 'assets.tag_renderer', |
||
| 29 | 'assets.entrypoint_lookup', |
||
| 30 | ]; |
||
| 31 | } |
||
| 32 | |||
| 33 | 8 | public function register() |
|
| 34 | { |
||
| 35 | 8 | $this->registerManager(); |
|
| 36 | 8 | $this->registerPackages(); |
|
| 37 | 8 | $this->registerTagRenderer(); |
|
| 38 | 8 | $this->registerEntrypointLookupCollection(); |
|
| 39 | 8 | } |
|
| 40 | |||
| 41 | 8 | protected function registerManager() |
|
| 42 | { |
||
| 43 | $this->getContainer()->share('assets.manager', function () { |
||
| 44 | 6 | $manager = new AssetsManager(); |
|
| 45 | 6 | $manager->setContainer($this->getContainer()); |
|
| 46 | 6 | return $manager; |
|
| 47 | 8 | }); |
|
| 48 | 8 | } |
|
| 49 | |||
| 50 | 8 | protected function registerPackages() |
|
| 51 | { |
||
| 52 | $this->getContainer()->share('assets.packages', function () { |
||
| 53 | 5 | $package = new Package(new EmptyVersionStrategy()); |
|
| 54 | 5 | return new Packages($package); |
|
| 55 | 8 | }); |
|
| 56 | 8 | } |
|
| 57 | |||
| 58 | 8 | protected function registerTagRenderer() |
|
| 59 | { |
||
| 60 | $this->getContainer()->share('assets.tag_renderer', function () { |
||
| 61 | 5 | return new TagRenderer( |
|
| 62 | 5 | $this->getContainer()->get('assets.entrypoint_lookup'), |
|
| 63 | 5 | $this->getContainer()->get('assets.packages') |
|
| 64 | ); |
||
| 65 | 8 | }); |
|
| 66 | 8 | } |
|
| 67 | |||
| 68 | 8 | protected function registerEntrypointLookupCollection() |
|
| 69 | { |
||
| 70 | $this->getContainer()->share('assets.entrypoint_lookup', function () { |
||
| 71 | 7 | return new EntrypointLookupCollection($this->generateBuildEntrypoints()); |
|
| 72 | 8 | }); |
|
| 73 | 8 | } |
|
| 74 | |||
| 75 | /** |
||
| 76 | * @return EntrypointsCollection |
||
| 77 | */ |
||
| 78 | 7 | protected function generateBuildEntrypoints() |
|
| 79 | { |
||
| 80 | 7 | $entries = EntrypointLookupFactory::getBuilds(); |
|
| 81 | 7 | return new EntrypointsCollection($entries); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 82 | } |
||
| 83 | } |
||
| 84 |