Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérémy Jourdin committed Nov 13, 2014
0 parents commit 1061288
Show file tree
Hide file tree
Showing 59 changed files with 2,988 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .atoum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
$runner->addTestsFromDirectory(__DIR__.'/Tests/');
2 changes: 2 additions & 0 deletions .bootstrap.atoum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
require 'vendor/autoload.php';
6 changes: 6 additions & 0 deletions .coke
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
standard-path=vendor/m6web/symfony2-coding-standard/
standard=Symfony2
.
!bin/
!Tests/
!vendor/
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/vendor/
/bin/
composer.lock
14 changes: 14 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
language: php
php:
- "5.5"
- "5.4"
- "5.3"

before_script:
- wget http://getcomposer.org/composer.phar
- php composer.phar install --dev
- cp build-tools/travis-ci/.atoum.php .atoum.php
- sed -i s/COVERALLS_TOKEN/$COVERALLS_TOKEN/ .atoum.php
script:
- bin/atoum
- bin/coke
22 changes: 22 additions & 0 deletions Annotation/Identity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace LLS\Bundle\AWSBundle\Annotation;

/**
* Identity Annotation
*
* @Annotation
* @Target({"PROPERTY", "METHOD"})
*/
class Identity
{
/**
* @var string
*/
public $name;

/**
* @Enum({"getter", "setter"})
*/
public $type = "getter";
}
40 changes: 40 additions & 0 deletions DependencyInjection/Compiler/IdentityCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
namespace LLS\Bundle\AWSBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;

/**
* Push tagged identity factories into the identity manager
*
* @author Jérémy Jourdin <jeremy.jourdin@lelivrescolaire.fr>
*/
class IdentityCompilerPass implements CompilerPassInterface
{
/**
* Process data
*
* @param ContainerBuilder $container SF2 Container Builder
*/
public function process(ContainerBuilder $container)
{
$taggedServices = $container->findTaggedServiceIds('llsaws.identity.type');

foreach ($taggedServices as $id => $tags) {
$definition = $container->getDefinition('llsaws.identity.manager');
$canonicalId = str_replace('.', '_', $id);

foreach ($tags as $attributes) {
$definition
->addMethodCall(
'addType',
array(
!empty($attributes['alias']) ? $attributes['alias'] : $canonicalId,
new Reference($id)
)
);
}
}
}
}
40 changes: 40 additions & 0 deletions DependencyInjection/Compiler/ServiceCompilerPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
namespace LLS\Bundle\AWSBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Reference;

/**
* Push tagged identity factories into the identity manager
*
* @author Jérémy Jourdin <jeremy.jourdin@lelivrescolaire.fr>
*/
class ServiceCompilerPass implements CompilerPassInterface
{
/**
* Process data
*
* @param ContainerBuilder $container SF2 Container Builder
*/
public function process(ContainerBuilder $container)
{
$taggedServices = $container->findTaggedServiceIds('llsaws.service.type');

foreach ($taggedServices as $id => $tags) {
$definition = $container->getDefinition('llsaws.service.manager');
$canonicalId = str_replace('.', '_', $id);

foreach ($tags as $attributes) {
$definition
->addMethodCall(
'addType',
array(
!empty($attributes['alias']) ? $attributes['alias'] : $canonicalId,
new Reference($id)
)
);
}
}
}
}
79 changes: 79 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

namespace LLS\Bundle\AWSBundle\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
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();

$rootNode = $treeBuilder->root('llsaws');
$rootNode
->fixXmlConfig('identity')
->append($this->getIdentitiesNode())
->fixXmlConfig('service')
->append($this->getServicesNode());

return $treeBuilder;
}

protected function getIdentitiesNode()
{
$treeBuilder = new TreeBuilder();

$node = $treeBuilder->root('identities');
$node
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('array')
->children()
->scalarNode('type')
->defaultValue('user')
->end()
->end()
->fixXmlConfig('field')
->children()
->arrayNode('fields')
->useAttributeAsKey('name')
->prototype('scalar')->end()
->end()
->end()
->end();

return $node;
}

protected function getServicesNode()
{
$treeBuilder = new TreeBuilder();

$node = $treeBuilder->root('services');
$node
->requiresAtLeastOneElement()
->useAttributeAsKey('name')
->prototype('array')
->children()
->scalarNode('type')
->isRequired()
->end()
->scalarNode('identity')
->isRequired()
->end()
->end()
->end();

return $node;
}
}
125 changes: 125 additions & 0 deletions DependencyInjection/LLSAWSExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?php

namespace LLS\Bundle\AWSBundle\DependencyInjection;

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

/**
* 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 LLSAWSExtension extends Extension
{
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');

if ($container->hasParameter('test') && $container->getParameter('test') === true) {
$loader->load('services_test.yml');
}

if (isset($config['identities'])) {
$this->loadIdentities($container, $config['identities']);
}

if (isset($config['services'])) {
$this->loadServices($container, $config['services']);
}
}

protected function loadIdentities(ContainerBuilder $container, array $config)
{
foreach ($config as $name => $infos) {
$this->createIdentityService($container, $name, $infos['type'], $infos['fields']);
}

return $this;
}

protected function createIdentityService(ContainerBuilder $container, $name, $type, $definition)
{
$container
->setDefinition(
self::getIdentityServiceKey($name),
new Definition(
'LLS\\Bundle\\AWSBundle\\Interfaces\\IdentityInterface',
array(
$type,
$definition
)
)
)
->setFactoryService('llsaws.identity.manager')
->setFactoryMethod('create');

return $this;
}

protected function loadServices(ContainerBuilder $container, array $config)
{
foreach ($config as $name => $infos) {
$this->createServiceService($container, $name, $infos);
}

return $this;
}

protected function createServiceService(ContainerBuilder $container, $name, $attributes)
{
$container
->setDefinition(
self::getServiceServiceKey($name),
new Definition(
'LLS\\Bundle\\AWSBundle\\Interfaces\\ServiceInterface',
array(
$attributes['type'],
array(
new Reference(self::getIdentityServiceKey($attributes['identity'])),
new Reference('llsaws.client.factory')
)
)
)
)
->setFactoryService('llsaws.service.manager')
->setFactoryMethod('create');

return $this;
}

/**
* Get Identity Service key from it's name
*
* @param string $name Service name
*
* @return string
*/
public static function getIdentityServiceKey($name)
{
return sprintf('llsaws.identities.%s', $name);
}

/**
* Get Service Service key from it's name
*
* @param string $name Service name
*
* @return string
*/
public static function getServiceServiceKey($name)
{
return sprintf('llsaws.services.%s', $name);
}
}

0 comments on commit 1061288

Please sign in to comment.