本文整理汇总了PHP中Assetic\Factory\AssetFactory类的典型用法代码示例。如果您正苦于以下问题:PHP AssetFactory类的具体用法?PHP AssetFactory怎么用?PHP AssetFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AssetFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAsseticFactory
protected function getAsseticFactory()
{
if (empty($this->config["input_path"][0])) {
throw new \Exception('Empty input path');
}
$factory = new AssetFactory($this->config["input_path"][0], $this->config["debug"]);
$factory->setDefaultOutput("");
// add a FilterManager to the AssetFactory
$fm = new FilterManager();
$factory->setFilterManager($fm);
// adding some filters to the filter manager
if ($this->config["less_filter"]) {
$lessphpFilter = new LessphpFilter();
if ($this->lessPresets) {
$lessphpFilter->setPresets($this->lessPresets);
}
$fm->set("less", $lessphpFilter);
}
if ($this->config["scss_filter"]) {
$scssFilter = new ScssphpFilter();
$fm->set("scss", $scssFilter);
}
$fm->set("min", new CssMinFilter());
return $factory;
}
示例2: getMinifiedAsset
private function getMinifiedAsset()
{
if (!(new SplFileInfo($this->asset->getPath()))->isWritable()) {
throw new Exception("path " . $this->asset->getPath() . " is not writable");
}
$factory = new AssetFactory($this->asset->getPath());
$factory->addWorker(new CacheBustingWorker());
$factory->setDefaultOutput('*');
$fm = new FilterManager();
$fm->set('min', $this->filter);
$factory->setFilterManager($fm);
$asset = $factory->createAsset(call_user_func(function ($files) {
$r = [];
foreach ($files as $file) {
$r[] = $file['fs'];
}
return $r;
}, $this->files), ['min'], ['name' => $this->asset->getBasename()]);
// only write the asset file if it does not already exist..
if (!file_exists($this->asset->getPath() . DIRECTORY_SEPARATOR . $asset->getTargetPath())) {
$writer = new AssetWriter($this->asset->getPath());
$writer->writeAsset($asset);
// TODO: write some code to garbage collect files of a certain age?
// possible alternative, modify CacheBustingWorker to have option
// to append a timestamp instead of a hash
}
return $asset;
}
示例3: testNoFilterManager
public function testNoFilterManager()
{
$this->setExpectedException('LogicException', 'There is no filter manager.');
$factory = new AssetFactory('.');
$factory->createAsset(array('foo'), array('foo'));
}
示例4: getChildren
public function getChildren(AssetFactory $factory, $content, $loadPath = null)
{
$children = array();
$includePaths = $this->includePaths;
if (null !== $loadPath && !in_array($loadPath, $includePaths)) {
array_unshift($includePaths, $loadPath);
}
if (empty($includePaths)) {
return $children;
}
foreach (CssUtils::extractImports($content) as $reference) {
if ('.css' === substr($reference, -4)) {
continue;
}
// the reference may or may not have an extension or be a partial
if (pathinfo($reference, PATHINFO_EXTENSION)) {
$needles = array($reference, $this->partialize($reference));
} else {
$needles = array($reference . '.scss', $this->partialize($reference) . '.scss');
}
foreach ($includePaths as $includePath) {
foreach ($needles as $needle) {
if (file_exists($file = $includePath . '/' . $needle)) {
$child = $factory->createAsset($file, array(), array('root' => $includePath));
$children[] = $child;
$child->load();
$children = array_merge($children, $this->getChildren($factory, $child->getContent(), $includePath));
}
}
}
}
return $children;
}
示例5: __construct
/**
* Constructor
*
* @param AssetFactory $factory The AssetFactory
* @param CacheInterface $cache The Cache Manager
* @param AssetManager $manager The Asset Manager
*
* @return void
*/
public function __construct(AssetFactory $factory = null, CacheInterface $cache = null, $cacheDir = null, AssetManager $manager = null)
{
$this->factory = $factory;
$this->manager = $manager;
$this->cache = $cache;
$this->cacheDirectory = $cacheDir;
$this->factory->setAssetManager($this->getAssetManager());
}
示例6: getChildren
public function getChildren(AssetFactory $factory, $content, $loadPath = null)
{
$hash = md5($content);
if ($this->cache->has($hash)) {
return $factory->createAsset($this->cache->get($hash), array(), array('root' => $loadPath));
} else {
return parent::getChildren($factory, $content, $loadPath);
}
}
示例7: getAssetFactory
/**
* @param $rootPath
* @param $debug
* @return AssetFactory
*/
private function getAssetFactory($rootPath, $debug)
{
$filterManager = new FilterManager();
$filterManager->set('yui_js', new JsCompressorFilter(dirname(__DIR__) . '/../optimizers/yuicompressor/yuicompressor-2.4.7.jar'));
$assetFactory = new AssetFactory($rootPath, $debug);
$assetFactory->setFilterManager($filterManager);
$assetFactory->setAssetManager(new AssetManager());
return $assetFactory;
}
示例8: process
public function process(AssetInterface $asset, AssetFactory $factory)
{
$path = $asset->getTargetPath();
$ext = pathinfo($path, PATHINFO_EXTENSION);
$lastModified = $factory->getLastModified($asset);
if (null !== $lastModified) {
$path = substr_replace($path, "{$lastModified}.{$ext}", -1 * strlen($ext));
$asset->setTargetPath($path);
}
}
示例9: initialize
protected function initialize(InputInterface $input, OutputInterface $output)
{
$this->basePath = $input->getArgument('write_to') ?: $this->getConfig()->getWebBasePath();
$this->verbose = $input->getOption('verbose');
$assetFactory = new AssetFactory($this->getConfig()->getAssetsBasePath(), $this->getConfig()->isDebug());
$loader = new TwigFormulaLoader($this->twig());
$this->am = new LazyAssetManager($assetFactory);
$assetFactory->setAssetManager($this->am);
$this->am->setLoader('twig', $loader);
}
示例10: setUp
protected function setUp()
{
parent::setUp();
$this->am = $this->getMock('Assetic\\AssetManager');
$this->fm = $this->getMock('Assetic\\FilterManager');
$factory = new AssetFactory(__DIR__ . '/templates');
$factory->setAssetManager($this->am);
$factory->setFilterManager($this->fm);
$this->engine->addExtension(new AsseticExtensionForTest($factory));
$this->loader = new SmartyFormulaLoader($this->engine);
}
示例11: factoryAf
protected function factoryAf()
{
$uglify = new UglifyJs2Filter("/usr/bin/uglifyjs", "/usr/bin/node");
$uglify->setCompress(true);
$uglify->setMangle(true);
$uglify->setCompress(true);
$factory = new AssetFactory(__DIR__ . "/../");
$filterManager = new FilterManager();
$filterManager->set("uglify", $uglify);
$factory->setFilterManager($filterManager);
return $factory;
}
示例12: getHash
protected function getHash(AssetInterface $asset, AssetFactory $factory)
{
$hash = hash_init('sha1');
hash_update($hash, $factory->getLastModified($asset));
if ($asset instanceof AssetCollectionInterface) {
foreach ($asset as $i => $leaf) {
$sourcePath = $leaf->getSourcePath();
hash_update($hash, $sourcePath ?: $i);
}
}
return substr(hash_final($hash), 0, 7);
}
示例13: build
/**
* Builds the AssetFactory object
*
* @return \Assetic\Factory\AssetFactory
*/
public function build()
{
$assetManager = new AssetManager();
$filterManager = new FilterManager();
foreach ($this->filters as $filterName => $filter) {
$filterManager->set($filterName, $filter);
}
$assetsFactory = new AssetFactory($this->configurationHandler->webDir());
$assetsFactory->setAssetManager($assetManager);
$assetsFactory->setFilterManager($filterManager);
return $assetsFactory;
}
示例14: configureAssetTools
protected function configureAssetTools()
{
$fm = new FilterManager();
$fm->set('less', new LessphpFilter());
$fm->set('cssrewrite', new AssetCssUriRewriteFilter());
$fm->set('cssmin', new CssMinFilter());
$fm->set('jscompile', new CompilerApiFilter());
//$fm->set('jscompilejar', new CompilerJarFilter(storage_path('jar/compiler.jar')));
$factory = new AssetFactory(Config::get('asset-manager::asset.paths.asset_path'));
$factory->setFilterManager($fm);
$factory->setDebug(Config::get('app.debug'));
$this->assetFactory = $factory;
}
示例15: getAsseticFactory
protected function getAsseticFactory()
{
if (empty($this->config["input_path"][0])) {
throw new \Exception("Empty input path");
}
$factory = new AssetFactory($this->config["input_path"][0], $this->config["debug"]);
$factory->setDefaultOutput("");
// add a FilterManager to the AssetFactory
$fm = new FilterManager();
$factory->setFilterManager($fm);
$fm->set("jshrink", new JShrinkFilter());
return $factory;
}