많은 CSS 자산을 하나로 결합하고이를 축소하고 덤프하는 두 가지 방법이 있습니다 "/assetic/6bad22c.css"와 같은 생성 된 파일 이름으로 캐시됩니다. 참조 방법을 현재 내가
private static function getCssAssetFactory()
{
$fm = new FilterManager();
$fm->set('less', new Filter\LessphpFilter());
$fm->set('import', new Filter\CssImportFilter());
$fm->set('rewrite', new Filter\CssRewriteFilter());
$fm->set('min', new Filter\CssMinFilter());
$factory = new AssetFactory(self::getAssetBuildPath());
$factory->setFilterManager($fm);
return $factory;
}
AssetFactory
사용및
public static function dumpStylesheets()
{
$asset = self::getCssAssetFactory()->createAsset
( self::$stylesheets
, array
( 'less' // Less CSS Compiler
, 'import' // Solves @imports
, 'rewrite' // Rewrites Base URLs when moving to another URL
, 'min' // Minifies the script
)
, array('output' => 'assetic/*.css')
);
$cache = self::getAssetCache($asset);
self::getAssetWriter()->writeAsset($cache);
return self::basePath().'/'.$asset->getTargetPath();
}
다음
있습니다 통해 자산을 만들 : 나는 다음과 같은 이용하여이를
private static function getAssetWriter()
{
if (is_null(self::$AssetWriter))
{
self::$AssetWriter = new AssetWriter(self::getAssetBuildPath());
}
return self::$AssetWriter;
}
private static function getAssetCache($asset)
{
return new AssetCache
( $asset
, new FilesystemCache(self::getAssetBuildPath().'/cache')
);
}
지금까지 마술은 없습니다. 내 문제는 에 의한 self::$stylesheets
배열에 자산에 대한 경로 문자열 만 포함되어 있다는 것입니다. 그러나 나는이 방법처럼 실제 Assetic 자산을 사용하는 필요 :
self::$stylesheets = array
(new Asset\FileAsset('path/to/style.css')
, new Asset\StringAsset('.some-class {text-decoration: none;}');
, new Asset\HttpAsset('http://domain.tld/assets/style.css');
);
그러나 AssetFactory::createAsset()
을 자신의 자산을 허용하지 않습니다. CSS/JS, 서버 측에서 일부 값을 변경해야하기 때문에 StringAsset
을 사용할 수있는 가능성이 필요합니다.
AssetFactory::createAsset()
을 사용하는 것 이외의 다른 방법이 있습니까?
$asset = new AssetCollection(self::$stylesheets);
$filters = array
( 'less' // Less CSS Compiler
, 'import' // Solves @imports
, 'rewrite' // Rewrites Base URLs when moving to another URL
, 'min' // Minifies the script
);
$options = array('output' => 'assetic/*.css');
foreach ($filters as $filter) {
if ('?' != $filter[0]) {
$asset->ensureFilter(self::getCssAssetFactory()->getFilterManager()->get($filter));
} elseif (!$options['debug']) {
$asset->ensureFilter(self::getCssAssetFactory()->getFilterManager()->get(substr($filter, 1)));
}
}
$asset->setTargetPath(str_replace('*', self::getCssAssetFactory()->generateAssetName(self::$stylesheets, $filters, $options), $options['output']));
이 모두 적절하게 전화를 교체해야 ... : 당신은 짧은 당신에게 문제를주고있는 부분을 단락, 본질적으로 createAsset 방법의 내부 동작을 재현 할 수 있습니다처럼
어떻게됩니까? 오류가 있습니까? 어떤 결과를 기대합니까? 실제로 어떤 결과가 발생합니까? AssetFactory에 익숙하지 않지만 더 많은 정보가 도움이 될 것입니다. – Jason
아니요, 내 방법은 정상적으로 작동합니다. 오류 없음. 하지만 원래 Assetic Assets으로 확장해야합니다. AssetFactory :: createAsset() 메소드에 경로 문자열 대신에 자산을 추가하려고하면 다음 오류로 실패합니다. __ 치명적 오류 : [AssetFactory :: Asset \ FileAsset 유형의 객체를 [...]의 배열로 사용할 수 없습니다. ] \ lib \ vendor \ Assetic \ src \ Assetic \ Factory \ AssetFactory.php 라인 270__에서 예상했으나 의도하지 않았습니다. – kernel
우리는 어딘가로 가고 있다고 생각합니다. 우리가 다루고있는 것을보기 위해 조금 둘러 보았습니다. createAsset 메소드 *는 문자열 또는 문자열 배열을 소비해야하며 모든 유형의 객체는 항상 실패합니다. 입력을 처리 할 때 객체에 대해 parseInput()을 호출하고 270 행의 오류에 따라 입력을 배열로 처리합니다. 문자열을 사용하면 첫 번째 문자에 액세스하는 것입니다. 객체를 사용하면 치명적인 오류가 발생합니다. 당신이 원하는 것을 할 수는 없습니다. 문자열과 달리 Assetic Assets을 전달해야하는 이유는 무엇입니까? – Jason