Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Allow inheritance from app resource folder #134

Open
wants to merge 17 commits into from

2 participants

jandevani Christophe Coevoet
jandevani

Set location to extend with app resource folder to be able to support inheritance equal to templates, only globs are still an issue here, any ideas?

jandevani jandevani Update Factory/AssetFactory.php
Set location to extend with app resource folder to be able to support inheritance equal to templates, only globs are still an issue here, any ideas?
9cf7472
Christophe Coevoet
Collaborator

This is simply broken for globs (you have to overwrite all files as soon as your folder is matched in app/Resources) so it cannot be merged as is.

Factory/AssetFactory.php
@@ -68,9 +68,9 @@ protected function parseInput($input, array $options = array())
if (false !== $pos = strpos($input, '*')) {
// locateResource() does not support globs so we provide a naive implementation here
list($before, $after) = explode('*', $input, 2);
- $input = $this->kernel->locateResource($before).'*'.$after;
+ $input = $this->kernel->locateResource($before,$this->container->getParameter('kernel.root_dir').'/Resources').'*'.$after;
} else {
Christophe Coevoet Collaborator
stof added a note

missing space after the comma

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 9, 2012
  1. jandevani

    Update Factory/AssetFactory.php

    jandevani authored
    Set location to extend with app resource folder to be able to support inheritance equal to templates, only globs are still an issue here, any ideas?
Commits on Nov 10, 2012
  1. jandevani

    Update Factory/AssetFactory.php

    jandevani authored
    Improved support for globs
Commits on Nov 11, 2012
  1. jandevani
Commits on Oct 16, 2014
  1. jandevani

    Update Factory/AssetFactory.php

    jandevani authored
    Set location to extend with app resource folder to be able to support inheritance equal to templates, only globs are still an issue here, any ideas?
  2. jandevani

    Update Factory/AssetFactory.php

    jandevani authored
    Improved support for globs
  3. jandevani
  4. jandevani
  5. jandevani
  6. jandevani

    Fixed failing test by adding mock with =false and returnvalue of arra…

    jandevani authored
    …y as described in KernelInterface
Commits on Dec 30, 2014
  1. jandevani

    Update Factory/AssetFactory.php

    jandevani authored
    Set location to extend with app resource folder to be able to support inheritance equal to templates, only globs are still an issue here, any ideas?
  2. jandevani

    Update Factory/AssetFactory.php

    jandevani authored
    Improved support for globs
  3. jandevani
  4. jandevani

    Fixed merge conflict

    jandevani authored
  5. jandevani
  6. jandevani

    Fixed failing test by adding mock with =false and returnvalue of arra…

    jandevani authored
    …y as described in KernelInterface
  7. jandevani

    Merge branch 'master' of https://github.com/jandevani/AsseticBundle

    jandevani authored
    Conflicts:
    	Factory/AssetFactory.php
Commits on Jan 26, 2015
  1. jandevani
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 3 deletions.
  1. +23 −3 Factory/AssetFactory.php
  2. +4 −0 Tests/Factory/AssetFactoryTest.php
26 Factory/AssetFactory.php
View
@@ -15,6 +15,7 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpKernel\KernelInterface;
+use Assetic\Asset\AssetCollection;
/**
* Loads asset formulae from the filesystem.
@@ -65,12 +66,31 @@ protected function parseInput($input, array $options = array())
$options['root'] = array($this->kernel->getBundle($bundle)->getPath());
// canonicalize the input
- if (false !== $pos = strpos($input, '*')) {
+ if (false !== strpos($input, '*')) {
// locateResource() does not support globs so we provide a naive implementation here
list($before, $after) = explode('*', $input, 2);
- $input = $this->kernel->locateResource($before).'*'.$after;
+ // support globs like /path/to/bootstrap/js/bootstrap-*.js
+ if (false !== $pos = strrpos($before, '/')) {
+ $pos++;
+ $after = substr($before, $pos).'*'.$after;
+ $before = substr($before, 0, $pos);
+ } else {
+ $after = '*'.$after;
+ }
+ // retrieve all related folders for current bundle notation
+ $globAssetFolders = $this->kernel->locateResource($before, $this->container->getParameter('kernel.root_dir').'/Resources', false);
+ if (count($globAssetFolders) == 1) {
+ $input = $globAssetFolders[0].$after;
+ } else {
+ $collection = new AssetCollection();
+ foreach ($globAssetFolders as $globAssetFolder) {
+ $input = $globAssetFolder.$after;
+ $collection->add(parent::parseInput($input, $options));
+ }
+ return $collection;
+ }
} else {
- $input = $this->kernel->locateResource($input);
+ $input = $this->kernel->locateResource($input, $this->container->getParameter('kernel.root_dir').'/Resources');
}
}
4 Tests/Factory/AssetFactoryTest.php
View
@@ -74,6 +74,10 @@ public function testBundleGlobNotation($input)
->will($this->returnValue($bundle));
$this->kernel->expects($this->once())
->method('locateResource')
+ ->with('@MyBundle/Resources/css/', $this->anything(), false)
+ ->will($this->returnValue(array('/path/to/MyBundle/Resources/css/')));
+ $this->kernel->expects($this->once())
+ ->method('locateResource')
->with('@MyBundle/Resources/css/')
->will($this->returnValue('/path/to/MyBundle/Resources/css/'));
$bundle->expects($this->once())
Something went wrong with that request. Please try again.