コード例 #1
0
 /**
  * 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());
 }
コード例 #2
0
 protected function setUp()
 {
     if (!class_exists('Twig_Environment')) {
         $this->markTestSkipped('Twig is not installed.');
     }
     $this->am = $this->getMock('Assetic\\AssetManager');
     $this->fm = $this->getMock('Assetic\\FilterManager');
     $this->valueSupplier = $this->getMock('Assetic\\ValueSupplierInterface');
     $this->factory = new AssetFactory(__DIR__ . '/templates');
     $this->factory->setAssetManager($this->am);
     $this->factory->setFilterManager($this->fm);
     $this->twig = new \Twig_Environment(new \Twig_Loader_Filesystem(__DIR__ . '/templates'));
     $this->twig->addExtension(new AsseticExtension($this->factory, array(), $this->valueSupplier));
 }
コード例 #3
0
ファイル: Optimizer.php プロジェクト: eberhm/phoenix
 /**
  * @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;
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 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);
 }
コード例 #6
0
 /**
  * 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;
 }
コード例 #7
0
ファイル: ThemeAssets.php プロジェクト: dennesabing/dxapp
 public function renderThemeAssets()
 {
     $conf = (array) $this->getThemeAssets();
     $factory = new Factory\AssetFactory($conf['root_path']);
     $factory->setAssetManager($this->getAssetManager());
     $factory->setFilterManager($this->getFilterManager());
     $factory->setDebug($this->configuration->isDebug());
     $mobileDetect = $this->serviceManager->get('dxMobileDetect');
     $isTablet = $mobileDetect->isTablet();
     $assetName = 'assets';
     $filterName = 'filters';
     $optionName = 'options';
     $outputName = 'output';
     if ($mobileDetect->isMobile()) {
         $assetName = $assetName . 'Mobile';
         $filterName = $filterName . 'Mobile';
         $optionName = $optionName . 'Mobile';
         $outputName = $outputName . 'Mobile';
     }
     if ($mobileDetect->isTablet()) {
         $assetName = $assetName . 'Tablet';
         $filterName = $filterName . 'Tablet';
         $optionName = $optionName . 'Tablet';
         $outputName = $outputName . 'Mobile';
     }
     $collections = (array) $conf['collections'];
     foreach ($collections as $name => $options) {
         $assets = isset($options[$assetName]) ? $options[$assetName] : isset($options['assets']) ? $options['assets'] : array();
         $filtersx = isset($options[$filterName]) ? $options[$filterName] : isset($options['filters']) ? $options['filters'] : array();
         $options = isset($options[$optionName]) ? $options[$optionName] : isset($options['options']) ? $options['options'] : array();
         $options['output'] = isset($options[$outputName]) ? $options[$outputName] : isset($options['output']) ? $options['output'] : $name;
         $filters = $this->initFilters($filtersx);
         /** @var $asset \Assetic\Asset\AssetCollection */
         $asset = $factory->createAsset($assets, $filters, $options);
         # allow to move all files 1:1 to new directory
         # its particulary usefull when this assets are images.
         if (isset($options['move_raw']) && $options['move_raw']) {
             foreach ($asset as $key => $value) {
                 $name = md5($value->getSourceRoot() . $value->getSourcePath());
                 $value->setTargetPath($value->getSourcePath());
                 $value = $this->cache($value);
                 $this->assetManager->set($name, $value);
             }
         } else {
             $asset = $this->cache($asset);
             $this->assetManager->set($name, $asset);
         }
     }
     $writer = new AssetWriter($this->configuration->getWebPath());
     $writer->writeManagerAssets($this->assetManager);
 }
コード例 #8
0
 protected function setUp()
 {
     if (!class_exists('Twig_Environment')) {
         $this->markTestSkipped('Twig is not installed.');
     }
     $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);
     $twig = new \Twig_Environment($this->getMock('Twig_LoaderInterface'));
     $twig->addExtension(new AsseticExtension($factory, array('some_func' => array('filter' => 'some_filter', 'options' => array('output' => 'css/*.css')))));
     $this->loader = new TwigFormulaLoader($twig);
 }
コード例 #9
0
ファイル: Module.php プロジェクト: lukezbihlyj/silex-assets
 /**
  * {@inheritDoc}
  */
 public function init(Application $app)
 {
     $app['assets'] = $app->share(function () use($app) {
         $assetManager = new AssetManager();
         $filterManager = new FilterManager();
         $filterManager->set('less', new LessphpFilter());
         $filterManager->set('cssmin', new CssMinFilter());
         $filterManager->set('jsmin', new JSqueezeFilter());
         $factory = new AssetFactory($app['assets.path']);
         $factory->setAssetManager($assetManager);
         $factory->setFilterManager($filterManager);
         $factory->setDefaultOutput('misc/*');
         return $factory;
     });
 }
コード例 #10
0
    protected function setUp()
    {
        if (!class_exists('Twig_Environment')) {
            $this->markTestSkipped('Twig is not installed.');
        }

        $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);

        $twig = new \Twig_Environment();
        $twig->addExtension(new AsseticExtension($factory));

        $this->loader = new TwigFormulaLoader($twig);
    }
 /**
  *
  * @param  Application $app
  */
 function register(Application $app)
 {
     $app['assetic.asset.root'] = '';
     $app['assetic.asset.output_root'] = '';
     $app['assetic.debug'] = false;
     $app['assetic.filter'] = array();
     $app['assetic.filter.default'] = array('cssmin' => '\\Assetic\\Filter\\CssMinFilter', 'cssrewrite' => '\\Assetic\\Filter\\CssRewriteFilter');
     $app['assetic.filter_manager'] = $app->share(function ($app) {
         $filterManager = new FilterManager();
         return $filterManager;
     });
     $app['assetic.asset_manager'] = $app->share(function ($app) {
         $assetManager = new AssetManager();
         return $assetManager;
     });
     $app['assetic.asset_factory'] = $app->share(function ($app) {
         $assetFactory = new AssetFactory($app['assetic.asset.root']);
         $assetFactory->setDefaultOutput($app['assetic.asset.output_root']);
         $assetFactory->setFilterManager($app['assetic.filter_manager']);
         $assetFactory->setAssetManager($app['assetic.asset_manager']);
         $assetFactory->setDebug($app['assetic.debug']);
         return $assetFactory;
     });
     $app['assetic.lazy_asset_manager'] = $app->share(function ($app) {
         $lazyAssetManager = new LazyAssetManager($app['assetic.asset_factory']);
         $lazyAssetManager->setLoader('twig', new TwigAsseticIntegrationFormulaLoader($app['twig'], null, $app));
         return $lazyAssetManager;
     });
     $app['assetic.asset_writer'] = $app->share(function ($app) {
         $assetWriter = new AssetWriter($app['assetic.asset.output_root']);
         return $assetWriter;
     });
     /*
      * Twig
      *
      */
     // Replace Twig loader
     $app['twig.loader.filesystem'] = $app->share(function ($app) {
         return new \Wake\Twig_AsseticLoader_Filesystem($app['twig.path']);
     });
     $app['twig.loader'] = $app->share(function ($app) {
         return new \Wake\Twig_AsseticLoader_Chain(array($app['twig.loader.array'], $app['twig.loader.filesystem']));
     });
 }
コード例 #12
0
 public function register()
 {
     // Register the asset manager singleton
     $this->app->bindShared('Concrete\\Package\\AssetPipeline\\Src\\Asset\\UtilityInterface', function ($app) {
         return new AssetUtility($app);
     });
     // Register filter settings repository singleton
     $this->app->singleton('Concrete\\Package\\AssetPipeline\\Src\\Asset\\Filter\\SettingsRepositoryInterface', 'Concrete\\Package\\AssetPipeline\\Src\\Asset\\Filter\\SettingsRepository');
     // Register Assetic's AssetFactory
     $this->app->bindShared('Assetic\\Factory\\AssetFactory', function ($app) {
         $am = new AssetManager();
         $fm = new FilterManager();
         $factory = new AssetFactory(DIR_BASE);
         $factory->setAssetManager($am);
         $factory->setFilterManager($fm);
         return $factory;
     });
     $singletons = array('helper/assets' => '\\Concrete\\Package\\AssetPipeline\\Src\\Service\\Assets');
     foreach ($singletons as $key => $value) {
         $this->app->singleton($this->pkgHandle . '/' . $key, $value);
     }
 }
コード例 #13
0
 public function register(Container $app)
 {
     $app['assetic.assets'] = $app['assetic.filters'] = $app['assetic.workers'] = array();
     $app['assetic.asset_manager'] = function () use($app) {
         $am = new AssetManager();
         if (isset($app['assetic.assets'])) {
             $assets = $app['assetic.assets'];
             if (!is_array($assets)) {
                 $assets = array($assets);
             }
             foreach ($assets as $name => $asset) {
                 if (!is_array($asset)) {
                     // não collection, transformar em collection
                     $asset = array($asset);
                 }
                 $col = new AssetCollection();
                 foreach ($asset as $a) {
                     if (is_string($a)) {
                         // é referencia
                         $a = new AssetReference($am, $a);
                     }
                     if (!$a instanceof AssetInterface) {
                         throw new \InvalidArgumentException("'assetic.assets' precisa ser um array de AssetInterface");
                     }
                     $col->add($a);
                 }
                 $am->set($name, $col);
             }
         }
         return $am;
     };
     $app['assetic.filter_manager'] = function () use($app) {
         $fm = new FilterManager();
         if (isset($app['assetic.filters'])) {
             $filters = $app['assetic.filters'];
             if (!is_array($filters)) {
                 $filters = array($filters);
             }
             foreach ($filters as $name => $filter) {
                 $fm->set($name, $filter);
             }
         }
         return $fm;
     };
     $app['assetic.factory'] = function () use($app) {
         $factory = new AssetFactory($app['assetic.dist_path']);
         $factory->setAssetManager($app['assetic.asset_manager']);
         $factory->setFilterManager($app['assetic.filter_manager']);
         $factory->setDebug(isset($app['debug']) ? $app['debug'] : false);
         $factory->setDefaultOutput($app['assetic.dist_path']);
         if (isset($app['assetic.workers']) && is_array($app['assetic.workers'])) {
             foreach ($app['assetic.workers'] as $worker) {
                 $factory->addWorker($worker);
             }
         }
         return $factory;
     };
     $app['assetic.lazy_asset_manager'] = function () use($app) {
         $am = new LazyAssetManager($app['assetic.factory']);
         if (isset($app['twig'])) {
             // carrega os assets pelo twig
             $am->setLoader('twig', new TwigFormulaLoader($app['twig']));
             $loader = $app['twig.loader.filesystem'];
             $namespaces = $loader->getNamespaces();
             foreach ($namespaces as $ns) {
                 if (count($loader->getPaths($ns)) > 0) {
                     $iterator = Finder::create()->files()->in($loader->getPaths($ns));
                     foreach ($iterator as $file) {
                         $resource = new TwigResource($loader, '@' . $ns . '/' . $file->getRelativePathname());
                         $am->addResource($resource, 'twig');
                     }
                 }
             }
         }
         return $am;
     };
     $app['assetic.asset_writer'] = function () use($app) {
         return new AssetWriter($app['assetic.dist_path']);
     };
     if (isset($app['twig'])) {
         $app['twig'] = $app->extend('twig', function ($twig, $app) {
             $functions = array('cssrewrite' => array('options' => array('combine' => true)));
             $twig->addExtension(new AsseticExtension($app['assetic.factory'], $functions));
             return $twig;
         });
     }
 }
コード例 #14
0
 /**
  * @param array $configuration
  * @return Factory\AssetFactory
  */
 public function createAssetFactory(array $configuration)
 {
     $factory = new Factory\AssetFactory($configuration['root_path']);
     $factory->setAssetManager($this->getAssetManager());
     $factory->setFilterManager($this->getFilterManager());
     // Cache buster should be add only if cache is enabled and if is available.
     if ($this->configuration->getCacheEnabled()) {
         $worker = $this->getCacheBusterStrategy();
         if ($worker instanceof WorkerInterface) {
             $factory->addWorker($worker);
         }
     }
     $factory->setDebug($this->configuration->isDebug());
     return $factory;
 }
コード例 #15
0
 /**
  * Registers services on the given container.
  *
  * This method should only be used to configure services and parameters.
  * It should not get services.
  *
  * @param Container $pimple An Container instance
  */
 public function register(Container $pimple)
 {
     /*
      * Default configuration.
      */
     $pimple['assetic.debug'] = false;
     $pimple['assetic.assets'] = array();
     $pimple['assetic.variables'] = array();
     $pimple['assetic.register_functions'] = true;
     $pimple['assetic.java.bin'] = '/usr/bin/java';
     $pimple['assetic.node.bin'] = '/usr/bin/node';
     $pimple['assetic.node.paths'] = array();
     $pimple['assetic.ruby.bin'] = '/usr/bin/ruby';
     $pimple['assetic.sass.bin'] = '/usr/bin/sass';
     /*
      * Finds IDs of all Asset Manager services.
      */
     $pimple['assetic.asset_managers'] = $pimple->factory(function (Container $c) {
         $ids = preg_grep(self::ASSET_MANAGER_MATCH, $c->keys());
         return $ids;
     });
     /*
      * Asset Factory configuration happens here
      *
      * @param Container $c
      * @return mixed
      */
     $pimple['assetic'] = function (Container $c) {
         // initializing lazy asset manager
         if (isset($c['assetic.assets']) && is_array($c['assetic.assets']) && !empty($c['assetic.assets'])) {
             $c['assetic.lazy_asset_manager'];
         }
         return $c['assetic.factory'];
     };
     /*
      * Factory
      *
      * @param Container $c
      * @return AssetFactory
      */
     $pimple['assetic.factory'] = function (Container $c) {
         $root = isset($c['assetic.read_from']) ? $c['assetic.read_from'] : $c['assetic.write_to'];
         $factory = new AssetFactory($root, $c['assetic.debug']);
         $factory->setAssetManager($c['assetic.asset_manager']);
         $factory->setFilterManager($c['assetic.filter_manager']);
         // Optionally enable the global asset functions.
         if ($c['assetic.register_functions']) {
             assetic_init($factory);
         }
         return $factory;
     };
     /*
      * Asset writer, writes to the 'assetic.write_to' folder
      *
      * @param Container $c
      * @return AssetWriter
      */
     $pimple['assetic.asset_writer'] = function (Container $c) {
         return new AssetWriter($c['assetic.write_to']);
     };
     /*
      * Asset manager
      *
      * @return AssetManager
      */
     $pimple['assetic.asset_manager'] = function () {
         return new AssetManager();
     };
     /*
      * Filter manager
      *
      * @return FilterManager
      */
     $pimple['assetic.filter_manager'] = function () {
         return new FilterManager();
     };
     /*
      * Lazy asset manager for loading assets from $pimple['assetic.assets']
      *
      * @param Container $c
      * @return \Assetic\Factory\LazyAssetManager
      */
     $pimple['assetic.lazy.asset_manager'] = function (Container $c) {
         $lazy = new LazyAssetManager($c['assetic.factory']);
         foreach ($c['assetic.assets'] as $name => $formula) {
             $lazy->setFormula($name, $formula);
         }
         return $lazy;
     };
 }
コード例 #16
0
 public function register(Application $app)
 {
     $app['assetic.options'] = array();
     /**
      * Asset Factory configuration happens here
      */
     $app['assetic'] = $app->share(function () use($app) {
         $app['assetic.options'] = array_replace(array('debug' => isset($app['debug']) ? $app['debug'] : false, 'formulae_cache_dir' => null, 'auto_dump_assets' => isset($app['debug']) ? !$app['debug'] : true), $app['assetic.options']);
         // initializing lazy asset manager
         if (isset($app['assetic.formulae']) && !is_array($app['assetic.formulae']) && !empty($app['assetic.formulae'])) {
             $app['assetic.lazy_asset_manager'];
         }
         return $app['assetic.factory'];
     });
     /**
      * Factory
      *
      * @return Assetic\Factory\AssetFactory
      */
     $app['assetic.factory'] = $app->share(function () use($app) {
         $root = isset($app['assetic.path_to_source']) ? $app['assetic.path_to_source'] : $app['assetic.path_to_web'];
         $factory = new AssetFactory($root, $app['assetic.options']['debug']);
         $factory->setAssetManager($app['assetic.asset_manager']);
         $factory->setFilterManager($app['assetic.filter_manager']);
         return $factory;
     });
     /**
      * Asset writer, writes to the 'assetic.path_to_web' folder
      *
      * @return Assetic\AssetWriter
      */
     $app['assetic.asset_writer'] = $app->share(function () use($app) {
         return new AssetWriter($app['assetic.path_to_web']);
     });
     /**
      * Asset manager
      *
      * @return Assetic\AssetManager
      */
     $app['assetic.asset_manager'] = $app->share(function () use($app) {
         return new AssetManager();
     });
     /**
      * Filter manager
      *
      * @return Assetic\FilterManager
      */
     $app['assetic.filter_manager'] = $app->share(function () use($app) {
         return new FilterManager();
     });
     /**
      * Lazy asset manager for loading assets from $app['assetic.formulae']
      * (will be later maybe removed)
      */
     $app['assetic.lazy_asset_manager'] = $app->share(function () use($app) {
         $formulae = isset($app['assetic.formulae']) ? $app['assetic.formulae'] : array();
         $options = $app['assetic.options'];
         $lazy = new LazyAssetmanager($app['assetic.factory']);
         if (empty($formulae)) {
             return $lazy;
         }
         foreach ($formulae as $name => $formula) {
             $lazy->setFormula($name, $formula);
         }
         if ($options['formulae_cache_dir'] !== null && $options['debug'] !== true) {
             foreach ($lazy->getNames() as $name) {
                 $lazy->set($name, new AssetCache($lazy->get($name), new FilesystemCache($options['formulae_cache_dir'])));
             }
         }
         return $lazy;
     });
     $app['assetic.dumper'] = $app->share(function () use($app) {
         return new Dumper($app['assetic.asset_manager'], $app['assetic.lazy_asset_manager'], $app['assetic.asset_writer']);
     });
     if (isset($app['twig'])) {
         $app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
             $twig->addExtension(new AsseticExtension($app['assetic']));
             return $twig;
         }));
         $app['assetic.lazy_asset_manager'] = $app->share($app->extend('assetic.lazy_asset_manager', function ($am, $app) {
             $am->setLoader('twig', new TwigFormulaLoader($app['twig']));
             return $am;
         }));
         $app['assetic.dumper'] = $app->share($app->extend('assetic.dumper', function ($helper, $app) {
             $helper->setTwig($app['twig'], $app['twig.loader.filesystem']);
             return $helper;
         }));
     }
 }
コード例 #17
0
 /**
  * @param array $configuration
  *
  * @return Factory\AssetFactory
  */
 public function createAssetFactory(array $configuration)
 {
     $factory = new Factory\AssetFactory($configuration['root_path']);
     $factory->setAssetManager($this->getAssetManager());
     $factory->setFilterManager($this->getFilterManager());
     $worker = $this->getCacheBusterStrategy();
     if ($worker instanceof WorkerInterface) {
         $factory->addWorker($worker);
     }
     $factory->setDebug($this->configuration->isDebug());
     return $factory;
 }
コード例 #18
0
 public function prepare()
 {
     static $ready;
     if (!$ready) {
         $factory = new AssetFactory($this->getRoot(), $this->getDebug());
         $factory->setAssetManager($this->getAssetManager());
         $factory->setFilterManager($this->getFilterManager());
         $extension = new AsseticExtension($factory);
         $this->getEnvironment()->addExtensionClass('Assetic', $extension);
         $lazyAm = new LazyAssetManager($factory);
         $this->setLazyAssetManager($lazyAm);
         $fm = $this->getFilterManager();
         $sm = $this->getServiceManager();
         foreach ($this->getFilters() as $name => $class) {
             $fm->set($name, $sm->get($class));
         }
         $ready = true;
     }
     return $this;
 }
コード例 #19
0
 /**
  * Generates assets from $asset_path in $output_path, using $filters.
  *
  * @param        $assetSource
  * @param        $assetDirectoryBase
  * @param string $webAssetsDirectoryBase the full path to the asset file (or file collection, e.g. *.less)
  *
  * @param string $webAssetsTemplate the full disk path to the base assets output directory in the web space
  * @param        $webAssetsKey
  * @param string $outputUrl         the URL to the base assets output directory in the web space
  *
  * @param string $assetType the asset type: css, js, ... The generated files will have this extension. Pass an empty string to use the asset source extension.
  * @param array  $filters   a list of filters, as defined below (see switch($filter_name) ...)
  *
  * @param boolean $debug true / false
  *
  * @return string The URL to the generated asset file.
  */
 public function processAsset($assetSource, $assetDirectoryBase, $webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey, $outputUrl, $assetType, $filters, $debug)
 {
     Tlog::getInstance()->addDebug("Processing asset: assetSource={$assetSource}, assetDirectoryBase={$assetDirectoryBase}, webAssetsDirectoryBase={$webAssetsDirectoryBase}, webAssetsTemplate={$webAssetsTemplate}, webAssetsKey={$webAssetsKey}, outputUrl={$outputUrl}");
     $assetName = basename($assetSource);
     $inputDirectory = realpath(dirname($assetSource));
     $assetFileDirectoryInAssetDirectory = trim(str_replace(array($assetDirectoryBase, $assetName), '', $assetSource), DS);
     $am = new AssetManager();
     $fm = new FilterManager();
     // Get the filter list
     $filterList = $this->decodeAsseticFilters($fm, $filters);
     // Factory setup
     $factory = new AssetFactory($inputDirectory);
     $factory->setAssetManager($am);
     $factory->setFilterManager($fm);
     $factory->setDefaultOutput('*' . (!empty($assetType) ? '.' : '') . $assetType);
     $factory->setDebug($debug);
     $asset = $factory->createAsset($assetName, $filterList);
     $outputDirectory = $this->getDestinationDirectory($webAssetsDirectoryBase, $webAssetsTemplate, $webAssetsKey);
     // Get the URL part from the relative path
     $outputRelativeWebPath = $webAssetsTemplate . DS . $webAssetsKey;
     $assetTargetFilename = $asset->getTargetPath();
     /*
      * This is the final name of the generated asset
      * We preserve file structure intending to keep - for example - relative css links working
      */
     $assetDestinationPath = $outputDirectory . DS . $assetFileDirectoryInAssetDirectory . DS . $assetTargetFilename;
     Tlog::getInstance()->addDebug("Asset destination full path: {$assetDestinationPath}");
     // We generate an asset only if it does not exists, or if the asset processing is forced in development mode
     if (!file_exists($assetDestinationPath) || $this->debugMode && ConfigQuery::read('process_assets', true)) {
         $writer = new AssetWriter($outputDirectory . DS . $assetFileDirectoryInAssetDirectory);
         Tlog::getInstance()->addDebug("Writing asset to {$outputDirectory}" . DS . "{$assetFileDirectoryInAssetDirectory}");
         $writer->writeAsset($asset);
     }
     // Normalize path to generate a valid URL
     if (DS != '/') {
         $outputRelativeWebPath = str_replace(DS, '/', $outputRelativeWebPath);
         $assetFileDirectoryInAssetDirectory = str_replace(DS, '/', $assetFileDirectoryInAssetDirectory);
         $assetTargetFilename = str_replace(DS, '/', $assetTargetFilename);
     }
     return rtrim($outputUrl, '/') . '/' . trim($outputRelativeWebPath, '/') . '/' . trim($assetFileDirectoryInAssetDirectory, '/') . '/' . ltrim($assetTargetFilename, '/');
 }
コード例 #20
0
 /**
  * Returns the public path of an asset
  *
  * @return string A public path
  */
 public function asseticBlock(array $params = array(), $content = null, $template, &$repeat)
 {
     // In debug mode, we have to be able to loop a certain number of times, so we use a static counter
     static $count;
     static $assetsUrls;
     // Read config file
     if (isset($params['config_path'])) {
         $base_path = $_SERVER['DOCUMENT_ROOT'] . '/' . $params['config_path'];
     } else {
         // Find the config file in Symfony2 config dir
         $base_path = __DIR__ . '/../../../../app/config/smarty-assetic';
     }
     $config = json_decode(file_get_contents($base_path . '/config.json'));
     // Opening tag (first call only)
     if ($repeat) {
         // Read bundles and dependencies config files
         $bundles = json_decode(file_get_contents($base_path . '/bundles.json'));
         $dependencies = json_decode(file_get_contents($base_path . '/dependencies.json'));
         $am = new AssetManager();
         $fm = new FilterManager();
         $fm->set('yui_js', new Filter\Yui\JsCompressorFilter($config->yuicompressor_path, $config->java_path));
         $fm->set('yui_css', new Filter\Yui\CssCompressorFilter($config->yuicompressor_path, $config->java_path));
         $fm->set('less', new Filter\LessphpFilter());
         $fm->set('sass', new Filter\Sass\SassFilter());
         $fm->set('closure_api', new Filter\GoogleClosure\CompilerApiFilter());
         $fm->set('closure_jar', new Filter\GoogleClosure\CompilerJarFilter($config->closurejar_path, $config->java_path));
         // Factory setup
         $factory = new AssetFactory($_SERVER['DOCUMENT_ROOT']);
         $factory->setAssetManager($am);
         $factory->setFilterManager($fm);
         $factory->setDefaultOutput('assetic/*.' . $params['output']);
         if (isset($params['filter'])) {
             $filters = explode(',', $params['filter']);
         } else {
             $filters = array();
         }
         // Prepare the assets writer
         $writer = new AssetWriter($params['build_path']);
         // If a bundle name is provided
         if (isset($params['bundle'])) {
             $asset = $factory->createAsset($bundles->{$params}['output']->{$params}['bundle'], $filters, array($params['debug']));
             $cache = new AssetCache($asset, new FilesystemCache($params['build_path']));
             $writer->writeAsset($cache);
             // If individual assets are provided
         } elseif (isset($params['assets'])) {
             $assets = array();
             // Include only the references first
             foreach (explode(',', $params['assets']) as $a) {
                 // If the asset is found in the dependencies file, let's create it
                 // If it is not found in the assets but is needed by another asset and found in the references, don't worry, it will be automatically created
                 if (isset($dependencies->{$params}['output']->assets->{$a})) {
                     // Create the reference assets if they don't exist
                     foreach ($dependencies->{$params}['output']->assets->{$a} as $ref) {
                         try {
                             $am->get($ref);
                         } catch (InvalidArgumentException $e) {
                             $assetTmp = $factory->createAsset($dependencies->{$params}['output']->references->{$ref});
                             $am->set($ref, $assetTmp);
                             $assets[] = '@' . $ref;
                         }
                     }
                 }
             }
             // Now, include assets
             foreach (explode(',', $params['assets']) as $a) {
                 // Add the asset to the list if not already present, as a reference or as a simple asset
                 $ref = null;
                 if (isset($dependencies->{$params}['output'])) {
                     foreach ($dependencies->{$params}['output']->references as $name => $file) {
                         if ($file == $a) {
                             $ref = $name;
                             break;
                         }
                     }
                 }
                 if (array_search($a, $assets) === false && ($ref === null || array_search('@' . $ref, $assets) === false)) {
                     $assets[] = $a;
                 }
             }
             // Create the asset
             $asset = $factory->createAsset($assets, $filters, array($params['debug']));
             $cache = new AssetCache($asset, new FilesystemCache($params['build_path']));
             $writer->writeAsset($cache);
         }
         // If debug mode is active, we want to include assets separately
         if ($params['debug']) {
             $assetsUrls = array();
             foreach ($asset as $a) {
                 $cache = new AssetCache($a, new FilesystemCache($params['build_path']));
                 $writer->writeAsset($cache);
                 $assetsUrls[] = $a->getTargetPath();
             }
             // It's easier to fetch the array backwards, so we reverse it to insert assets in the right order
             $assetsUrls = array_reverse($assetsUrls);
             $count = count($assetsUrls);
             if (isset($config->site_url)) {
                 $template->assign($params['asset_url'], $config->site_url . '/' . $params['build_path'] . '/' . $assetsUrls[$count - 1]);
             } else {
                 $template->assign($params['asset_url'], '/' . $params['build_path'] . '/' . $assetsUrls[$count - 1]);
             }
             // Production mode, include an all-in-one asset
         } else {
             if (isset($config->site_url)) {
                 $template->assign($params['asset_url'], $config->site_url . '/' . $params['build_path'] . '/' . $asset->getTargetPath());
             } else {
                 $template->assign($params['asset_url'], '/' . $params['build_path'] . '/' . $asset->getTargetPath());
             }
         }
         // Closing tag
     } else {
         if (isset($content)) {
             // If debug mode is active, we want to include assets separately
             if ($params['debug']) {
                 $count--;
                 if ($count > 0) {
                     if (isset($config->site_url)) {
                         $template->assign($params['asset_url'], $config->site_url . '/' . $params['build_path'] . '/' . $assetsUrls[$count - 1]);
                     } else {
                         $template->assign($params['asset_url'], '/' . $params['build_path'] . '/' . $assetsUrls[$count - 1]);
                     }
                 }
                 $repeat = $count > 0;
             }
             return $content;
         }
     }
 }
コード例 #21
0
ファイル: Assets.php プロジェクト: RanLee/XoopsCore
 /**
  * getUrlToAssets
  *
  * Create an asset file from a list of assets
  *
  * @param string       $type    type of asset, css or js
  * @param array        $assets  list of source files to process
  * @param string|array $filters either a comma separated list of known namsed filters
  *                              or an array of named filters and/or filter object
  * @param string       $target  target path, will default to assets directory
  *
  * @return string URL to asset file
  */
 public function getUrlToAssets($type, $assets, $filters = 'default', $target = null)
 {
     if (is_scalar($assets)) {
         $assets = array($assets);
         // just a single path name
     }
     if ($filters == 'default') {
         if (isset($this->default_filters[$type])) {
             $filters = $this->default_filters[$type];
         } else {
             $filters = '';
         }
     }
     if (!is_array($filters)) {
         if (empty($filters)) {
             $filters = array();
         } else {
             $filters = explode(',', str_replace(' ', '', $filters));
         }
     }
     if (isset($this->default_output[$type])) {
         $output = $this->default_output[$type];
     } else {
         $output = '';
     }
     $xoops = \Xoops::getInstance();
     if (isset($target)) {
         $target_path = $target;
     } else {
         $target_path = $xoops->path('assets');
     }
     try {
         $am = $this->assetManager;
         $fm = new FilterManager();
         foreach ($filters as $filter) {
             if (is_object($filter) && $filter instanceof $this->filterInterface) {
                 $filterArray[] = $filter;
             } else {
                 switch (ltrim($filter, '?')) {
                     case 'cssembed':
                         $fm->set('cssembed', new Filter\PhpCssEmbedFilter());
                         break;
                     case 'cssmin':
                         $fm->set('cssmin', new Filter\CssMinFilter());
                         break;
                     case 'cssimport':
                         $fm->set('cssimport', new Filter\CssImportFilter());
                         break;
                     case 'cssrewrite':
                         $fm->set('cssrewrite', new Filter\CssRewriteFilter());
                         break;
                     case 'lessphp':
                         $fm->set('lessphp', new Filter\LessphpFilter());
                         break;
                     case 'scssphp':
                         $fm->set('scssphp', new Filter\ScssphpFilter());
                         break;
                     case 'jsmin':
                         $fm->set('jsmin', new Filter\JSMinFilter());
                         break;
                     default:
                         throw new \Exception(sprintf('%s filter not implemented.', $filter));
                         break;
                 }
             }
         }
         // Factory setup
         $factory = new AssetFactory($target_path);
         $factory->setAssetManager($am);
         $factory->setFilterManager($fm);
         $factory->setDefaultOutput($output);
         $factory->setDebug($this->debug);
         $factory->addWorker(new CacheBustingWorker());
         // Prepare the assets writer
         $writer = new AssetWriter($target_path);
         // Translate asset paths, remove duplicates
         $translated_assets = array();
         foreach ($assets as $k => $v) {
             // translate path if not a reference or absolute path
             if (0 == preg_match("/^\\/|^\\\\|^[a-zA-Z]:|^@/", $v)) {
                 $v = $xoops->path($v);
             }
             if (!in_array($v, $translated_assets)) {
                 $translated_assets[] = $v;
             }
         }
         // Create the asset
         $asset = $factory->createAsset($translated_assets, $filters);
         $asset_path = $asset->getTargetPath();
         if (!is_readable($target_path . $asset_path)) {
             $xoops->events()->triggerEvent('debug.timer.start', array('writeAsset', $asset_path));
             $oldumask = umask(02);
             $writer->writeAsset($asset);
             umask($oldumask);
             $xoops->events()->triggerEvent('debug.timer.stop', 'writeAsset');
         }
         return $xoops->url('assets/' . $asset_path);
     } catch (\Exception $e) {
         $xoops->events()->triggerEvent('core.exception', $e);
         return null;
     }
 }
コード例 #22
0
use Assetic\AssetManager;
use Assetic\Cache\FilesystemCache;
use Assetic\Cache\ApcCache;
use Assetic\Asset\AssetCache;
use Assetic\Asset\AssetCollection;
use Assetic\Asset\FileAsset;
use Assetic\Asset\GlobAsset;
use Assetic\AssetWriter;
use Assetic\Filter\Yui\CssCompressorFilter as YuiCompressorFilter;
use Assetic\Filter\GoogleClosure\CompilerJarFilter as GoogleClosureFilter;
$fm = new FilterManager();
$am = new AssetManager();
$factory = new AssetFactory(__DIR__ . '/', true);
$factory->setDefaultOutput('/');
$factory->setFilterManager($fm);
$factory->setAssetManager($am);
$yui_compressor = new YuiCompressorFilter(__DIR__ . '/utils/yuicompressor-2.4.8.jar');
$fm->set('yui_css', $yui_compressor);
$google_closure_compiler = new GoogleClosureFilter(__DIR__ . '/utils/google-closure-compiler.jar');
$google_closure_compiler->setLanguage($google_closure_compiler::LANGUAGE_ECMASCRIPT5);
$fm->set('google_js', $google_closure_compiler);
// The Asset Manager allows us to keep our assets organized.
$am->set('main_js', new AssetCollection(array(new FileAsset(__DIR__ . '/../assets/js/lib/angular.js'), new FileAsset(__DIR__ . '/../assets/js/lib/underscore.js'), new FileAsset(__DIR__ . '/../assets/js/lib/angular-route.js'), new FileAsset(__DIR__ . '/../assets/js/lib/angular-resource.js'), new FileAsset(__DIR__ . '/../assets/js/lib/heartcode-canvasloader.js'), new FileAsset(__DIR__ . '/../assets/js/app/myKraigsList.js'))));
$am->set('main_css', new AssetCollection(array(new FileAsset(__DIR__ . '/../assets/css/body.css'), new FileAsset(__DIR__ . '/../assets/css/angular-csp.css'))));
$write_cache = function ($asset) {
    $cache = new AssetCache($asset, new FilesystemCache(__DIR__ . '/../cache/assets/'));
    $writer = new AssetWriter(__DIR__ . '/compiled/');
    $writer->writeAsset($cache);
};
$js_asset = $factory->createAsset(array('@main_js'), array('google_js'), array('output' => '/js/application.js'));
$css_asset = $factory->createAsset(array('@main_css'), array('yui_css'), array('output' => '/css/application.css'));
コード例 #23
0
 public static function register($core)
 {
     $app = $core->getServiceContainer();
     $container = $app;
     // Initialise le parametres services comme un tableau vide s'il n'existe pas sinon fussion un autre tableau à celui déjà existant
     $services = $core->getConf()->loadConfigurationFile("services", __DIR__ . DIRECTORY_SEPARATOR . "Resources" . DIRECTORY_SEPARATOR . "config");
     if (!$container->has("services")) {
         $container->services = array();
     }
     $container->services = array_merge($container->services, $services);
     $app['assetic.options'] = array();
     /**
      * Asset Factory configuration happens here
      */
     $app['assetic'] = $app->share(function () use($app) {
         $app['assetic.options'] = array_replace(array('debug' => isset($app['debug']) ? $app['debug'] : false, 'formulae_cache_dir' => null, 'auto_dump_assets' => isset($app['debug']) ? !$app['debug'] : true), $app['assetic.options']);
         // initializing lazy asset manager
         if (isset($app['assetic.formulae']) && !is_array($app['assetic.formulae']) && !empty($app['assetic.formulae'])) {
             $app['assetic.lazy_asset_manager'];
         }
         return $app['assetic.factory'];
     });
     /**
      * Factory
      *
      * @return Assetic\Factory\AssetFactory
      */
     $app['assetic.factory'] = $app->share(function () use($app) {
         $root = isset($app['assetic.path_to_source']) ? $app['assetic.path_to_source'] : $app['assetic.path_to_web'];
         $factory = new AssetFactory($root, $app['assetic.options']['debug']);
         $factory->setAssetManager($app['assetic.asset_manager']);
         $factory->setFilterManager($app['assetic.filter_manager']);
         return $factory;
     });
     /**
      * Asset writer, writes to the 'assetic.path_to_web' folder
      *
      * @return Assetic\AssetWriter
      */
     $app['assetic.asset_writer'] = $app->share(function () use($app) {
         return new AssetWriter($app['assetic.path_to_web']);
     });
     /**
      * Asset manager
      *
      * @return Assetic\AssetManager
      */
     $app['assetic.asset_manager'] = $app->share(function () use($app) {
         return new AssetManager();
     });
     /**
      * Filter manager
      *
      * @return Assetic\FilterManager
      */
     $app['assetic.filter_manager'] = $app->share(function () use($app) {
         return new FilterManager();
     });
     /**
      * Lazy asset manager for loading assets from $app['assetic.formulae']
      * (will be later maybe removed)
      */
     $app['assetic.lazy_asset_manager'] = $app->share(function () use($app) {
         $formulae = isset($app['assetic.formulae']) ? $app['assetic.formulae'] : array();
         $options = $app['assetic.options'];
         $lazy = new LazyAssetmanager($app['assetic.factory']);
         if (empty($formulae)) {
             return $lazy;
         }
         foreach ($formulae as $name => $formula) {
             $lazy->setFormula($name, $formula);
         }
         if ($options['formulae_cache_dir'] !== null && $options['debug'] !== true) {
             foreach ($lazy->getNames() as $name) {
                 $lazy->set($name, new AssetCache($lazy->get($name), new FilesystemCache($options['formulae_cache_dir'])));
             }
         }
         return $lazy;
     });
     $app['assetic.dumper'] = $app->share(function () use($app) {
         return new Dumper($app['assetic.asset_manager'], $app['assetic.lazy_asset_manager'], $app['assetic.asset_writer']);
     });
     $eventManager = $core->getEventManager();
     $eventManager->listenEvent("onReady", function ($event) use($app) {
         if (isset($app['twig'])) {
             $app['assetic.lazy_asset_manager'] = $app->share($app->extend('assetic.lazy_asset_manager', function ($am, $app) {
                 $am->setLoader('twig', new TwigFormulaLoader($app['twig']));
                 return $am;
             }));
             $app['assetic.dumper'] = $app->share($app->extend('assetic.dumper', function ($helper, $app) {
                 $helper->setTwig($app['twig'], $app['twig.loader.filesystem']);
                 return $helper;
             }));
         }
         // Register our filters to use
         if (isset($app['assetic.filters']) && is_callable($app['assetic.filters'])) {
             $app['assetic.filters']($app['assetic.filter_manager']);
         }
         /**
          * Writes down all lazy asset manager and asset managers assets
          */
         // Boot assetic
         $assetic = $app['assetic'];
         if (!$app['debug']) {
             return;
         }
         $helper = $app['assetic.dumper'];
         if (isset($app['twig'])) {
             $helper->addTwigAssets();
         }
         $helper->dumpAssets();
     });
 }
コード例 #24
0
 public function __construct(AssetFactory $factory)
 {
     $this->factory = $factory;
     $factory->setAssetManager($this);
 }
コード例 #25
0
ファイル: bootstrap.php プロジェクト: RettuSh/e-pracownik
use Assetic\AssetManager;
use Assetic\AssetWriter;
use Assetic\Extension\Twig\AsseticExtension;
use Assetic\Extension\Twig\TwigFormulaLoader;
use Assetic\Extension\Twig\TwigResource;
use Assetic\Factory\AssetFactory;
use Assetic\Factory\LazyAssetManager;
use Assetic\Filter\LessFilter;
use Assetic\FilterManager;
use Symfony\Component\Finder\Finder;
$loader = new Twig_Loader_Filesystem(VIEWS_PATH);
$options = ['cache' => DEBUG_APP ? false : 'cache'];
$twig = new Twig_Environment($loader, $options);
$assetManager = new AssetManager();
$filterManager = new FilterManager();
$filterManager->set('less', new LessFilter(NODE_PATH, [NODE_MODULE_PATH]));
$assetFactory = new AssetFactory('assets/');
$assetFactory->setDebug(false);
$assetFactory->setAssetManager($assetManager);
$assetFactory->setFilterManager($filterManager);
$twig->addExtension(new AsseticExtension($assetFactory));
$lazyAssetManager = new LazyAssetManager($assetFactory);
$lazyAssetManager->setLoader('twig', new TwigFormulaLoader($twig));
$finder = new Finder();
$finder->files()->in('assets')->exclude('css')->exclude('js')->exclude('images')->name("*.twig");
foreach ($finder as $template) {
    $resource = new TwigResource($loader, $template->getFileName());
    $lazyAssetManager->addResource($resource, 'twig');
}
$writer = new AssetWriter('.');
$writer->writeManagerAssets($lazyAssetManager);
コード例 #26
0
function smarty_block_assetic($params, $content, $template, &$repeat)
{
    // In debug mode, we have to be able to loop a certain number of times, so we use a static counter
    static $count;
    static $assetsUrls;
    $realpath = realpath(__DIR__ . '/../../../' . $params['config_path']);
    $root = realpath($realpath . '/../') . '/';
    $base_path = null;
    $bundles = null;
    $dependencies = null;
    $themesService = \Zend_Registry::get('container')->getService('newscoop_newscoop.themes_service');
    $themePath = $themesService->getThemePath();
    $viewBildPath = '/themes/' . $themePath . $params['build_path'];
    $params['build_path'] = $root . $params['build_path'];
    // Set defaults
    if (!array_key_exists('debug', $params)) {
        $params['debug'] = false;
    }
    // Read config file
    if (isset($params['config_path'])) {
        $base_path = __DIR__ . '/../../../' . $params['config_path'];
    }
    $config = json_decode(file_get_contents($base_path . '/config.json'));
    // Opening tag (first call only)
    if ($repeat) {
        // Read bundles and dependencies config files
        if (file_exists($base_path . '/bundles.json')) {
            $bundles = json_decode(file_get_contents($base_path . '/bundles.json'));
        }
        if (file_exists($base_path . '/dependencies.json')) {
            $dependencies = json_decode(file_get_contents($base_path . '/dependencies.json'));
        }
        $am = new AssetManager();
        $fm = new FilterManager();
        if (property_exists($config, 'cssembed_path')) {
            $cssEmbedFilter = new Filter\CssEmbedFilter($config->cssembed_path, $config->java_path);
            $cssEmbedFilter->setRoot($root);
            $fm->set('cssembed', $cssEmbedFilter);
        }
        if (property_exists($config, 'yuicompressor_path') && property_exists($config, 'java_path')) {
            $fm->set('yui_js', new Filter\Yui\JsCompressorFilter($config->yuicompressor_path, $config->java_path));
            $fm->set('yui_css', new Filter\Yui\CssCompressorFilter($config->yuicompressor_path, $config->java_path));
        }
        $fm->set('less', new Filter\LessphpFilter());
        $fm->set('sass', new Filter\Sass\SassFilter());
        $fm->set('closure_api', new Filter\GoogleClosure\CompilerApiFilter());
        $fm->set('rewrite', new Filter\CssRewriteFilter());
        if (property_exists($config, 'closurejar_path') && property_exists($config, 'java_path')) {
            $fm->set('closure_jar', new Filter\GoogleClosure\CompilerJarFilter($config->closurejar_path, $config->java_path));
        }
        // Factory setup
        $factory = new AssetFactory($root);
        $factory->setAssetManager($am);
        $factory->setFilterManager($fm);
        $factory->setDefaultOutput('*.' . $params['output']);
        $factory->setDebug($params['debug']);
        if (isset($params['filters'])) {
            $filters = explode(',', $params['filters']);
        } else {
            $filters = array();
        }
        // Prepare the assets writer
        $writer = new AssetWriter($params['build_path']);
        // If a bundle name is provided
        if (isset($params['bundle'])) {
            $asset = $factory->createAsset($bundles->{$params}['output']->{$params}['bundle'], $filters);
            $cache = new AssetCache($asset, new FilesystemCache($params['build_path']));
            $writer->writeAsset($cache);
            // If individual assets are provided
        } elseif (isset($params['assets'])) {
            $assets = array();
            // Include only the references first
            foreach (explode(',', $params['assets']) as $a) {
                // If the asset is found in the dependencies file, let's create it
                // If it is not found in the assets but is needed by another asset and found in the references, don't worry, it will be automatically created
                if (isset($dependencies->{$params}['output']->assets->{$a})) {
                    // Create the reference assets if they don't exist
                    foreach ($dependencies->{$params}['output']->assets->{$a} as $ref) {
                        try {
                            $am->get($ref);
                        } catch (InvalidArgumentException $e) {
                            $path = $dependencies->{$params}['output']->references->{$ref};
                            $assetTmp = $factory->createAsset($path);
                            $am->set($ref, $assetTmp);
                            $assets[] = '@' . $ref;
                        }
                    }
                }
            }
            // Now, include assets
            foreach (explode(',', $params['assets']) as $a) {
                // Add the asset to the list if not already present, as a reference or as a simple asset
                $ref = null;
                if (isset($dependencies->{$params}['output'])) {
                    foreach ($dependencies->{$params}['output']->references as $name => $file) {
                        if ($file == $a) {
                            $ref = $name;
                            break;
                        }
                    }
                }
                if (array_search($a, $assets) === FALSE && ($ref === null || array_search('@' . $ref, $assets) === FALSE)) {
                    $assets[] = $a;
                }
            }
            // Create the asset
            $asset = $factory->createAsset($assets, $filters);
            $cache = new AssetCache($asset, new FilesystemCache($params['build_path']));
            $writer->writeAsset($cache);
        }
        // If debug mode is active, we want to include assets separately
        if ($params['debug']) {
            $assetsUrls = array();
            foreach ($asset as $a) {
                $cache = new AssetCache($a, new FilesystemCache($params['build_path']));
                $writer->writeAsset($cache);
                $assetsUrls[] = $a->getTargetPath();
            }
            // It's easier to fetch the array backwards, so we reverse it to insert assets in the right order
            $assetsUrls = array_reverse($assetsUrls);
            $count = count($assetsUrls);
            if (isset($config->site_url)) {
                $template->assign($params['asset_url'], $config->site_url . '/' . $params['build_path'] . '/' . $assetsUrls[$count - 1]);
            } else {
                $template->assign($params['asset_url'], $viewBildPath . '/' . $assetsUrls[$count - 1]);
            }
            // Production mode, include an all-in-one asset
        } else {
            if (isset($config->site_url)) {
                $template->assign($params['asset_url'], $config->site_url . '/' . $params['build_path'] . '/' . $asset->getTargetPath());
            } else {
                $template->assign($params['asset_url'], $viewBildPath . '/' . $asset->getTargetPath());
            }
        }
        // Closing tag
    } else {
        if (isset($content)) {
            // If debug mode is active, we want to include assets separately
            if ($params['debug']) {
                $count--;
                if ($count > 0) {
                    if (isset($config->site_url)) {
                        $template->assign($params['asset_url'], $config->site_url . '/' . $params['build_path'] . '/' . $assetsUrls[$count - 1]);
                    } else {
                        $template->assign($params['asset_url'], '/' . $params['build_path'] . '/' . $assetsUrls[$count - 1]);
                    }
                }
                $repeat = $count > 0;
            }
            return $content;
        }
    }
}
コード例 #27
0
ファイル: index.php プロジェクト: ahyswang/eva-engine
 public function compress()
 {
     $am = new AssetManager();
     $am->set('jquery', new FileAsset($jsPath . '/jquery/jquery.js'));
     $am->set('base_css', new GlobAsset($cssPath . '/bootstrap/bootstrap.css'));
     $am->set('jquery_anytime', new AssetCollection(array(new AssetReference($am, 'jquery'), new FileAsset($jsPath . '/jquery/jquery.anytime.js'))));
     $fm = new FilterManager();
     $fm->set('yui_js', new Yui\JsCompressorFilter(__DIR__ . '/yuicompressor.jar', 'C:\\Program Files\\Java\\jdk1.7.0_09\\bin\\java.exe'));
     $factory = new AssetFactory(__DIR__);
     $factory->setAssetManager($am);
     $factory->setFilterManager($fm);
     $factory->setDebug(true);
     $js = $factory->createAsset(array('@jquery_anytime'), array(), array('output' => 'all.js'));
     $writer = new AssetWriter(__DIR__);
     $writer->writeAsset($js);
     //$css->setTargetPath(ASSETS);
     //$js->dump();
 }
コード例 #28
0
 public function register(Application $app)
 {
     $app['assetic.options'] = array_replace(array('debug' => false, 'formulae_cache_dir' => null), isset($app['assetic.options']) ? $app['assetic.options'] : array());
     /**
      * Asset Factory conifguration happens here
      */
     $app['assetic'] = $app->share(function () use($app) {
         // initializing lazy asset manager
         if (isset($app['assetic.formulae']) && !is_array($app['assetic.formulae']) && !empty($app['assetic.formulae'])) {
             $app['assetic.lazy_asset_manager'];
         }
         return $app['assetic.factory'];
     });
     /**
      * Factory
      * @return Assetic\Factory\AssetFactory
      */
     $app['assetic.factory'] = $app->share(function () use($app) {
         $options = $app['assetic.options'];
         $factory = new AssetFactory($app['assetic.path_to_web'], $options['debug']);
         $factory->setAssetManager($app['assetic.asset_manager']);
         $factory->setFilterManager($app['assetic.filter_manager']);
         return $factory;
     });
     /**
      * Writes down all lazy asset manager and asset managers assets
      */
     $app->after(function () use($app) {
         $app['assetic.asset_writer']->writeManagerAssets($app['assetic.lazy_asset_manager']);
         $app['assetic.asset_writer']->writeManagerAssets($app['assetic.asset_manager']);
     });
     /**
      * Asset writer, writes to the 'assetic.path_to_web' folder
      */
     $app['assetic.asset_writer'] = $app->share(function () use($app) {
         return new AssetWriter($app['assetic.path_to_web']);
     });
     /**
      * Asset manager, can be accessed via $app['assetic.asset_manager']
      * and can be configured via $app['assetic.assets'], just provide a
      * protected callback $app->protect(function($am) { }) and add
      * your assets inside the function to asset manager ($am->set())
      */
     $app['assetic.asset_manager'] = $app->share(function () use($app) {
         $assets = isset($app['assetic.assets']) ? $app['assetic.assets'] : function () {
         };
         $manager = new AssetManager();
         call_user_func_array($assets, array($manager, $app['assetic.filter_manager']));
         return $manager;
     });
     /**
      * Filter manager, can be accessed via $app['assetic.filter_manager']
      * and can be configured via $app['assetic.filters'], just provide a
      * protected callback $app->protect(function($fm) { }) and add
      * your filters inside the function to filter manager ($fm->set())
      */
     $app['assetic.filter_manager'] = $app->share(function () use($app) {
         $filters = isset($app['assetic.filters']) ? $app['assetic.filters'] : function () {
         };
         $manager = new FilterManager();
         call_user_func_array($filters, array($manager));
         return $manager;
     });
     /**
      * Lazy asset manager for loading assets from $app['assetic.formulae']
      * (will be later maybe removed)
      */
     $app['assetic.lazy_asset_manager'] = $app->share(function () use($app) {
         $formulae = isset($app['assetic.formulae']) ? $app['assetic.formulae'] : array();
         $options = $app['assetic.options'];
         $lazy = new LazyAssetmanager($app['assetic.factory']);
         if (empty($formulae)) {
             return $lazy;
         }
         foreach ($formulae as $name => $formula) {
             $lazy->setFormula($name, $formula);
         }
         if ($options['formulae_cache_dir'] !== null && $options['debug'] !== true) {
             foreach ($lazy->getNames() as $name) {
                 $lazy->set($name, new AssetCache($lazy->get($name), new FilesystemCache($options['formulae_cache_dir'])));
             }
         }
         return $lazy;
     });
     if (isset($app['twig'])) {
         $app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
             $twig->addExtension(new TwigAsseticExtension($app['assetic.factory']));
             return $twig;
         }));
     }
 }
コード例 #29
0
ファイル: Service.php プロジェクト: nuxwin/zf2-assetic-module
 public function initLoadedModules(array $loadedModules)
 {
     $moduleConfiguration = $this->configuration->getModules();
     foreach ($loadedModules as $moduleName => $module) {
         $moduleName = strtolower($moduleName);
         if (!isset($moduleConfiguration[$moduleName])) {
             continue;
         }
         $conf = (array) $moduleConfiguration[$moduleName];
         $factory = new Factory\AssetFactory($conf['root_path']);
         $factory->setAssetManager($this->getAssetManager());
         $factory->setFilterManager($this->getFilterManager());
         $factory->setDebug($this->configuration->isDebug());
         $collections = (array) $conf['collections'];
         foreach ($collections as $name => $options) {
             $assets = isset($options['assets']) ? $options['assets'] : array();
             $filters = isset($options['filters']) ? $options['filters'] : array();
             $options = isset($options['options']) ? $options['options'] : array();
             $options['output'] = isset($options['output']) ? $options['output'] : $name;
             $filters = $this->initFilters($filters);
             /** @var $asset \Assetic\Asset\AssetCollection */
             $asset = $factory->createAsset($assets, $filters, $options);
             # allow to move all files 1:1 to new directory
             # its particulary usefull when this assets are images.
             if (isset($options['move_raw']) && $options['move_raw']) {
                 foreach ($asset as $key => $value) {
                     $name = md5($value->getSourceRoot() . $value->getSourcePath());
                     $value->setTargetPath($value->getSourcePath());
                     $value = $this->cache($value);
                     $this->assetManager->set($name, $value);
                 }
             } else {
                 $asset = $this->cache($asset);
                 $this->assetManager->set($name, $asset);
             }
         }
         $writer = new AssetWriter($this->configuration->getWebPath());
         $writer->writeManagerAssets($this->assetManager);
     }
 }
コード例 #30
0
 /**
  * Sets the asset manager to use when creating asset references.
  *
  * @param AssetManagerInterface $am The asset manager
  */
 public function setAssetManager(AssetManagerInterface $am)
 {
     $this->assetFactory->setAssetManager($am);
 }