Пример #1
0
 /**
  * @param mixed[]        $reference
  * @param AssetInterface $asset
  *
  * @return string
  */
 public function rewrite(array $reference, AssetInterface $asset)
 {
     if (!$this->isRewritable($reference['url'], $asset->getSourcePath(), $asset->getTargetPath())) {
         return $reference[0];
     }
     $absoluteSourcePath = $this->getAssetPath(dirname($this->createAssetPath($asset->getSourceRoot(), $asset->getSourcePath())), parse_url($reference['url'])['path']);
     $webTargetPath = $this->createAssetPath($this->rewriteDirectory, $this->namer->name($absoluteSourcePath, $asset));
     $absoluteTargetPath = $this->webDirectory . $webTargetPath;
     $this->filesystem->{$this->strategy}($absoluteSourcePath, $absoluteTargetPath, true);
     return str_replace($reference['url'], $this->packages->getUrl($webTargetPath), $reference[0]);
 }
Пример #2
0
 public function testRewrite()
 {
     $asset = $this->createAssetMock();
     $asset->expects($this->once())->method('getSourceRoot')->will($this->returnValue($sourceRoot = 'source_root'));
     $asset->expects($this->exactly(2))->method('getSourcePath')->will($this->returnValue($sourcePath = 'source_path'));
     $asset->expects($this->once())->method('getTargetPath')->will($this->returnValue($targetPath = 'target_path'));
     $reference = $this->createReference($path = 'foo.jpg');
     $this->filesystem->expects($this->once())->method('exists')->with($this->identicalTo($absoluteSourcePath = $sourceRoot . DIRECTORY_SEPARATOR . $path))->will($this->returnValue(true));
     $this->namer->expects($this->once())->method('name')->with($this->identicalTo($absoluteSourcePath))->will($this->returnValue($namedFile = 'named_file'));
     $webTargetPath = DIRECTORY_SEPARATOR . $this->rewriteDirectory . DIRECTORY_SEPARATOR . $namedFile;
     $this->filesystem->expects($this->once())->method($this->strategy)->with($this->identicalTo($absoluteSourcePath), $this->identicalTo($this->webDirectory . $webTargetPath), $this->isTrue());
     $this->packages->expects($this->once())->method('getUrl')->with($this->identicalTo($webTargetPath))->will($this->returnValue($packagedPath = 'packaged_path'));
     $this->assertSame('url("' . $packagedPath . '")', $this->cssRewriter->rewrite($reference, $asset));
 }