/**
  * {@inheritdoc}
  */
 public function process(ContainerInterface $container)
 {
     if (count($this->options['include'])) {
         /**
          * @var LibraryDefinitionInterface $definition
          */
         foreach ($definitions = $container->getLibraries()->getDefinitions() as $definition) {
             $hasHelper = false;
             /**
              * @var ResourceInterface $resource
              */
             foreach ($resources = $definition->getResources() as $resource) {
                 if ($resource instanceof HttpResource && in_array(AssetType::guessExtension($resource->getSource()), $this->options['include']) && ($replacement = $this->processResource($resource)) != $resource) {
                     if ($hasHelper) {
                         $definition->replaceResource($resource, [$replacement]);
                     } else {
                         $hasHelper = true;
                         $definition->replaceResource($resource, [new FileResource($this->options['helper']), $replacement]);
                     }
                 }
             }
         }
     }
     return new CompilerPassResult($container);
 }
Ejemplo n.º 2
0
 public function getAssetType()
 {
     $this->assertSame(AssetType::STYLESHEET, AssetType::guessAssetType('//code.jquery.com/jquery-1.11.3.css'));
     $this->assertSame(AssetType::JAVASCRIPT, AssetType::guessExtension(realpath(__DIR__ . '/../Data/web/js/jquery.js')));
     $this->assertNull(AssetType::guessExtension('/some/path.with.dot/jquery.unknown'));
 }
 public function testProcessAssetWithExcludedOptionalFilter()
 {
     $this->emptyOutput();
     $sourceFile = realpath(__DIR__ . '/../Data/web/js/myjavascript.js');
     $container = new Container(new LibraryCollection(array(new LibraryDefinition('mylib', array(new FileResource($sourceFile, array('filters' => array('?mockup'))))))));
     $result = $this->getCompilerPass(true)->process($container);
     $this->assertInstanceOf(CompilerPassResult::class, $result);
     $this->assertFalse($result->isProcessingStopped());
     $files = glob(rtrim($this->outputDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '/*');
     $this->assertSame(1, count($files), 'Only one file should be dumped into output dir.');
     $this->assertSame(file_get_contents($sourceFile), file_get_contents($files[0]), 'Source and dumped files should be same.');
     $this->assertSame('.dev.', substr($files[0], -7, 5), 'File name should contain ".dev.".');
     $this->assertSame(AssetType::guessExtension($sourceFile), AssetType::guessExtension($files[0]), 'File should have proper extension.');
     $this->assertFalse(array_key_exists('filters', $result->getContainer()->getLibraries()->getDefinition('mylib')->getResources()[0]->getOptions()));
 }