Skip to content

Commit

Permalink
Move to Troopers org (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
lenybernard authored Oct 3, 2016
1 parent 6c00c1a commit edd4f25
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 105 deletions.
17 changes: 8 additions & 9 deletions AssetsCollector/Collector.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php
namespace AppVentus\AsseticInjectorBundle\AssetsCollector;

namespace Troopers\AsseticInjectorBundle\AssetsCollector;

use Symfony\Component\Finder\Finder;

/**
* Assets collector.
*
* @author Paul Andrieux <paul@appventus.com>
* @author Paul Andrieux <paul@troopers.email>
*/
class Collector
{
/**
* Constructor
* Constructor.
*
* @param Container $container The container
*/
Expand All @@ -21,7 +22,7 @@ public function __construct($container)
}

/**
* Inject the assets
* Inject the assets.
*
* @param \Twig_TokenParser $parser
*/
Expand All @@ -31,7 +32,7 @@ public function injectAssets(\Twig_TokenParser $parser)
}

/**
* Get the assets for each bundle
* Get the assets for each bundle.
*
* @return multitype:
*/
Expand All @@ -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) {
Expand All @@ -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))) {
Expand All @@ -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());
Expand Down
9 changes: 5 additions & 4 deletions AssetsCollector/RequireAll.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?php
namespace AppVentus\AsseticInjectorBundle\AssetsCollector;

namespace Troopers\AsseticInjectorBundle\AssetsCollector;

class RequireAll
{
protected $resources = array();
protected $resources = [];

public function compute($item)
{
foreach($item as $type => $resource) {
foreach($resource as $k => $path) {
foreach ($item as $type => $resource) {
foreach ($resource as $k => $path) {
$this->resources[$type][$k] = $path;
}
}
Expand Down
9 changes: 0 additions & 9 deletions AvAsseticInjectorBundle.php

This file was deleted.

8 changes: 4 additions & 4 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<?php

namespace AppVentus\AsseticInjectorBundle\DependencyInjection;
namespace Troopers\AsseticInjectorBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
* This is the class that validates and merges configuration from your app/config files.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$treeBuilder->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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php

namespace AppVentus\AsseticInjectorBundle\DependencyInjection;
namespace Troopers\AsseticInjectorBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* This is the class that loads and manages your bundle configuration
* This is the class that loads and manages your bundle configuration.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class AvAsseticInjectorExtension extends Extension
class TroopersAsseticInjectorExtension extends Extension
{
/**
* {@inheritDoc}
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013-2015 AppVentus
Copyright (c) 2013-2017 Troopers

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
[![AppVentus](https://github.com/AppVentus/AvAlertifyBundle/blob/master/Media/appventus.png)](http://appventus.com)
[![Troopers](https://cloud.githubusercontent.com/assets/618536/18787530/83cf424e-81a3-11e6-8f66-cde3ec5fa82a.png)](http://troopers.agency)


[![Dependency Status](https://www.versioneye.com/php/appventus:assetic-injector-bundle/dev-master/badge.svg)](https://www.versioneye.com/php/appventus:assetic-injector-bundle/dev-master)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/d10e1e8e-8bd5-462e-994f-419bcfb7da78/mini.png)](https://insight.sensiolabs.com/projects/d10e1e8e-8bd5-462e-994f-419bcfb7da78)

=============
Expand All @@ -20,14 +18,14 @@ With Composer :

Add this line in your composer.json file :

"appventus/assetic-injector-bundle": "dev-master"
"troopers/assetic-injector-bundle": "~1.0"

Declare the bundle in your AppKernel.php:

public function registerBundles() {
$bundles = array(
[...]
new AppVentus\AsseticInjectorBundle\AvAsseticInjectorBundle(),
new Troopers\AsseticInjectorBundle\TroopersAsseticInjectorBundle(),
[...]

Then declare an assetic_injector.json in the Resource/config folder of your application or bundle:
Expand Down
16 changes: 8 additions & 8 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
parameters:
assetic.twig_extension.class: "AppVentus\AsseticInjectorBundle\Twig\AsseticExtension"
av_assetic_injector.collector.class: "AppVentus\AsseticInjectorBundle\AssetsCollector\Collector"
assetic.twig_extension.class: "Troopers\AsseticInjectorBundle\Twig\AsseticExtension"
troopers_assetic_injector.collector.class: "Troopers\AsseticInjectorBundle\AssetsCollector\Collector"

services:

av_assetic_injector.collector:
class: %av_assetic_injector.collector.class%
troopers_assetic_injector.collector:
class: %troopers_assetic_injector.collector.class%
arguments: [@service_container]

av_assetic_injector.collector_engine.require_all:
class: "AppVentus\AsseticInjectorBundle\AssetsCollector\RequireAll"
troopers_assetic_injector.collector_engine.require_all:
class: "Troopers\AsseticInjectorBundle\AssetsCollector\RequireAll"

assetic_injector.require_all:
alias: av_assetic_injector.collector_engine.require_all
alias: troopers_assetic_injector.collector_engine.require_all

assetic.twig_extension:
class: %assetic.twig_extension.class%
Expand All @@ -22,4 +22,4 @@ services:
- {name: assetic.templating.twig}
arguments: [@assetic.asset_factory, @templating.name_parser, %assetic.use_controller%, %assetic.twig_extension.functions%, %assetic.bundles%, @assetic.value_supplier ]
calls:
- [ setCollector, [ @av_assetic_injector.collector ] ]
- [ setCollector, [ @troopers_assetic_injector.collector ] ]
17 changes: 0 additions & 17 deletions Tests/Controller/DefaultControllerTest.php

This file was deleted.

9 changes: 9 additions & 0 deletions TroopersAsseticInjectorBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Troopers\AsseticInjectorBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class TroopersAsseticInjectorBundle extends Bundle
{
}
24 changes: 12 additions & 12 deletions Twig/AsseticExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@
* with this source code in the file LICENSE.
*/

namespace AppVentus\AsseticInjectorBundle\Twig;

namespace Troopers\AsseticInjectorBundle\Twig;

use Assetic\Extension\Twig\AsseticExtension as BaseAsseticExtension;
use Symfony\Bundle\AsseticBundle\Twig\AsseticNodeVisitor;
use Assetic\Factory\AssetFactory;
use Assetic\ValueSupplierInterface;
use Symfony\Bundle\AsseticBundle\Twig\AsseticNodeVisitor;
use Symfony\Component\Templating\TemplateNameParserInterface;

/**
* Assetic extension.
*
* @author Leny Bernard <leny@appventus.com>
* @author Paul Andrieux <paul@appventus.com>
* @author Leny Bernard <leny@troopers.email>
* @author Paul Andrieux <paul@troopers.email>
*/
class AsseticExtension extends BaseAsseticExtension implements \Twig_Extension_GlobalsInterface
{
Expand All @@ -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);

Expand All @@ -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()
Expand All @@ -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);
Expand Down
Loading

0 comments on commit edd4f25

Please sign in to comment.