Skip to content

Commit

Permalink
Updated namespaces, added new code to subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
dev-marcel committed Mar 11, 2015
1 parent e9030a4 commit 2fc0380
Show file tree
Hide file tree
Showing 18 changed files with 208 additions and 159 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

namespace VMelnik\DoctrineEncryptBundle;
namespace Ambta\DoctrineEncryptBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use VMelnik\DoctrineEncryptBundle\DependencyInjection\VMelnikDoctrineEncryptExtension;
use VMelnik\DoctrineEncryptBundle\DependencyInjection\Compiler\RegisterServiceCompilerPass;
use Ambta\DoctrineEncryptBundle\DependencyInjection\DoctrineEncryptExtension;
use Ambta\DoctrineEncryptBundle\DependencyInjection\Compiler\RegisterServiceCompilerPass;


class VMelnikDoctrineEncryptBundle extends Bundle {
class AmbtaDoctrineEncryptBundle extends Bundle {

public function build(ContainerBuilder $container) {
parent::build($container);
Expand All @@ -18,6 +17,6 @@ public function build(ContainerBuilder $container) {

public function getContainerExtension()
{
return new VMelnikDoctrineEncryptExtension();
return new DoctrineEncryptExtension();
}
}
2 changes: 1 addition & 1 deletion Configuration/Encrypted.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace VMelnik\DoctrineEncryptBundle\Configuration;
namespace Ambta\DoctrineEncryptBundle\Configuration;

/**
* The Encrypted class handles the @Encrypted annotation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace VMelnik\DoctrineEncryptBundle\DependencyInjection;
namespace Ambta\DoctrineEncryptBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
Expand All @@ -16,7 +16,7 @@
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class VMelnikDoctrineEncryptExtension extends Extension {
class AmbtaDoctrineEncryptExtension extends Extension {

/**
* {@inheritDoc}
Expand All @@ -25,7 +25,7 @@ public function load(array $configs, ContainerBuilder $container) {
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$services = array('orm' => 'orm-services');
$supportedEncryptorClasses = array('aes256' => 'VMelnik\DoctrineEncryptBundle\Encryptors\AES256Encryptor');
$supportedEncryptorClasses = array('aes256' => 'Ambta\DoctrineEncryptBundle\Encryptors\AES256Encryptor');

if (empty($config['secret_key'])) {
if ($container->hasParameter('secret')) {
Expand All @@ -41,11 +41,11 @@ public function load(array $configs, ContainerBuilder $container) {
$encryptorFullName = $supportedEncryptorClasses[$config['encryptor']];
}

$container->setParameter('vmelnik_doctrine_encrypt.encryptor_class_name', $encryptorFullName);
$container->setParameter('vmelnik_doctrine_encrypt.secret_key', $config['secret_key']);
$container->setParameter('ambta_doctrine_encrypt.encryptor_class_name', $encryptorFullName);
$container->setParameter('ambta_doctrine_encrypt.secret_key', $config['secret_key']);

if (!empty($config['encryptor_service'])) {
$container->setParameter('vmelnik_doctrine_encrypt.encryptor_service', $config['encryptor_service']);
$container->setParameter('ambta_doctrine_encrypt.encryptor_service', $config['encryptor_service']);
}

$loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
Expand All @@ -68,7 +68,7 @@ private function getDefinition(ContainerBuilder $container, $id) {
}

public function getAlias() {
return 'vmelnik_doctrine_encrypt';
return 'ambta_doctrine_encrypt';
}

}
32 changes: 2 additions & 30 deletions DependencyInjection/Compiler/RegisterServiceCompilerPass.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace VMelnik\DoctrineEncryptBundle\DependencyInjection\Compiler;
namespace Ambta\DoctrineEncryptBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -16,37 +16,9 @@
class RegisterServiceCompilerPass implements CompilerPassInterface {

public function process(ContainerBuilder $container) {

if ($container->hasParameter('vmelnik_doctrine_encrypt.encryptor_service')) {
// Load some parameters
$secretKey = $container->getParameter('vmelnik_doctrine_encrypt.secret_key');
$encryptorServiceId = $container->getParameter('vmelnik_doctrine_encrypt.encryptor_service');

// Get the definitions
$subscriberDefinition = $this->getDefinition($container, 'vmelnik_doctrine_encrypt.subscriber');
$encryptorDefinition = $this->getDefinition($container, $encryptorServiceId);

// Adjust the definitions
$encryptorDefinition->setArguments(array($secretKey));
$subscriberDefinition->replaceArgument(1, '');
$subscriberDefinition->addArgument(new Reference($encryptorServiceId));
}
//Nothing here
}

/**
*
* @param ContainerBuilder $container
* @param string $id
* @return Definition
* @throws \RuntimeException
*/
private function getDefinition(ContainerBuilder $container, $id) {
try {
return $container->findDefinition($id);
} catch (InvalidArgumentException $e) {
throw new \RuntimeException('Unable to locate service (' . $id . ').', NULL, $e);
}
}

}

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

namespace VMelnik\DoctrineEncryptBundle\DependencyInjection;
namespace Ambta\DoctrineEncryptBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
Expand All @@ -19,7 +19,7 @@ class Configuration implements ConfigurationInterface {
*/
public function getConfigTreeBuilder() {
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('vmelnik_doctrine_encrypt');
$rootNode = $treeBuilder->root('ambta_doctrine_encrypt');
$supportedDrivers = array('orm');
$supportedEncryptors = array('aes256');

Expand Down
61 changes: 61 additions & 0 deletions DependencyInjection/DoctrineEncryptExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Ambta\DoctrineEncryptBundle\DependencyInjection;

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

/**
* Initialization of bundle.
*
* 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 DoctrineEncryptExtension extends Extension {

/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container) {

$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$services = array('orm' => 'orm-services');
$supportedEncryptorClasses = array('aes256' => 'Ambta\DoctrineEncryptBundle\Encryptors\AES256Encryptor');

if (empty($config['secret_key'])) {
if ($container->hasParameter('secret')) {
$config['secret_key'] = $container->getParameter('secret');
} else {
throw new \RuntimeException('You must provide "secret_key" for DoctrineEncryptBundle or "secret" for framework');
}
}

if (!empty($config['encryptor_class'])) {
$encryptorFullName = $config['encryptor_class'];
} else {
$encryptorFullName = $supportedEncryptorClasses[$config['encryptor']];
}

$container->setParameter('ambta_doctrine_encrypt.encryptor_class_name', $encryptorFullName);
$container->setParameter('ambta_doctrine_encrypt.secret_key', $config['secret_key']);

if (!empty($config['encryptor_service'])) {
$container->setParameter('ambta_doctrine_encrypt.encryptor_service', $config['encryptor_service']);
}

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load(sprintf('%s.yml', $services[$config['db_driver']]));
}


public function getAlias() {
return 'ambta_doctrine_encrypt';
}

}
2 changes: 1 addition & 1 deletion Encryptors/AES256Encryptor.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace VMelnik\DoctrineEncryptBundle\Encryptors;
namespace Ambta\DoctrineEncryptBundle\Encryptors;

/**
* Class for AES256 encryption
Expand Down
2 changes: 1 addition & 1 deletion Encryptors/EncryptorInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace VMelnik\DoctrineEncryptBundle\Encryptors;
namespace Ambta\DoctrineEncryptBundle\Encryptors;

/**
* Encryptor interface for encryptors
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
Bundle allows to create doctrine entities with fields that will be protected with
help of some encryption algorithm in database and it will be clearly for developer, because bundle is uses doctrine life cycle events

This is an fork from the original bundle created by vmelnik-ukrain (Many thanks to him) which can be found here:
[vmelnik-ukraine/DoctrineEncryptBundle](https://github.com/vmelnik-ukraine/DoctrineEncryptBundle)

I improved several things, i make better use of the doctrine events.
and it works with lazy loading (relationships)!

###Documentation

The bulk of the documentation is stored in the `Resources/doc/index.md` file in this bundle

[Read the Documentation](https://github.com/vmelnik-ukraine/DoctrineEncryptBundle/blob/master/Resources/doc/index.md)
[Read the Documentation](https://github.com/marcel-ambta/DoctrineEncryptBundle/blob/master/Resources/doc/index.md)

###License

Expand Down
8 changes: 8 additions & 0 deletions Resources/config/encryptBundleService.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
ambta_doctrine_encrypt.orm_subscriber:
class: %ambta_doctrine_encrypt.orm_subscriber.class%
arguments: ["@annotation_reader", %ambta_doctrine_encrypt.encryptor_class_name%, %ambta_doctrine_encrypt.secret_key%]
tags:
- { name: doctrine.event_subscriber }
ambta_doctrine_encrypt.subscriber:
alias: ambta_doctrine_encrypt.orm_subscriber
21 changes: 0 additions & 21 deletions Resources/config/orm-services.xml

This file was deleted.

8 changes: 8 additions & 0 deletions Resources/config/orm-services.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
ambta_doctrine_encrypt.orm_subscriber:
class: Ambta\DoctrineEncryptBundle\Subscribers\DoctrineEncryptSubscriber
arguments: ["@annotation_reader", %ambta_doctrine_encrypt.encryptor_class_name%, %ambta_doctrine_encrypt.secret_key%]
tags:
- { name: doctrine.event_subscriber }
ambta_doctrine_encrypt.subscriber:
alias: ambta_doctrine_encrypt.orm_subscriber
20 changes: 10 additions & 10 deletions Resources/doc/configuration_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
All available configuration options are listed below with their default values.

``` yaml
vmelnik_doctrine_encrypt:

ambta_doctrine_encrypt:

# Secret key for encrypt algorithm. All secret key checks are encryptor tasks only.
# We recommend an 32 character long key (256 bits), Use another key for each project!

secret_key: ~ # Required
# Default and only one encryptor is aes256. If you want to provide your own - set encryptor_class
encryptor: aes256

# If you want, you can use your own Encryptor. Encryptor must implements EncryptorInterface interface
# Default: VMelnik\DoctrineEncryptBundle\Encryptors\AES256Encryptor
encryptor_class: ~
# You can optionally provide a service as an encryptor instead of specifying a class. The service
# must implement EncryptorInterface. You do not need to provide encryptor_class if you provide the service.
encryptor_service: ~
# Now it's only one db driver is supported - orm
db_driver: orm
# Default: Ambta\DoctrineEncryptBundle\Encryptors\AES256Encryptor

encryptor_class: ~ #optional

```
4 changes: 2 additions & 2 deletions Resources/doc/example_of_usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Acme\DemoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;

// importing @Encrypted annotation
use VMelnik\DoctrineEncryptBundle\Configuration\Encrypted;
use Ambta\DoctrineEncryptBundle\Configuration\Encrypted;

/**
* @ORM\Entity
Expand Down Expand Up @@ -111,7 +111,7 @@ use Acme\DemoBundle\Entity\UserV;
class DemoController extends Controller
{
/**
* @Route("/show-user/{id}", name="_vmelnik_decrypt_test", requirements={"id" = "\d+"})
* @Route("/show-user/{id}", name="_ambta_decrypt_test", requirements={"id" = "\d+"})
* @Template
*/
public function getUserAction(UserV $user) {}
Expand Down
6 changes: 3 additions & 3 deletions Resources/doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ on PHP side

The following documents are available:

* [Configuration reference](https://github.com/vmelnik-ukraine/DoctrineEncryptBundle/blob/master/Resources/doc/configuration_reference.md)
* [Installation](https://github.com/vmelnik-ukraine/DoctrineEncryptBundle/blob/master/Resources/doc/installation.md)
* [Example of usage](https://github.com/vmelnik-ukraine/DoctrineEncryptBundle/blob/master/Resources/doc/example_of_usage.md)
* [Configuration reference](https://github.com/marcel-ambta/DoctrineEncryptBundle/blob/master/Resources/doc/configuration_reference.md)
* [Installation](https://github.com/marcel-ambta/DoctrineEncryptBundle/blob/master/Resources/doc/installation.md)
* [Example of usage](https://github.com/marcel-ambta/DoctrineEncryptBundle/blob/master/Resources/doc/example_of_usage.md)
14 changes: 7 additions & 7 deletions Resources/doc/installation.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
#Installation

1. Download VMelnikDoctrineEncryptBundle using composer
1. Download AmbtaDoctrineEncryptBundle using composer
2. Enable the Bundle

### Step 1: Download VMelnikDoctrineEncryptBundle using composer
### Step 1: Download AmbtaDoctrineEncryptBundle using composer

Add VMelnikDoctrineEncryptBundle in your composer.json:
Add AmbtaDoctrineEncryptBundle in your composer.json:

```js
{
"require": {
"vmelnik/doctrine-encrypt-bundle": "dev-master"
"ambta/doctrine-encrypt-bundle": "dev-master"
}
}
```

Now tell composer to download the bundle by running the command:

``` bash
$ php composer.phar update vmelnik/doctrine-encrypt-bundle
$ php composer.phar update ambta/doctrine-encrypt-bundle
```

Composer will install the bundle to your project's `vendor/vmelnik` directory.
Composer will install the bundle to your project's `vendor/ambta` directory.

### Step 2: Enable the bundle

Expand All @@ -35,7 +35,7 @@ public function registerBundles()
{
$bundles = array(
// ...
new VMelnik\DoctrineEncryptBundle\VMelnikDoctrineEncryptBundle(),
new Ambta\DoctrineEncryptBundle\AmbtaDoctrineEncryptBundle(),
);
}
```
Loading

0 comments on commit 2fc0380

Please sign in to comment.