/** * Executes the current command. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @return null|int null or 0 if everything went fine, or an error code */ protected function execute(InputInterface $input, OutputInterface $output) { $config = $this->assetic->getConfiguration(); $config->setBuildOnRequest(true); $this->assetic->build(); $this->assetic->getAssetWriter()->writeManagerAssets($this->assetic->getAssetManager()); }
public function setupAction() { $config = $this->assetic->getConfiguration(); $mode = null !== ($mode = $config->getUmask()) ? $mode : 0775; $displayMode = decoct($mode); $cachePath = $config->getCachePath(); $pathExists = is_dir($cachePath); if ($cachePath && !$pathExists) { mkdir($cachePath, $mode, true); echo "Cache path created '{$cachePath}' with mode '{$displayMode}' \n"; } else { if ($pathExists) { echo "Creation of cache path '{$cachePath}' skipped - path exists \n"; } else { echo "Creation of cache path '{$cachePath}' skipped - no path provided \n"; } } $webPath = $config->getWebPath(); $pathExists = is_dir($webPath); if ($webPath && !$pathExists) { mkdir($webPath, $mode, true); echo "Web path created '{$webPath}' with mode '{$displayMode}' \n"; } else { if ($pathExists) { echo "Creation of web path '{$webPath}' skipped - path exists \n"; } else { echo "Creation of web path '{$webPath}' skipped - no path provided \n"; } } }
/** * @param ServiceLocatorInterface $serviceLocator * @return \AsseticBundle\Service */ public function createService(ServiceLocatorInterface $serviceLocator) { $configuration = $serviceLocator->get('Configuration'); $asseticConfig = new Configuration($configuration['assetic_configuration']); $asseticAssetManager = $serviceLocator->get('Assetic\\AssetManager'); $asseticFilterManager = $serviceLocator->get('Assetic\\FilterManager'); $asseticService = new Service($asseticConfig); $asseticService->setAssetManager($asseticAssetManager); $asseticService->setFilterManager($asseticFilterManager); $strategies = isset($configuration['assetic_configuration']['strategies']) ? $configuration['assetic_configuration']['strategies'] : array(); return $asseticService; }
/** * Executes the current command. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @return null|int null or 0 if everything went fine, or an error code */ protected function execute(InputInterface $input, OutputInterface $output) { $config = $this->assetic->getConfiguration(); $mode = null !== ($mode = $config->getUmask()) ? $mode : 0775; if (!$this->createPath($output, 'Cache', $config->getCachePath(), $mode)) { return 1; } if (!$this->createPath($output, 'Web', $config->getWebPath(), $mode)) { return 1; } return 0; }
/** * @param AssetInterface $asset * @param array $options * @return string */ protected function setupAsset(AssetInterface $asset, array $options = array()) { $ret = ''; if ($this->service->getConfiguration()->isDebug() && !$this->service->getConfiguration()->isCombine() && $asset instanceof AssetCollection) { // Move assets as single instance not as a collection foreach ($asset as $value) { /** @var AssetCollection $value */ $ret .= $this->helper($value, $options) . PHP_EOL; } } else { $ret .= $this->helper($asset, $options) . PHP_EOL; } return $ret; }
public function testWriteAssetIfNotUpdated() { $this->configuration->setBuildOnRequest(true); $this->configuration->setWriteIfChanged(true); $this->object->build(); $manager = $this->object->getAssetManager(); $assets = $manager->get('base_css')->all(); /** @var \Assetic\Asset\AssetInterface $asset */ $asset = $assets[0]; $asset->setTargetPath($manager->get('base_css')->getTargetPath()); $targetFile = $this->configuration->getWebPath($asset->getTargetPath()); if (is_file($targetFile)) { unlink($targetFile); } $this->assertFileNotExists($targetFile); $this->object->writeAsset($asset); $this->assertFileExists($targetFile); $sourceFile = $asset->getSourceRoot() . '/' . $asset->getSourcePath(); $targetMTime = filemtime($targetFile); sleep(2); $modifiedAsset = new FileAsset($sourceFile); $modifiedAsset->setTargetPath($targetFile); $this->object->writeAsset($modifiedAsset); clearstatcache(true, $targetFile); $targetMTimeNotModified = filemtime($targetFile); $this->assertLessThanOrEqual($targetMTime, $targetMTimeNotModified); }
public function testCacheBusterStrategyWorker() { $factory = $this->object->createAssetFactory($this->configuration->getModule('test_application')); // no workers by default: $this->assertAttributeEquals(array(), 'workers', $factory); $cacheBusterStrategy = $this->getMock('AsseticBundle\\CacheBuster\\LastModifiedStrategy'); $this->object->setCacheBusterStrategy($cacheBusterStrategy); $factory = $this->object->createAssetFactory($this->configuration->getModule('test_application')); // cache buster strategy is added to workers list: $this->assertAttributeEquals(array($cacheBusterStrategy), 'workers', $factory); }
/** * @inheritdoc */ public function build() { if ($this->built) { return; } $key = 'assets-manager'; if ($this->cacheAdapter->hasItem($key)) { $data = $this->cacheAdapter->getItem($key); $assetManager = unserialize($data); if ($assetManager instanceof AssetManager) { $this->setAssetManager($assetManager); return; } } parent::build(); $this->cacheAdapter->setItem($key, serialize($this->getAssetManager())); $this->built = true; }
/** * @param ServiceLocatorInterface $locator * @return \AsseticBundle\Service */ public function createService(ServiceLocatorInterface $locator) { $asseticConfig = $locator->get('AsseticConfiguration'); if ($asseticConfig->detectBaseUrl()) { /** @var $request \Zend\Http\PhpEnvironment\Request */ $request = $locator->get('Request'); if (method_exists($request, 'getBaseUrl')) { $asseticConfig->setBaseUrl($request->getBaseUrl()); } } $asseticService = new Service($asseticConfig); $asseticService->setAssetManager($locator->get('AsseticAssetManager')); $asseticService->setAssetWriter($locator->get('AsseticAssetWriter')); $asseticService->setFilterManager($locator->get('AsseticFilterManager')); // Cache buster is not mandatory if ($locator->has('AsseticCacheBuster')) { $asseticService->setCacheBusterStrategy($locator->get('AsseticCacheBuster')); } return $asseticService; }
/** * @param ContainerInterface $locator * @param string $requestedName * @param array $options, optional * * @return \AsseticBundle\Service */ public function __invoke(ContainerInterface $locator, $requestedName, array $options = null) { $asseticConfig = $locator->get('AsseticConfiguration'); if ($asseticConfig->detectBaseUrl()) { /** @var $request \Zend\Http\PhpEnvironment\Request */ $request = $locator->get('Request'); if (method_exists($request, 'getBaseUrl')) { $asseticConfig->setBaseUrl($request->getBaseUrl()); } } $asseticService = new Service($asseticConfig); $asseticService->setAssetManager($locator->get('Assetic\\AssetManager')); $asseticService->setAssetWriter($locator->get('Assetic\\AssetWriter')); $asseticService->setFilterManager($locator->get('Assetic\\FilterManager')); // Cache buster is not mandatory if ($locator->has('AsseticCacheBuster')) { $asseticService->setCacheBusterStrategy($locator->get('AsseticCacheBuster')); } return $asseticService; }