Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions CipherText/Rotator/Store/DoctrineDBALStoreBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Created by PhpStorm.
* User: jjose00
* Date: 2/5/18
* Time: 5:42 PM
*/

namespace Giftcards\EncryptionBundle\CipherText\Rotator\Store;

use Doctrine\DBAL\Connection;
use Giftcards\Encryption\CipherText\Rotator\Store\DoctrineDBALStoreBuilder as BaseDoctrineDBALStoreBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class DoctrineDBALStoreBuilder extends BaseDoctrineDBALStoreBuilder
{
protected $container;

/**
* DatabaseTableRotatorBuilder constructor.
* @param $container
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}

public function configureOptionsResolver(OptionsResolver $resolver)
{
parent::configureOptionsResolver($resolver);
$container = $this->container;
$resolver
->addAllowedTypes('connection', 'string')
->setNormalizer('connection', function ($_, $connection) use ($container) {
if ($connection instanceof Connection) {
return $connection;
}

return $container->get($connection);
})
;
}
}
1 change: 1 addition & 0 deletions DependencyInjection/Compiler/AddBuildersPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class AddBuildersPass implements CompilerPassInterface
protected $registries = array(
'giftcards.encryption.key_source.factory.registry' => 'giftcards.encryption.key_source.builder',
'giftcards.encryption.cipher_text_rotator.factory.registry' => 'giftcards.encryption.cipher_text_rotator.builder',
'giftcards.encryption.cipher_text_store.factory.registry' => 'giftcards.encryption.cipher_text_store.builder',
'giftcards.encryption.cipher_text_serializer.factory.registry' => 'giftcards.encryption.cipher_text_serializer.builder',
'giftcards.encryption.cipher_text_deserializer.factory.registry' => 'giftcards.encryption.cipher_text_deserializer.builder',
);
Expand Down
37 changes: 37 additions & 0 deletions DependencyInjection/Compiler/AddCipherTextStoresPass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Created by PhpStorm.
* User: jderay
* Date: 8/3/15
* Time: 7:58 PM
*/

namespace Giftcards\EncryptionBundle\DependencyInjection\Compiler;

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

class AddCipherTextStoresPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('giftcards.encryption.cipher_text_store.registry')) {
return;
}

$registry = $container->getDefinition('giftcards.encryption.cipher_text_store.registry');

foreach ($container->findTaggedServiceIds('giftcards.encryption.cipher_text_store') as $id => $tags) {
foreach ($tags as $tag) {
if (!isset($tag['alias'])) {
throw new \InvalidArgumentException(sprintf(
'The service "%s" tagged giftcards.encryption.cipher_text_store must have an "alias" key given.',
$id
));
}
$registry->addMethodCall('setServiceId', array($tag['alias'], $id));
}
}
}
}
25 changes: 25 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,31 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
->arrayNode('rotator')
->addDefaultsIfNotSet()
->children()
->arrayNode('tracker')
->addDefaultsIfNotSet()
->children()
->scalarNode('id')->defaultValue('giftcards.encryption.rotator.tracker.null')->cannotBeEmpty()->end()
->end()
->end()
->end()
->end()
->arrayNode('stores')
->defaultValue(array())
->useAttributeAsKey('name')
->prototype('array')
->children()
->scalarNode('type')->isRequired()->cannotBeEmpty()->end()
->arrayNode('options')
->defaultValue(array())
->prototype('variable')
->end()
->end()
->end()
->end()
->end()
->arrayNode('serializers')
->defaultValue(array())
->prototype('array')
Expand Down
18 changes: 18 additions & 0 deletions DependencyInjection/GiftcardsEncryptionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ public function load(array $configs, ContainerBuilder $container)
;
}

$container->setAlias("giftcards.encryption.rotator.tracker", $config['rotator']['tracker']['id']);

foreach ($config['cipher_texts']['stores'] as $name => $rotatorConfig) {
$serviceId = sprintf('giftcards.encryption.cipher_text_store.%s', $name);
$container
->setDefinition(
$serviceId,
new DefinitionDecorator('giftcards.encryption.abstract_cipher_text_store')
)
->replaceArgument(0, $rotatorConfig['type'])
->replaceArgument(1, $rotatorConfig['options'])
->addTag(
'giftcards.encryption.cipher_text_store',
array('alias' => $name)
)
;
}

foreach ($config['cipher_texts']['serializers'] as $name => $serializerConfig) {
$serviceId = sprintf('giftcards.encryption.cipher_text_serializer.%s', $name);
$container
Expand Down
2 changes: 2 additions & 0 deletions GiftcardsEncryptionBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Giftcards\EncryptionBundle\DependencyInjection\Compiler\AddCipherTextRotatorsPass;
use Giftcards\EncryptionBundle\DependencyInjection\Compiler\AddCiphersPass;
use Giftcards\EncryptionBundle\DependencyInjection\Compiler\AddCipherTextSerializersDeserializersPass;
use Giftcards\EncryptionBundle\DependencyInjection\Compiler\AddCipherTextStoresPass;
use Giftcards\EncryptionBundle\DependencyInjection\Compiler\AddKeySourcesPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand All @@ -16,6 +17,7 @@ public function build(ContainerBuilder $container)
{
$container
->addCompilerPass(new AddCipherTextRotatorsPass())
->addCompilerPass(new AddCipherTextStoresPass())
->addCompilerPass(new AddCiphersPass())
->addCompilerPass(new AddKeySourcesPass())
->addCompilerPass(new AddCipherTextSerializersDeserializersPass())
Expand Down
8 changes: 8 additions & 0 deletions Resources/config/builders.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ services:
- '@service_container'
tags:
- { name: giftcards.encryption.cipher_text_rotator.builder, alias: doctrine_dbal }

#stores
giftcards.encryption.cipher_text_store.builder.doctrine_dbal:
class: Giftcards\EncryptionBundle\CipherText\Rotator\Store\DoctrineDBALStoreBuilder
arguments:
- '@service_container'
tags:
- { name: giftcards.encryption.cipher_text_store.builder, alias: doctrine_dbal }

#serializers
giftcards.encryption.cipher_text_serializer.builder.basic:
Expand Down
22 changes: 20 additions & 2 deletions Resources/config/factories.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ services:
class: Giftcards\Encryption\Factory\ContainerAwareRegistry
arguments:
- '@service_container'

giftcards.encryption.cipher_text_store.factory.registry:
class: Giftcards\Encryption\Factory\ContainerAwareRegistry
arguments:
- '@service_container'

giftcards.encryption.cipher_text_serializer.factory.registry:
class: Giftcards\Encryption\Factory\ContainerAwareRegistry
Expand All @@ -30,7 +35,13 @@ services:
arguments:
- Giftcards\Encryption\CipherText\Rotator\RotatorInterface
- '@giftcards.encryption.cipher_text_rotator.factory.registry'


giftcards.encryption.cipher_text_store.factory:
class: Giftcards\Encryption\Factory\Factory
arguments:
- Giftcards\Encryption\CipherText\Rotator\Store\StoreInterface
- '@giftcards.encryption.cipher_text_store.factory.registry'

giftcards.encryption.cipher_text_serializer.factory:
class: Giftcards\Encryption\Factory\Factory
arguments:
Expand Down Expand Up @@ -58,6 +69,14 @@ services:
- type
- options
abstract: true

giftcards.encryption.abstract_cipher_text_store:
class: Giftcards\Encryption\CipherText\Rotator\Store\StoreInterface
factory: ['@giftcards.encryption.cipher_text_store.factory', create]
arguments:
- type
- options
abstract: true

giftcards.encryption.abstract_cipher_text_serializer:
class: Giftcards\Encryption\CipherText\Serializer\SerializerInterface
Expand All @@ -74,4 +93,3 @@ services:
- type
- options
abstract: true

25 changes: 25 additions & 0 deletions Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ services:
class: Giftcards\Encryption\CipherText\Rotator\ContainerAwareRotatorRegistry
arguments:
- '@service_container'

giftcards.encryption.cipher_text_store.registry:
class: Giftcards\Encryption\CipherText\Rotator\Store\ContainerAwareStoreRegistry
arguments:
- '@service_container'

giftcards.encryption.cipher.registry:
class: Giftcards\Encryption\Cipher\ContainerAwareCipherRegistry
Expand Down Expand Up @@ -55,3 +60,23 @@ services:
- '@giftcards.encryption.encryptor'
tags:
- { name: console.command }

giftcards.encryption.rotator:
class: Giftcards\Encryption\CipherText\Rotator\Rotator
arguments:
- '@giftcards.encryption.encryptor'
- '@giftcards.encryption.cipher_text_store.registry'

giftcards.encryption.rotator.tracker.null:
class: Giftcards\Encryption\CipherText\Rotator\Tracker\NullTracker

giftcards.encryption.command.rotate_store:
class: Giftcards\Encryption\Command\RotateStoreCommand
arguments:
- '@giftcards.encryption.rotator'
- '@giftcards.encryption.rotator.tracker'

giftcards.encryption.command.rotate_range:
class: Giftcards\Encryption\Command\RotateRangeInStoreCommand
arguments:
- '@giftcards.encryption.rotator'
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@

namespace Giftcards\EncryptionBundle\Tests\DependencyInjection\Compiler;

use Giftcards\EncryptionBundle\DependencyInjection\Compiler\AddCipherTextRotatorsPass;
use Giftcards\EncryptionBundle\DependencyInjection\Compiler\AddCipherTextStoresPass;
use Giftcards\Encryption\Tests\AbstractTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;

class AddCipherTextRotatorsPassTest extends AbstractTestCase
{
/** @var AddCipherTextRotatorsPass */
/** @var AddCipherTextStoresPass */
protected $pass;

public function setUp()
{
$this->pass = new AddCipherTextRotatorsPass();
$this->pass = new AddCipherTextStoresPass();
}

public function testProcessWithNoRegistry()
Expand Down
2 changes: 1 addition & 1 deletion Tests/GiftcardsEncryptionBundleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function testCompile()
\Mockery::mock('Symfony\Component\DependencyInjection\ContainerBuilder')
->shouldReceive('addCompilerPass')
->once()
->with('Giftcards\EncryptionBundle\DependencyInjection\Compiler\AddCipherTextRotatorsPass')
->with('Giftcards\EncryptionBundle\DependencyInjection\Compiler\AddCipherTextStoresPass')
->andReturn(\Mockery::self())
->getMock()
->shouldReceive('addCompilerPass')
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Bundle to integrate the giftcards/encryption lib into symfony",
"require": {
"symfony/symfony": "~2.6|~3.0",
"giftcards/encryption": "~1.5"
"giftcards/encryption": "~1.7"
},
"require-dev": {
"mockery/mockery": "0.9.9",
Expand Down
Loading