本文整理汇总了PHP中Assetic\Asset\FileAsset类的典型用法代码示例。如果您正苦于以下问题:PHP FileAsset类的具体用法?PHP FileAsset怎么用?PHP FileAsset使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FileAsset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* {@inheritdoc}
*/
public function process()
{
$filters = new FilterCollection(array(new CssRewriteFilter()));
$assets = new AssetCollection();
$styles = $this->packageStyles($this->packages);
foreach ($styles as $package => $packageStyles) {
foreach ($packageStyles as $style => $paths) {
foreach ($paths as $path) {
// The full path to the CSS file.
$assetPath = realpath($path);
// The root of the CSS file.
$sourceRoot = dirname($path);
// The style path to the CSS file when external.
$sourcePath = $package . '/' . $style;
// Where the final CSS will be generated.
$targetPath = $this->componentDir;
// Build the asset and add it to the collection.
$asset = new FileAsset($assetPath, $filters, $sourceRoot, $sourcePath);
$asset->setTargetPath($targetPath);
$assets->add($asset);
}
}
}
$css = $assets->dump();
if (file_put_contents($this->componentDir . '/require.css', $css) === FALSE) {
$this->io->write('<error>Error writing require.css to destination</error>');
return false;
}
}
示例2: onTerminate
public function onTerminate(CarewEvent $carewEvent)
{
foreach ($this->finder->in($carewEvent->getArgument('webDir')) as $file) {
$asset = new FileAsset($file->getPathname(), array($this->getFilter()));
file_put_contents($file->getPathname(), $asset->dump());
}
}
示例3: parseInput
/**
* Adds support for pipeline assets.
*
* {@inheritdoc}
*/
protected function parseInput($input, array $options = array())
{
if (is_string($input) && '|' == $input[0]) {
switch (pathinfo($options['output'], PATHINFO_EXTENSION)) {
case 'js':
$type = 'js';
break;
case 'css':
$type = 'css';
break;
default:
throw new \RuntimeException('Unsupported pipeline asset type provided: ' . $input);
}
$assets = new AssetCollection();
foreach ($this->locator->locatePipelinedAssets(substr($input, 1), $type) as $formula) {
$filters = array();
if ($formula['filter']) {
$filters[] = $this->getFilter($formula['filter']);
}
$asset = new FileAsset($formula['root'] . '/' . $formula['file'], $filters, $options['root'][0], $formula['file']);
$asset->setTargetPath($formula['file']);
$assets->add($asset);
}
return $assets;
}
return parent::parseInput($input, $options);
}
示例4: fonts
public function fonts(array $params)
{
$font = $params['font'];
if (strlen($font) < 1) {
return false;
}
$fontfiles = Registry::getInstance()->assets['fonts'];
if (isset($fontfiles[$font])) {
$asset = new FileAsset($fontfiles[$font]);
switch (strtolower(substr($font, strpos($font, ".")))) {
case ".eot":
$type = "application/vnd.ms-fontobject";
break;
case "otf":
$type = "font/opentype";
break;
case "ttf":
$type = "application/x-font-ttf";
break;
case ".woff":
$type = "application/x-font-woff";
break;
default:
$type = "application/x-font";
}
header('Content-Type: ' . $type);
echo $asset->dump();
}
return true;
}
示例5: testCompassMixin
public function testCompassMixin()
{
$asset = new FileAsset(__DIR__ . '/fixtures/compass/compass.sass');
$asset->load();
$this->filter->filterLoad($asset);
$this->assertContains('text-decoration', $asset->getContent());
}
示例6: testCompassExtensionCanBeDisabled
public function testCompassExtensionCanBeDisabled()
{
$this->setExpectedException("Exception", "Undefined mixin box-shadow: failed at `@include box-shadow(10px " . "10px 8px red);` line: 4");
$asset = new FileAsset(__DIR__ . '/fixtures/sass/main_compass.scss');
$asset->load();
$this->getFilter(false)->filterLoad($asset);
}
示例7: testAssetLastModifiedTimestampIsPrependBeforeFileExtension
public function testAssetLastModifiedTimestampIsPrependBeforeFileExtension()
{
$asset = new FileAsset(TEST_ASSETS_DIR . '/css/global.css');
$asset->setTargetPath(TEST_PUBLIC_DIR . '/css/global.css');
$this->cacheBuster->process($asset);
$this->assertSame(TEST_PUBLIC_DIR . '/css/global.' . $asset->getLastModified() . '.css', $asset->getTargetPath());
}
示例8: testRelativeSourceUrlImportImports
public function testRelativeSourceUrlImportImports()
{
$asset = new FileAsset(__DIR__ . '/fixtures/jsmin/js.js');
$asset->load();
$filter = new JSMinFilter();
$filter->filterDump($asset);
$this->assertEquals('var a="abc";;;var bbb="u";', $asset->getContent());
}
示例9: testRelativeSourceUrlImportImports
public function testRelativeSourceUrlImportImports()
{
$asset = new FileAsset(__DIR__ . '/fixtures/minifycsscompressor/main.css');
$asset->load();
$filter = new MinifyCssCompressorFilter();
$filter->filterDump($asset);
$this->assertEquals('body{color:white}body{background:black}', $asset->getContent());
}
示例10: testNonCssImport
public function testNonCssImport()
{
$asset = new FileAsset(__DIR__ . '/fixtures/cssimport/noncssimport.css', array(), __DIR__ . '/fixtures/cssimport', 'noncssimport.css');
$asset->load();
$filter = new CssImportFilter();
$filter->filterLoad($asset);
$this->assertEquals(file_get_contents(__DIR__ . '/fixtures/cssimport/noncssimport.css'), $asset->getContent(), '->filterLoad() skips non css');
}
示例11: createAssetManager
protected function createAssetManager()
{
$asset = new FileAsset(__DIR__ . '/../../../tests/test.css');
$asset->setTargetPath('css/test.css');
$assetManager = new AssetManager();
$assetManager->set('test_css', $asset);
return $assetManager;
}
示例12: testRelativeSourceUrlImportImports
public function testRelativeSourceUrlImportImports()
{
$asset = new FileAsset(__DIR__ . '/fixtures/jsmin/js.js');
$asset->load();
$filter = new JSqueezeFilter();
$filter->filterDump($asset);
$this->assertEquals(";var a='abc',bbb='u';", $asset->getContent());
}
示例13: testPacker
public function testPacker()
{
$asset = new FileAsset(__DIR__ . '/fixtures/packer/example.js');
$asset->load();
$filter = new PackerFilter();
$filter->filterDump($asset);
$this->assertEquals("var exampleFunction=function(arg1,arg2){alert('exampleFunction called!')}", $asset->getContent());
}
示例14: filterLoad
public function filterLoad(AssetInterface $asset)
{
$importFilter = $this->importFilter;
$sourceRoot = $asset->getSourceRoot();
$sourcePath = $asset->getSourcePath();
$callback = function ($matches) use($importFilter, $sourceRoot, $sourcePath) {
if (!$matches['url']) {
return $matches[0];
}
if (null === $sourceRoot) {
return $matches[0];
}
$importRoot = $sourceRoot;
if (false !== strpos($matches['url'], '://')) {
// absolute
list($importScheme, $tmp) = explode('://', $matches['url'], 2);
list($importHost, $importPath) = explode('/', $tmp, 2);
$importRoot = $importScheme . '://' . $importHost;
} elseif (0 === strpos($matches['url'], '//')) {
// protocol-relative
list($importHost, $importPath) = explode('/', substr($matches['url'], 2), 2);
$importHost = '//' . $importHost;
} elseif ('/' == $matches['url'][0]) {
// root-relative
$importPath = substr($matches['url'], 1);
} elseif (null !== $sourcePath) {
// document-relative
$importPath = $matches['url'];
if ('.' != ($sourceDir = dirname($sourcePath))) {
$importPath = $sourceDir . '/' . $importPath;
}
} else {
return $matches[0];
}
// ignore other imports
if ('css' != pathinfo($importPath, PATHINFO_EXTENSION)) {
return $matches[0];
}
$importSource = $importRoot . '/' . $importPath;
if (false !== strpos($importSource, '://') || 0 === strpos($importSource, '//')) {
$import = new HttpAsset($importSource, array($importFilter), true);
} elseif (!file_exists($importSource)) {
// ignore not found imports
return $matches[0];
} else {
$import = new FileAsset($importSource, array($importFilter), $importRoot, $importPath);
}
$import->setTargetPath($sourcePath);
return $import->dump();
};
$content = $asset->getContent();
$lastHash = md5($content);
do {
$content = $this->filterImports($content, $callback);
$hash = md5($content);
} while ($lastHash != $hash && ($lastHash = $hash));
$asset->setContent($content);
}
示例15: testCompilation
public function testCompilation()
{
$asset = new FileAsset(__DIR__ . '/stubs/coffeescript/script.coffee');
$asset->load();
$filter = new CoffeeScriptphpFilter();
$filter->filterLoad($asset);
$expected = file_get_contents(__DIR__ . '/stubs/coffeescript/script.js');
$this->assertEquals($expected, $asset->getContent());
}