本文整理汇总了PHP中Assetic\Asset\AssetInterface::getVars方法的典型用法代码示例。如果您正苦于以下问题:PHP AssetInterface::getVars方法的具体用法?PHP AssetInterface::getVars怎么用?PHP AssetInterface::getVars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Assetic\Asset\AssetInterface
的用法示例。
在下文中一共展示了AssetInterface::getVars方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doDump
/**
* Performs the asset dump.
*
* @param AssetInterface $asset An asset
* @param OutputInterface $stdout The command output
*
* @throws RuntimeException If there is a problem writing the asset
*/
private function doDump(AssetInterface $asset, OutputInterface $stdout)
{
$combinations = VarUtils::getCombinations($asset->getVars(), $this->getContainer()->getParameter('assetic.variables'));
foreach ($combinations as $combination) {
$asset->setValues($combination);
// resolve the target path
$target = rtrim($this->basePath, '/') . '/' . $asset->getTargetPath();
$target = str_replace('_controller/', '', $target);
$target = VarUtils::resolve($target, $asset->getVars(), $asset->getValues());
if (!is_dir($dir = dirname($target))) {
$stdout->writeln(sprintf('<comment>%s</comment> <info>[dir+]</info> %s', date('H:i:s'), $dir));
if (false === @mkdir($dir, 0777, true)) {
throw new \RuntimeException('Unable to create directory ' . $dir);
}
}
$stdout->writeln(sprintf('<comment>%s</comment> <info>[file+]</info> %s', date('H:i:s'), $target));
if (OutputInterface::VERBOSITY_VERBOSE <= $stdout->getVerbosity()) {
if ($asset instanceof AssetCollectionInterface) {
foreach ($asset as $leaf) {
$root = $leaf->getSourceRoot();
$path = $leaf->getSourcePath();
$stdout->writeln(sprintf(' <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
}
} else {
$root = $asset->getSourceRoot();
$path = $asset->getSourcePath();
$stdout->writeln(sprintf(' <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
}
}
if (false === @file_put_contents($target, $asset->dump())) {
throw new \RuntimeException('Unable to write file ' . $target);
}
}
}
示例2: writeAsset
public function writeAsset(AssetInterface $asset)
{
foreach ($this->getCombinations($asset->getVars()) as $combination) {
$asset->setValues($combination);
static::write($this->dir . '/' . PathUtils::resolvePath($asset->getTargetPath(), $asset->getVars(), $asset->getValues()), $asset->dump());
}
}
示例3: writeAsset
public function writeAsset(AssetInterface $asset)
{
foreach (VarUtils::getCombinations($asset->getVars(), $this->values) as $combination) {
$asset->setValues($combination);
$path = $this->dir . '/' . VarUtils::resolve($asset->getTargetPath(), $asset->getVars(), $asset->getValues());
if (!is_dir($path) && (!file_exists($path) || filemtime($path) <= $asset->getLastModified())) {
static::write($path, $asset->dump());
}
}
}
示例4: writeAsset
public function writeAsset(AssetInterface $asset)
{
foreach (VarUtils::getCombinations($asset->getVars(), $this->values) as $combination) {
$asset->setValues($combination);
$path = $this->dir . '/' . VarUtils::resolve($asset->getTargetPath(), $asset->getVars(), $asset->getValues());
if ($this->force || !file_exists($path) || $this->factory->getLastModified($asset) > filemtime($path)) {
$this->log('Writing: ' . $path);
if (!$this->dryRun) {
static::write($path, $asset->combineThenDump());
}
} else {
$this->log('Skipping: ' . $path);
}
}
}
示例5: dump
public function dump(AssetInterface $asset)
{
$writer = new \Assetic\AssetWriter(sys_get_temp_dir(), $this->container->getParameter('assetic.variables'));
$ref = new \ReflectionMethod($writer, 'getCombinations');
$ref->setAccessible(true);
$name = $asset->getSourcePath();
$type = substr($name, strrpos($name, '.') + 1);
switch ($type) {
case 'coffee':
$asset->ensureFilter($this->container->get('assetic.filter.coffee'));
$type = 'js';
break;
case 'less':
$asset->ensureFilter($this->container->get('assetic.filter.less'));
$type = 'css';
break;
}
$combinations = $ref->invoke($writer, $asset->getVars());
$asset->setValues($combinations[0]);
$asset->load();
$content = $asset->getContent();
// because the assetic cssrewrite makes bullshit here, we need to reimplement the filter
if ($type === 'css') {
$content = $this->cssFilter($content, '/' . dirname($asset->getSourcePath()));
}
return $content;
}
示例6: compileAssetUrl
protected function compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset, $name)
{
$vars = array();
foreach ($asset->getVars() as $var) {
$vars[] = new \Twig_Node_Expression_Constant($var, $this->getLine());
// Retrieves values of assetic vars from the context, $context['assetic']['vars'][$var].
$vars[] = new \Twig_Node_Expression_GetAttr(new \Twig_Node_Expression_GetAttr(new \Twig_Node_Expression_Name('assetic', $this->getLine()), new \Twig_Node_Expression_Constant('vars', $this->getLine()), new \Twig_Node_Expression_Array(array(), $this->getLine()), \Twig_Template::ARRAY_CALL, $this->getLine()), new \Twig_Node_Expression_Constant($var, $this->getLine()), new \Twig_Node_Expression_Array(array(), $this->getLine()), \Twig_Template::ARRAY_CALL, $this->getLine());
}
$compiler->raw('isset($context[\'assetic\'][\'use_controller\']) && $context[\'assetic\'][\'use_controller\'] ? ')->subcompile($this->getPathFunction($name, $vars))->raw(' : ')->subcompile($this->getAssetFunction(new TargetPathNode($this, $asset, $name)));
}
示例7: cachifyAsset
protected function cachifyAsset(AssetInterface $asset)
{
if ($vars = $asset->getVars()) {
if (null === $this->valueSupplier) {
throw new \RuntimeException(sprintf('You must configure a value supplier if you have assets with variables.'));
}
$asset->setValues(array_intersect_key($this->valueSupplier->getValues(), array_flip($vars)));
}
return new AssetCache($asset, $this->cache);
}
示例8: doDump
private function doDump(AssetInterface $asset, $documentRoot)
{
$writer = new AssetWriter(sys_get_temp_dir(), $this->container->getParameter('assetic.variables'));
$ref = new \ReflectionMethod($writer, 'getCombinations');
$ref->setAccessible(true);
$combinations = $ref->invoke($writer, $asset->getVars());
foreach ($combinations as $combination) {
$asset->setValues($combination);
$target = rtrim($documentRoot, '/') . '/' . str_replace('_controller/', '', PathUtils::resolvePath($asset->getTargetPath(), $asset->getVars(), $asset->getValues()));
if (!is_dir($dir = dirname($target))) {
if (false === @mkdir($dir, 0777, true)) {
throw new \RuntimeException('Unable to create directory ' . $dir);
}
}
if (false === @file_put_contents($target, $asset->dump())) {
throw new \RuntimeException('Unable to write file ' . $target);
}
}
}
示例9: compileAssetUrl
protected function compileAssetUrl(\Twig_Compiler $compiler, AssetInterface $asset, $name)
{
if (!($vars = $asset->getVars())) {
$compiler->repr($asset->getTargetPath());
return;
}
$compiler->raw("strtr(")->string($asset->getTargetPath())->raw(", array(");
$first = true;
foreach ($vars as $var) {
if (!$first) {
$compiler->raw(", ");
}
$first = false;
$compiler->string("{" . $var . "}")->raw(" => \$context['assetic']['vars']['{$var}']");
}
$compiler->raw("))");
}
示例10: configureAssetValues
protected function configureAssetValues(AssetInterface $asset, Request $request)
{
if ($vars = $asset->getVars()) {
$asset->setValues(array_intersect_key($request->attributes->all(), array_flip($vars)));
}
return $this;
}
示例11: getAssetVarCombinations
private function getAssetVarCombinations(AssetInterface $asset)
{
return VarUtils::getCombinations($asset->getVars(), $this->getContainer()->getParameter('assetic.variables'));
}
示例12: doDump
/**
* Performs the asset dump.
*
* @param AssetInterface $asset An asset
* @param OutputInterface $output The command output
*
* @throws RuntimeException If there is a problem writing the asset
*/
private function doDump(AssetInterface $asset, OutputInterface $output)
{
$writer = new AssetWriter(sys_get_temp_dir(), $this->getContainer()->getParameter('assetic.variables'));
$ref = new \ReflectionMethod($writer, 'getCombinations');
$ref->setAccessible(true);
$combinations = $ref->invoke($writer, $asset->getVars());
foreach ($combinations as $combination) {
$asset->setValues($combination);
$target = rtrim($this->basePath, '/') . '/' . str_replace('_controller/', '', PathUtils::resolvePath($asset->getTargetPath(), $asset->getVars(), $asset->getValues()));
if (!is_dir($dir = dirname($target))) {
$output->writeln(sprintf('<comment>%s</comment> <info>[dir+]</info> %s', date('H:i:s'), $dir));
if (false === @mkdir($dir, 0777, true)) {
throw new \RuntimeException('Unable to create directory ' . $dir);
}
}
$output->writeln(sprintf('<comment>%s</comment> <info>[file+]</info> %s', date('H:i:s'), $target));
if ($this->verbose) {
if ($asset instanceof \Traversable) {
foreach ($asset as $leaf) {
$root = $leaf->getSourceRoot();
$path = $leaf->getSourcePath();
$output->writeln(sprintf(' <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
}
} else {
$root = $asset->getSourceRoot();
$path = $asset->getSourcePath();
$output->writeln(sprintf(' <comment>%s/%s</comment>', $root ?: '[unknown root]', $path ?: '[unknown path]'));
}
}
if (false === @file_put_contents($target, $asset->dump())) {
throw new \RuntimeException('Unable to write file ' . $target);
}
}
}
示例13: getGulpConfig
/**
* Performs the asset dump.
*
* @param AssetInterface $asset An asset
* @param OutputInterface $stdout The command output
* @return array
*/
private function getGulpConfig(AssetInterface $asset, OutputInterface $stdout)
{
$combinations = VarUtils::getCombinations($asset->getVars(), $this->getContainer()->getParameter('assetic.variables'));
// see http://stackoverflow.com/questions/30133597/is-there-a-way-to-merge-less-with-css-in-gulp
// for a method of merging css and less
$assets = [];
foreach ($combinations as $combination) {
$asset->setValues($combination);
// resolve the target path
$target = rtrim($this->basePath, '/') . '/' . $asset->getTargetPath();
$target = str_replace('_controller/', '', $target);
$target = VarUtils::resolve($target, $asset->getVars(), $asset->getValues());
if (!is_dir($dir = dirname($target))) {
$stdout->writeln(sprintf('<comment>%s</comment> <info>[dir+]</info> %s', date('H:i:s'), $dir));
if (false === @mkdir($dir, 0777, true) && !is_dir($dir)) {
throw new \RuntimeException('Unable to create directory ' . $dir);
}
}
$stdout->writeln(sprintf('<comment>%s</comment> <info>[file+]</info> %s', date('H:i:s'), $target));
$gulpAsset = new GulpAsset();
$gulpAsset->setDestination($target);
$asset = $this->resolveAsset($asset);
$this->gulpAsset($gulpAsset, $asset, $stdout);
$assets[] = $gulpAsset->getArrayConfig();
}
return $assets;
}
示例14: loadRouteForAsset
/**
* Loads a route to serve an supplied asset.
*
* The fake front controller that {@link UseControllerWorker} adds to the
* target URL will be removed before set as a route pattern.
*
* @param RouteCollection $routes The route collection
* @param AssetInterface $asset The asset
* @param string $name The name to use
* @param integer $pos The leaf index
*/
private function loadRouteForAsset(RouteCollection $routes, AssetInterface $asset, $name, $pos = null)
{
$defaults = array('_controller' => 'assetic.controller:render', 'name' => $name, 'pos' => $pos);
$requirements = array();
// remove the fake front controller
$pattern = str_replace('_controller/', '', $asset->getTargetPath());
if ($format = pathinfo($pattern, PATHINFO_EXTENSION)) {
$defaults['_format'] = $format;
}
$route = '_assetic_' . $name;
if (null !== $pos) {
$route .= '_' . $pos;
}
foreach ($asset->getVars() as $var) {
if (empty($this->varValues[$var])) {
throw new \UnexpectedValueException(sprintf('The possible values for the asset variable "%s" are not known', $var));
}
$values = array();
foreach ($this->varValues[$var] as $value) {
$values[] = preg_quote($value, '#');
}
$requirements[$var] = implode('|', $values);
}
$routes->add($route, new Route($pattern, $defaults, $requirements));
}
示例15: getVars
/**
* Returns an array of variable names for this asset.
*
* @return array
*/
public function getVars()
{
return $this->asset->getVars();
}