本文整理汇总了PHP中Assetic\Asset\AssetCollection::setTargetPath方法的典型用法代码示例。如果您正苦于以下问题:PHP AssetCollection::setTargetPath方法的具体用法?PHP AssetCollection::setTargetPath怎么用?PHP AssetCollection::setTargetPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Assetic\Asset\AssetCollection
的用法示例。
在下文中一共展示了AssetCollection::setTargetPath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: resolve
/**
* {@inheritDoc}
*/
public function resolve($name)
{
if (!isset($this->collections[$name])) {
return null;
}
if (!is_array($this->collections[$name])) {
throw new \RuntimeException("Collection with name {$name} is not an array.");
}
$collection = new AssetCollection();
$mimeType = 'application/javascript';
$collection->setTargetPath($name);
foreach ($this->collections[$name] as $asset) {
if (!is_string($asset)) {
throw new \RuntimeException('Asset should be of type string. got ' . gettype($asset));
}
if (null === ($content = $this->riotTag->__invoke($asset))) {
throw new \RuntimeException("Riot tag '{$asset}' could not be found.");
}
$res = new StringAsset($content);
$res->mimetype = $mimeType;
$asset .= ".js";
$this->getAssetFilterManager()->setFilters($asset, $res);
$collection->add($res);
}
$collection->mimetype = $mimeType;
return $collection;
}
示例2: createGroup
/**
* Create a new AssetCollection instance for the given group.
*
* @param string $name
* @param bool $overwrite force writing
* @return \Assetic\Asset\AssetCollection
*/
public function createGroup($name, $overwrite = false)
{
if (isset($this->groups[$name])) {
return $this->groups[$name];
}
$assets = $this->createAssetArray($name);
$filters = $this->createFilterArray($name);
$coll = new AssetCollection($assets, $filters);
if ($output = $this->getConfig($name, 'output')) {
$coll->setTargetPath($output);
}
// check output cache
$write_output = true;
if (!$overwrite) {
if (file_exists($output = public_path($coll->getTargetPath()))) {
$output_mtime = filemtime($output);
$asset_mtime = $coll->getLastModified();
if ($asset_mtime && $output_mtime >= $asset_mtime) {
$write_output = false;
}
}
}
// store assets
if ($overwrite || $write_output) {
$writer = new AssetWriter(public_path());
$writer->writeAsset($coll);
}
return $this->groups[$name] = $coll;
}
示例3: testProcess_withAssetCollection_shouldHash
public function testProcess_withAssetCollection_shouldHash()
{
$collection = new AssetCollection();
$collection->add($this->getFileAsset('asset.txt'));
$collection->add($this->getStringAsset('string', 'string.txt'));
$collection->setTargetPath('collection.txt');
$this->getCacheBustingWorker()->process($collection, $this->getAssetFactory());
$this->assertSame('collection-ae851400.txt', $collection->getTargetPath());
}
示例4: build
public function build($collection_name)
{
$build_path_setting = Config::get("assetie::build_path");
$build_directory = public_path() . DIRECTORY_SEPARATOR . $build_path_setting;
/**
* the designated name of the build, i.e. base_123.js
*/
$build_name = $collection_name . "." . $this->buildExtension;
$build_file = $build_directory . DIRECTORY_SEPARATOR . $build_name;
$buildExists = file_exists($build_file);
$build_url = URL::asset($build_path_setting . DIRECTORY_SEPARATOR . $build_name);
$debugMode = Config::get("app.debug");
if (!$buildExists || $debugMode) {
$files = \Collection::dump($collection_name)[$this->group];
$collection_hash = sha1(serialize($files));
$hash_in_cache = Cache::get("collection_" . $this->group . "_" . $collection_name);
$collectionChanged = $collection_hash != $hash_in_cache;
$src_dir = app_path() . DIRECTORY_SEPARATOR . Config::get("assetie::directories." . $this->group) . DIRECTORY_SEPARATOR;
$forceRebuild = false;
if ($collectionChanged) {
$forceRebuild = true;
} else {
if ($buildExists) {
/**
* only recompile if no compiled build exists or when in debug mode and
* build's source files or collections.php has been changed
*/
$forceRebuild = $this->checkModification($build_file, $files, $src_dir);
}
}
if (!$buildExists || $forceRebuild) {
$am = new AssetManager();
$assets = [];
foreach ($files as $file) {
$filters = $this->getFilters($file);
$assets[] = new FileAsset($src_dir . $file, $filters);
}
$collection = new AssetCollection($assets);
// , $filters
$collection->setTargetPath($build_name);
$am->set('collection', $collection);
$writer = new AssetWriter($build_directory);
$writer->writeManagerAssets($am);
}
// Cache::forever("collection_" . $collection_name, $collection_hash);
$cache_key = "collection_" . $this->group . "_" . $collection_name;
if (Cache::has($cache_key) && $collectionChanged) {
Cache::forget($cache_key);
}
if ($collectionChanged) {
Cache::put($cache_key, $collection_hash, 60);
// 1 hour
}
}
return $build_url;
}
示例5: addCollection
public function addCollection($name, $assets)
{
$collection = new AssetCollection(array_map(function ($asset) {
return new FileAsset($this->guessPath($asset['src']));
}, $assets));
$collection->setTargetPath($name);
if (endsWith($name, '.css')) {
$collection->ensureFilter(new CssRewriteFilter());
}
$this->write($name, $collection->dump());
}
示例6: addFiles
public function addFiles($type, $files, $filter = NULL)
{
if (is_null($filter)) {
$filter = $type;
}
$filter = AssetFacade::GetFilter($filter);
if (!isset($this->collections[$type])) {
$col = new AssetCollection();
$col->setTargetPath($this->path . '/' . $this->name . '.' . $type);
$this->collections[$type] = $col;
}
$collection = $this->factory->createAsset($files, $filter);
$this->collections[$type]->add($collection);
}
示例7: init
public function init()
{
$css = new AssetCollection();
$js = new AssetCollection();
$path =& $this->path;
array_walk($this->config['css'], function ($v, $i) use(&$css, $path) {
$asset = new FileAsset($path . $v, [new \Assetic\Filter\CssMinFilter()]);
$css->add($asset);
});
array_walk($this->config['js'], function ($v, $i) use(&$js, $path) {
$asset = new FileAsset($path . $v);
$js->add($asset);
});
$css->setTargetPath('/theme/' . $this->skin . '_styles.css');
$js->setTargetPath('/theme/' . $this->skin . '_scripts.js');
$this->am->set('css', $css);
$this->am->set('js', $js);
}
示例8: addToAssetManager
private function addToAssetManager($aAssets)
{
// Build asset array
foreach ($aAssets as $sName => $aAssetGroup) {
foreach ($aAssetGroup as $sType => $aFiles) {
$aCollection = array();
foreach ($aFiles as $sFile) {
$aCollection[] = new AssetCache(new FileAsset($sFile, $this->getFilters($sType)), new FilesystemCache($this->sCachePath));
}
$oCollection = new AssetCollection($aCollection);
$oCollection->setTargetPath($sName . '.' . $sType);
$this->oAssetManager->set($sName . '_' . $sType, $oCollection);
// Add to list of assets
if (!isset($this->aAssetFiles[$sType])) {
$this->aAssetFiles[$sType] = array();
}
$this->aAssetFiles[$sType][] = $this->sCacheUrl . '/' . trim($sName . '.' . $sType, '/');
}
}
}
示例9: testMultipleSameVariableValues
public function testMultipleSameVariableValues()
{
$vars = array('locale');
$asset = new FileAsset(__DIR__ . '/../Fixture/messages.{locale}.js', array(), null, null, $vars);
$coll = new AssetCollection(array($asset), array(), null, $vars);
$coll->setTargetPath('output.{locale}.js');
$coll->setValues(array('locale' => 'en'));
foreach ($coll as $asset) {
$this->assertEquals('output.{locale}_messages._1.js', $asset->getTargetPath(), 'targetPath must not contain several time the same variable');
}
}
示例10: minifyFiles
/**
* Process files from specified group(s) with Assetic library
* https://github.com/kriswallsmith/assetic
*
* @param string|int $group
*
* @return string
*/
public function minifyFiles($group)
{
$output = '';
$filenames = array();
$groupIds = array();
// Check if multiple groups are defined in group parameter
// If so, combine all the files from specified groups
$allGroups = explode(',', $group);
foreach ($allGroups as $group) {
$group = $this->getGroupId($group);
$groupIds[] = $group;
$filenames = array_merge($filenames, $this->getGroupFilenames($group));
}
// Setting group key which is used for filename and logging
if (count($groupIds) > 1) {
$group = implode('_', $groupIds);
}
if (count($filenames)) {
require_once $this->options['corePath'] . 'assetic/vendor/autoload.php';
$minifiedFiles = array();
$am = new AssetManager();
$writer = new AssetWriter($this->options['rootPath']);
$allFiles = array();
$fileDates = array();
$updatedFiles = 0;
$skipMinification = 0;
foreach ($filenames as $file) {
$filePath = $this->options['rootPath'] . $file;
$fileExt = pathinfo($filePath, PATHINFO_EXTENSION);
if (!$this->validateFile($filePath, $fileExt)) {
// no valid files found in group (non-existent or not allowed extension)
$this->log('File ' . $filePath . ' not valid.' . "\n\r", 'error');
continue;
} else {
$this->log('File ' . $filePath . ' successfully added to group.' . "\n\r");
}
$fileFilter = array();
$minifyFilter = array();
if ($fileExt == 'js') {
$minifyFilter = array(new JSMinFilter());
$filePrefix = 'scripts';
$fileSuffix = '.min.js';
} else {
// if file is .scss, use the correct filter to parse scss to css
if ($fileExt == 'scss') {
$fileFilter = array(new ScssphpFilter());
}
// if file is .less, use the correct filter to parse less to css
if ($fileExt == 'less') {
$fileFilter = array(new LessphpFilter());
}
$minifyFilter = array(new CSSUriRewriteFilter(), new MinifyCssCompressorFilter());
$filePrefix = 'styles';
$fileSuffix = '.min.css';
}
$fileDates[] = filemtime($filePath);
$allFiles[] = new FileAsset($filePath, $fileFilter);
}
// endforeach $files
if (count($fileDates) && count($allFiles)) {
sort($fileDates);
$lastEdited = end($fileDates);
$minifyFilename = $filePrefix . '-' . $group . '-' . $lastEdited . $fileSuffix;
// find the old minified files
// if necessary, remove old and generate new, based on file modification time of minified file
foreach (glob($this->options['cachePath'] . '/' . $filePrefix . '-' . $group . '-*' . $fileSuffix) as $current) {
if (filemtime($current) > $lastEdited) {
// current file is up to date
$this->log('Minified file "' . basename($current) . '" up to date. Skipping group "' . $group . '" minification.' . "\n\r");
$minifyFilename = basename($current);
$skip = 1;
} else {
unlink($current);
$this->log('Removing current file ' . $current . "\n\r");
}
}
$updatedFiles++;
$this->log("Writing " . $minifyFilename . "\n\r");
$collection = new AssetCollection($allFiles, $minifyFilter);
$collection->setTargetPath($this->options['cacheUrl'] . '/' . $minifyFilename);
$am->set($group, $collection);
if ($updatedFiles > 0 && $skip == 0) {
$writer->writeManagerAssets($am);
}
$output = $this->options['cacheUrl'] . '/' . $minifyFilename;
} else {
$this->log('No files parsed from group ' . $group . '. Check the log for more info.' . "\n\r", 'error');
}
} else {
// No files in specified group
}
return $output;
//.........这里部分代码省略.........
示例11: resolve
/**
* {@inheritDoc}
*/
public function resolve($name)
{
if (!isset($this->collections[$name])) {
return null;
}
if (!is_array($this->collections[$name])) {
throw new Exception\RuntimeException("Collection with name {$name} is not an an array.");
}
$collection = new AssetCollection();
$mimeType = null;
$collection->setTargetPath($name);
foreach ($this->collections[$name] as $asset) {
if (!is_string($asset)) {
throw new Exception\RuntimeException('Asset should be of type string. got ' . gettype($asset));
}
if (null === ($res = $this->getAggregateResolver()->resolve($asset))) {
throw new Exception\RuntimeException("Asset '{$asset}' could not be found.");
}
if (!$res instanceof AssetInterface) {
throw new Exception\RuntimeException("Asset '{$asset}' does not implement Assetic\\Asset\\AssetInterface.");
}
if (null !== $mimeType && $res->mimetype !== $mimeType) {
throw new Exception\RuntimeException(sprintf('Asset "%s" from collection "%s" doesn\'t have the expected mime-type "%s".', $asset, $name, $mimeType));
}
$mimeType = $res->mimetype;
$this->getAssetFilterManager()->setFilters($asset, $res);
$collection->add($res);
}
$collection->mimetype = $mimeType;
return $collection;
}
示例12: computeAsset
public function computeAsset($relative_path, $name = null)
{
$paths = is_array($relative_path) ? $relative_path : array($relative_path);
if (count($paths) > 1 && null === $name) {
throw new Exception('You have to define a name for asset collection');
}
$am = new LazyAssetManager(new AssetFactory(''));
$assets = array();
$asset_collection = new AssetCollection();
if ($this->settings['modes'] & Modes::CONCAT) {
$assets[] = $asset_collection;
}
foreach ($paths as $p) {
$file = $this->loader->fromAppPath($p);
$asset = $file->asset(['compass' => $this->settings['modes'] & Modes::COMPASS]);
$ext = str_replace(array('sass', 'scss'), 'css', File::getExt($p));
$filename = substr($p, 0, strrpos($p, '.'));
if ($this->settings['modes'] & Modes::CONCAT) {
$asset_collection->add($asset);
if (null === $name) {
$name = $filename . $ext;
}
$asset_collection->setTargetPath($name);
} else {
$asset->setTargetPath($filename . $ext);
$assets[] = $asset;
}
}
foreach ($assets as $asset) {
// add the timestamp
$target_path = explode('/', $asset->getTargetPath());
$file_name = array_pop($target_path);
$target_path[] = $am->getLastModified($asset) . '-' . $file_name;
$web_path = implode('/', $target_path);
$asset->setTargetPath($web_path);
if (!file_exists($this->settings['public_path'] . '/' . $this->settings['compiled_dir'] . '/' . $asset->getTargetPath())) {
if ($this->settings['modes'] & Modes::MINIFY) {
switch ($ext) {
case '.css':
$asset->ensureFilter(new \Assetic\Filter\CssMinFilter());
break;
case '.js':
$asset->ensureFilter(new \Assetic\Filter\JSMinFilter());
break;
}
}
$writer = new AssetWriter($this->settings['public_path'] . '/' . $this->settings['compiled_dir']);
$writer->writeAsset($asset);
}
}
return $assets[0];
}
示例13: generateCssAsset
/**
* generates a single css asset file from an array of css files if at least one of them has changed
* otherwise it just returns the path to the old asset file
* @param $files
* @return string
*/
private function generateCssAsset($files)
{
$assetDir = \OC::$server->getConfig()->getSystemValue('assetdirectory', \OC::$SERVERROOT);
$hash = self::hashFileNames($files);
if (!file_exists("{$assetDir}/assets/{$hash}.css")) {
$files = array_map(function ($item) {
$root = $item[0];
$file = $item[2];
$assetPath = $root . '/' . $file;
$sourceRoot = \OC::$SERVERROOT;
$sourcePath = substr($assetPath, strlen(\OC::$SERVERROOT));
return new FileAsset($assetPath, array(new CssRewriteFilter(), new CssMinFilter(), new CssImportFilter()), $sourceRoot, $sourcePath);
}, $files);
$cssCollection = new AssetCollection($files);
$cssCollection->setTargetPath("assets/{$hash}.css");
$writer = new AssetWriter($assetDir);
$writer->writeAsset($cssCollection);
}
return \OC::$server->getURLGenerator()->linkTo('assets', "{$hash}.css");
}
示例14: generateAssets
public function generateAssets()
{
$jsFiles = self::findJavascriptFiles(OC_Util::$scripts);
$jsHash = self::hashScriptNames($jsFiles);
if (!file_exists("assets/{$jsHash}.js")) {
$jsFiles = array_map(function ($item) {
$root = $item[0];
$file = $item[2];
return new FileAsset($root . '/' . $file, array(), $root, $file);
}, $jsFiles);
$jsCollection = new AssetCollection($jsFiles);
$jsCollection->setTargetPath("assets/{$jsHash}.js");
$writer = new AssetWriter(\OC::$SERVERROOT);
$writer->writeAsset($jsCollection);
}
$cssFiles = self::findStylesheetFiles(OC_Util::$styles);
$cssHash = self::hashScriptNames($cssFiles);
if (!file_exists("assets/{$cssHash}.css")) {
$cssFiles = array_map(function ($item) {
$root = $item[0];
$file = $item[2];
$assetPath = $root . '/' . $file;
$sourceRoot = \OC::$SERVERROOT;
$sourcePath = substr($assetPath, strlen(\OC::$SERVERROOT));
return new FileAsset($assetPath, array(new CssRewriteFilter()), $sourceRoot, $sourcePath);
}, $cssFiles);
$cssCollection = new AssetCollection($cssFiles);
$cssCollection->setTargetPath("assets/{$cssHash}.css");
$writer = new AssetWriter(\OC::$SERVERROOT);
$writer->writeAsset($cssCollection);
}
$this->append('jsfiles', OC_Helper::linkTo('assets', "{$jsHash}.js"));
$this->append('cssfiles', OC_Helper::linkTo('assets', "{$cssHash}.css"));
}
示例15: generate
//.........这里部分代码省略.........
//Get Default group ?
$constraintsTarget = $constraintsTarget[0]->fields;
}
}
if (!empty($constraintsTarget)) {
// we look through each field of the form
foreach ($formView->children as $formField) {
$names = array();
$names[] = $formField;
if (!empty($formField->children)) {
foreach ($formField->children as $nextLevelChildren) {
$names[] = $nextLevelChildren;
}
}
foreach ($names as $formFieldN) {
/* @var $formField \Symfony\Component\Form\FormView */
// Fields with property_path=false must be excluded from validation
if (isset($formFieldN->vars['property_path']) && $formFieldN->vars['property_path'] === false) {
continue;
}
//Setting "property_path" to "false" is deprecated since version 2.1 and will be removed in 2.3.
//Set "mapped" to "false" instead
if (isset($formFieldN->vars['mapped']) && $formFieldN->vars['mapped'] === false) {
continue;
}
// we look for constraints for the field
if (!isset($constraintsTarget[$formFieldN->vars['name']])) {
continue;
}
$constraintList = isset($entityName) ? $constraintsTarget[$formFieldN->vars['name']]->getConstraints() : $constraintsTarget[$formFieldN->vars['name']]->constraints;
//Adds entity level constraints that have been provided for this field
if (!empty($aConstraints[$formFieldN->vars['name']])) {
$constraintList = array_merge($constraintList, $aConstraints[$formFieldN->vars['name']]);
}
// we look through each field constraint
foreach ($constraintList as $constraint) {
$constraintName = end(explode(chr(92), get_class($constraint)));
$constraintProperties = get_object_vars($constraint);
// Groups are no longer needed
unset($constraintProperties['groups']);
if (!$fieldsConstraints->hasLibrary($constraintName)) {
$librairy = "APYJsFormValidationBundle:Constraints:{$constraintName}Validator.js.twig";
$fieldsConstraints->addLibrary($constraintName, $librairy);
}
$constraintParameters = array();
//We need to know entity class for the field which is applied by UniqueEntity constraint
if ($constraintName == 'UniqueEntity' && !empty($formFieldN->parent)) {
$entity = isset($formFieldN->parent->vars['value']) ? $formFieldN->parent->vars['value'] : null;
if (isset($formView->children[$this->getParameter('identifier_field')])) {
$id = json_encode($formView->children[$this->getParameter('identifier_field')]->vars['id']);
} else {
$id = json_encode($formFieldN->vars['id']);
}
$constraintParameters += array('entity:' . json_encode(get_class($entity)), 'identifier_field_id:' . $id);
}
foreach ($constraintProperties as $variable => $value) {
if (is_array($value)) {
$value = json_encode($value);
} else {
// regex
if (stristr('pattern', $variable) === false) {
$value = json_encode($value);
}
}
$constraintParameters[] = "{$variable}:{$value}";
}
$fieldsConstraints->addFieldConstraint($formFieldN->vars['id'], array('name' => $constraintName, 'parameters' => '{' . join(', ', $constraintParameters) . '}'));
}
}
}
}
// Dispatch JsfvEvents::postProcess event
$postProcessEvent = new PostProcessEvent($formView, $fieldsConstraints);
$dispatcher->dispatch(JsfvEvents::postProcess, $postProcessEvent);
// Retrieve validation mode from configuration
$check_modes = array('submit' => false, 'blur' => false, 'change' => false);
foreach ($this->container->getParameter('apy_js_form_validation.check_modes') as $check_mode) {
$check_modes[$check_mode] = true;
}
// Render the validation script
$validation_bundle = $this->getValidationBundle();
$javascript_framework = strtolower($this->container->getParameter('apy_js_form_validation.javascript_framework'));
$dataTemplate = array('formName' => $formName, 'fieldConstraints' => $fieldsConstraints->getFieldsConstraints(), 'librairyCalls' => $fieldsConstraints->getLibraries(), 'check_modes' => $check_modes, 'getterHandlers' => $gettersLibraries->all(), 'gettersConstraints' => $aGetters, 'translation_group' => $this->container->getParameter('apy_js_form_validation.translation_group'));
$template = $this->container->get('templating')->render("{$validation_bundle}:Frameworks:JsFormValidation.js.{$javascript_framework}.twig", $dataTemplate);
// Create asset and compress it
$asset = new AssetCollection();
$asset->setContent($template);
$asset->setTargetPath($scriptRealPath . $scriptFile);
// Js compression
if ($this->container->getParameter('apy_js_form_validation.yui_js')) {
$yui = new JsCompressorFilter($this->container->getParameter('assetic.filter.yui_js.jar'), $this->container->getParameter('assetic.java.bin'));
$yui->filterDump($asset);
}
$this->container->get('filesystem')->mkdir($scriptRealPath);
if (false === @file_put_contents($asset->getTargetPath(), $asset->getContent())) {
throw new \RuntimeException('Unable to write file ' . $asset->getTargetPath());
}
}
return $this->container->get('templating.helper.assets')->getUrl($scriptPath . $scriptFile);
}