From edd4f2510e61f0a9a83df66a23b2652b9c5e8979 Mon Sep 17 00:00:00 2001 From: Leny BERNARD Date: Mon, 3 Oct 2016 16:16:23 +0200 Subject: [PATCH] Move to Troopers org (#9) --- AssetsCollector/Collector.php | 17 ++++--- AssetsCollector/RequireAll.php | 9 ++-- AvAsseticInjectorBundle.php | 9 ---- DependencyInjection/Configuration.php | 8 ++-- ...p => TroopersAsseticInjectorExtension.php} | 12 ++--- LICENSE.md | 2 +- README.md | 8 ++-- Resources/config/services.yml | 16 +++---- Tests/Controller/DefaultControllerTest.php | 17 ------- TroopersAsseticInjectorBundle.php | 9 ++++ Twig/AsseticExtension.php | 24 +++++----- Twig/AsseticInjectorTokenParser.php | 44 +++++++++---------- composer.json | 13 +++--- 13 files changed, 83 insertions(+), 105 deletions(-) delete mode 100644 AvAsseticInjectorBundle.php rename DependencyInjection/{AvAsseticInjectorExtension.php => TroopersAsseticInjectorExtension.php} (83%) delete mode 100644 Tests/Controller/DefaultControllerTest.php create mode 100644 TroopersAsseticInjectorBundle.php diff --git a/AssetsCollector/Collector.php b/AssetsCollector/Collector.php index 45abc9f..e8d39b3 100644 --- a/AssetsCollector/Collector.php +++ b/AssetsCollector/Collector.php @@ -1,17 +1,18 @@ + * @author Paul Andrieux */ class Collector { /** - * Constructor + * Constructor. * * @param Container $container The container */ @@ -21,7 +22,7 @@ public function __construct($container) } /** - * Inject the assets + * Inject the assets. * * @param \Twig_TokenParser $parser */ @@ -31,7 +32,7 @@ public function injectAssets(\Twig_TokenParser $parser) } /** - * Get the assets for each bundle + * Get the assets for each bundle. * * @return multitype: */ @@ -42,7 +43,7 @@ public function getAssets() $rootDir = $this->container->get('kernel')->getRootDir(); $appOverrideDir = '/Resources'; - $resources = array(); + $resources = []; $finder = new Finder(); $finder->files()->name('assetic_injector.json'); foreach ($this->container->get('kernel')->getBundles() as $bundle) { @@ -66,9 +67,8 @@ public function getAssets() $finder->in($bundle->getPath().'/Resources/config/'); } } - } - $injectArray = array(); + $injectArray = []; foreach ($finder as $file) { $json = file_get_contents($file); if (is_array(json_decode($json, true))) { @@ -77,7 +77,6 @@ public function getAssets() } foreach ($injectArray as $engine => $assets) { - $engine = $this->container->get('assetic_injector.'.$engine); $engine->compute($assets); $resources = array_merge_recursive($resources, $engine->getResources()); diff --git a/AssetsCollector/RequireAll.php b/AssetsCollector/RequireAll.php index 1707a14..6a80aea 100644 --- a/AssetsCollector/RequireAll.php +++ b/AssetsCollector/RequireAll.php @@ -1,14 +1,15 @@ $resource) { - foreach($resource as $k => $path) { + foreach ($item as $type => $resource) { + foreach ($resource as $k => $path) { $this->resources[$type][$k] = $path; } } diff --git a/AvAsseticInjectorBundle.php b/AvAsseticInjectorBundle.php deleted file mode 100644 index de7a258..0000000 --- a/AvAsseticInjectorBundle.php +++ /dev/null @@ -1,9 +0,0 @@ -root('av_assetic_injector'); + $treeBuilder->root('troopers_assetic_injector'); // Here you should define the parameters that are allowed to // configure your bundle. See the documentation linked above for diff --git a/DependencyInjection/AvAsseticInjectorExtension.php b/DependencyInjection/TroopersAsseticInjectorExtension.php similarity index 83% rename from DependencyInjection/AvAsseticInjectorExtension.php rename to DependencyInjection/TroopersAsseticInjectorExtension.php index 2aec0f7..579d49c 100644 --- a/DependencyInjection/AvAsseticInjectorExtension.php +++ b/DependencyInjection/TroopersAsseticInjectorExtension.php @@ -1,21 +1,21 @@ request('GET', '/hello/Fabien'); - - $this->assertTrue($crawler->filter('html:contains("Hello Fabien")')->count() > 0); - } -} diff --git a/TroopersAsseticInjectorBundle.php b/TroopersAsseticInjectorBundle.php new file mode 100644 index 0000000..fe4a630 --- /dev/null +++ b/TroopersAsseticInjectorBundle.php @@ -0,0 +1,9 @@ + - * @author Paul Andrieux + * @author Leny Bernard + * @author Paul Andrieux */ class AsseticExtension extends BaseAsseticExtension implements \Twig_Extension_GlobalsInterface { @@ -31,7 +30,7 @@ class AsseticExtension extends BaseAsseticExtension implements \Twig_Extension_G private $enabledBundles; private $collector; - public function __construct(AssetFactory $factory, TemplateNameParserInterface $templateNameParser, $useController = false, $functions = array(), $enabledBundles = array(), ValueSupplierInterface $valueSupplier = null) + public function __construct(AssetFactory $factory, TemplateNameParserInterface $templateNameParser, $useController = false, $functions = [], $enabledBundles = [], ValueSupplierInterface $valueSupplier = null) { parent::__construct($factory, $functions, $valueSupplier); @@ -44,20 +43,21 @@ public function setCollector($collector) { $this->collector = $collector; } + public function getTokenParsers() { - return array( + return [ $this->createTokenParser('javascripts', 'js/*.js'), $this->createTokenParser('stylesheets', 'css/*.css'), $this->createTokenParser('image', 'images/*', true), - ); + ]; } public function getNodeVisitors() { - return array( + return [ new AsseticNodeVisitor($this->templateNameParser, $this->enabledBundles), - ); + ]; } public function getGlobals() @@ -70,8 +70,8 @@ public function getGlobals() private function createTokenParser($tag, $output, $single = false) { - $tokenParser = new AsseticInjectorTokenParser($this->factory, $tag, $output, $single, array('package')); - if (in_array($tag, array("stylesheets", "javascripts"))) { + $tokenParser = new AsseticInjectorTokenParser($this->factory, $tag, $output, $single, ['package']); + if (in_array($tag, ['stylesheets', 'javascripts'])) { $this->collector->injectAssets($tokenParser); } $tokenParser->setTemplateNameParser($this->templateNameParser); diff --git a/Twig/AsseticInjectorTokenParser.php b/Twig/AsseticInjectorTokenParser.php index 2f5959f..d8f0e4f 100644 --- a/Twig/AsseticInjectorTokenParser.php +++ b/Twig/AsseticInjectorTokenParser.php @@ -9,19 +9,17 @@ * with this source code in the file LICENSE. */ -namespace AppVentus\AsseticInjectorBundle\Twig; +namespace Troopers\AsseticInjectorBundle\Twig; use Assetic\Asset\AssetInterface; -use Symfony\Bundle\AsseticBundle\Twig\AsseticTokenParser as BaseAsseticTokenParser; use Symfony\Bundle\AsseticBundle\Exception\InvalidBundleException; -use Symfony\Component\Templating\TemplateNameParserInterface; use Symfony\Bundle\AsseticBundle\Factory\AssetFactory; use Symfony\Bundle\AsseticBundle\Twig\AsseticNode; +use Symfony\Bundle\AsseticBundle\Twig\AsseticTokenParser as BaseAsseticTokenParser; +use Symfony\Component\Templating\TemplateNameParserInterface; /** * Assetic token parser. - * - * @author Kris Wallsmith */ class AsseticInjectorTokenParser extends BaseAsseticTokenParser { @@ -29,15 +27,14 @@ class AsseticInjectorTokenParser extends BaseAsseticTokenParser private $enabledBundles; private $injectedAssets; - public function __construct(AssetFactory $factory, $tag, $output, $single = false, array $extensions = array()) + public function __construct(AssetFactory $factory, $tag, $output, $single = false, array $extensions = []) { - - $this->factory = $factory; - $this->tag = $tag; - $this->output = $output; - $this->single = $single; + $this->factory = $factory; + $this->tag = $tag; + $this->output = $output; + $this->single = $single; $this->extensions = $extensions; - $this->injectedAssets = array(); + $this->injectedAssets = []; parent::__construct($factory, $tag, $output, $single, $extensions); } @@ -46,6 +43,7 @@ public function addAssets($assets) { $this->injectedAssets = $assets; } + public function setTemplateNameParser(TemplateNameParserInterface $templateNameParser) { $this->templateNameParser = $templateNameParser; @@ -83,14 +81,14 @@ public function parse(\Twig_Token $token) return $this->parseAndInject($token); } - protected function createNode(AssetInterface $asset, \Twig_NodeInterface $body, array $inputs, array $filters, $name, array $attributes = array(), $lineno = 0, $tag = null) + protected function createNode(AssetInterface $asset, \Twig_NodeInterface $body, array $inputs, array $filters, $name, array $attributes = [], $lineno = 0, $tag = null) { return new AsseticNode($asset, $body, $inputs, $filters, $name, $attributes, $lineno, $tag); } public function parseAndInject(\Twig_Token $token) { - $inputs = $filters = $injectorLocationsAvailables = array(); + $inputs = $filters = $injectorLocationsAvailables = []; $name = $injectorLocation = null; foreach ($this->injectedAssets as $tag => $assets) { @@ -99,11 +97,11 @@ public function parseAndInject(\Twig_Token $token) } } - $attributes = array( + $attributes = [ 'output' => $this->output, 'var_name' => 'asset_url', - 'vars' => array(), - ); + 'vars' => [], + ]; $stream = $this->parser->getStream(); while (!$stream->test(\Twig_Token::BLOCK_END_TYPE)) { @@ -139,12 +137,12 @@ public function parseAndInject(\Twig_Token $token) // debug=true $stream->next(); $stream->expect(\Twig_Token::OPERATOR_TYPE, '='); - $attributes['debug'] = 'true' == $stream->expect(\Twig_Token::NAME_TYPE, array('true', 'false'))->getValue(); + $attributes['debug'] = 'true' == $stream->expect(\Twig_Token::NAME_TYPE, ['true', 'false'])->getValue(); } elseif ($stream->test(\Twig_Token::NAME_TYPE, 'combine')) { // combine=true $stream->next(); $stream->expect(\Twig_Token::OPERATOR_TYPE, '='); - $attributes['combine'] = 'true' == $stream->expect(\Twig_Token::NAME_TYPE, array('true', 'false'))->getValue(); + $attributes['combine'] = 'true' == $stream->expect(\Twig_Token::NAME_TYPE, ['true', 'false'])->getValue(); } elseif ($stream->test(\Twig_Token::NAME_TYPE, 'vars')) { // vars=['locale','browser'] $stream->next(); @@ -174,12 +172,12 @@ public function parseAndInject(\Twig_Token $token) } $stream->expect(\Twig_Token::BLOCK_END_TYPE); - $body = $this->parser->subparse(array($this, 'testEndTag'), true); + $body = $this->parser->subparse([$this, 'testEndTag'], true); $stream->expect(\Twig_Token::BLOCK_END_TYPE); if ($injectorLocation) { - $injectorLocationArray = explode(",", $injectorLocation); + $injectorLocationArray = explode(',', $injectorLocation); //INJECT foreach ($injectorLocationArray as $injectorLocation) { @@ -187,7 +185,7 @@ public function parseAndInject(\Twig_Token $token) if (array_key_exists($this->tag, $this->injectedAssets) && in_array($injectorLocation, $injectorLocationsAvailables)) { if (!empty($this->injectedAssets[$this->tag][$injectorLocation])) { if (!is_array($this->injectedAssets[$this->tag][$injectorLocation])) { - $this->injectedAssets[$this->tag][$injectorLocation] = array($this->injectedAssets[$this->tag][$injectorLocation]); + $this->injectedAssets[$this->tag][$injectorLocation] = [$this->injectedAssets[$this->tag][$injectorLocation]]; } $inputs = array_merge($inputs, $this->injectedAssets[$this->tag][$injectorLocation]); } @@ -202,7 +200,7 @@ public function parseAndInject(\Twig_Token $token) $name = $this->factory->generateAssetName($inputs, $filters, $attributes); } - $asset = $this->factory->createAsset($inputs, $filters, $attributes + array('name' => $name)); + $asset = $this->factory->createAsset($inputs, $filters, $attributes + ['name' => $name]); return $this->createNode($asset, $body, $inputs, $filters, $name, $attributes, $token->getLine(), $this->getTag()); } diff --git a/composer.json b/composer.json index 6c9fe01..5a95d43 100644 --- a/composer.json +++ b/composer.json @@ -1,28 +1,27 @@ { - "name": "appventus/assetic-injector-bundle", + "name": "troopers/assetic-injector-bundle", "type": "symfony-bundle", "description": "This bundle allow you to define global javascripts and stylesheets", "keywords": ["assetic", "injector"], - "homepage": "http://appventus.com", + "homepage": "http://troopers.agency", "license": "MIT", "authors": [ { "name": "Paul Andrieux", - "email": "paul@appventus.com" + "email": "paul@troopers.email" }, { "name": "Leny Bernard", - "email": "leny@appventus.com" + "email": "leny@troopers.email" } ], "require": { "php": ">=5.3.2" }, "autoload": { - "psr-0": { "AppVentus\\AsseticInjectorBundle": "" } + "psr-0": { "Troopers\\AsseticInjectorBundle": "" } }, - "target-dir": "AppVentus/AsseticInjectorBundle", - "minimum-stability": "dev", + "target-dir": "Troopers/AsseticInjectorBundle", "extra" : { "branch-alias": { "dev-master": "1.0.x-dev"