Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DoctrineMongoDBBundle] switched to compiler passes for proxy/hydrato…
…r directory creation and event listeners
- Loading branch information
1 parent
1753985
commit 8235f71
Showing
9 changed files
with
148 additions
and
120 deletions.
There are no files selected for viewing
58 changes: 0 additions & 58 deletions
58
src/Symfony/Bundle/DoctrineAbstractBundle/Event/EventManager.php
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/CreateHydratorDirectoryPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
|
||
class CreateHydratorDirectoryPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasParameter('doctrine.odm.mongodb.hydrator_dir')) { | ||
return; | ||
} | ||
// Don't do anything if auto_generate_hydrator_classes is false | ||
if (!$container->getParameter('doctrine.odm.mongodb.auto_generate_hydrator_classes')) { | ||
return; | ||
} | ||
// Create document proxy directory | ||
$hydratorCacheDir = $container->getParameter('doctrine.odm.mongodb.hydrator_dir'); | ||
if (!is_dir($hydratorCacheDir)) { | ||
if (false === @mkdir($hydratorCacheDir, 0777, true)) { | ||
die(sprintf('Unable to create the Doctrine Hydrator directory (%s)', dirname($hydratorCacheDir))); | ||
} | ||
} elseif (!is_writable($hydratorCacheDir)) { | ||
die(sprintf('Unable to write in the Doctrine Hydrator directory (%s)', $hydratorCacheDir)); | ||
} | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
...ny/Bundle/DoctrineMongoDBBundle/DependencyInjection/Compiler/CreateProxyDirectoryPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
|
||
class CreateProxyDirectoryPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasParameter('doctrine.odm.mongodb.proxy_dir')) { | ||
return; | ||
} | ||
// Don't do anything if auto_generate_proxy_classes is false | ||
if (!$container->getParameter('doctrine.odm.mongodb.auto_generate_proxy_classes')) { | ||
return; | ||
} | ||
// Create document proxy directory | ||
$proxyCacheDir = $container->getParameter('doctrine.odm.mongodb.proxy_dir'); | ||
if (!is_dir($proxyCacheDir)) { | ||
if (false === @mkdir($proxyCacheDir, 0777, true)) { | ||
die(sprintf('Unable to create the Doctrine Proxy directory (%s)', dirname($proxyCacheDir))); | ||
} | ||
} elseif (!is_writable($proxyCacheDir)) { | ||
die(sprintf('Unable to write in the Doctrine Proxy directory (%s)', $proxyCacheDir)); | ||
} | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
...neMongoDBBundle/DependencyInjection/Compiler/RegisterEventListenersAndSubscribersPass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace Symfony\Bundle\DoctrineMongoDBBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
|
||
class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface | ||
{ | ||
protected $container; | ||
|
||
public function process(ContainerBuilder $container) | ||
{ | ||
$this->container = $container; | ||
foreach ($container->findTaggedServiceIds('doctrine.odm.mongodb.event_manager') as $id => $tag) { | ||
$definition = $container->getDefinition($id); | ||
$prefix = substr($id, 0, -1 * strlen('_event_manager')); | ||
$this->registerListeners($prefix, $definition); | ||
$this->registerSubscribers($prefix, $definition); | ||
} | ||
} | ||
|
||
protected function registerSubscribers($prefix, $definition) | ||
{ | ||
$subscribers = array_merge( | ||
$this->container->findTaggedServiceIds('doctrine.common.event_subscriber'), | ||
$this->container->findTaggedServiceIds($prefix.'_event_subscriber') | ||
); | ||
|
||
foreach ($subscribers as $id => $instances) { | ||
$definition->addMethodCall('addEventSubscriber', array(new Reference($id))); | ||
} | ||
} | ||
|
||
protected function registerListeners($prefix, $definition) | ||
{ | ||
$listeners = array_merge( | ||
$this->container->findTaggedServiceIds('doctrine.common.event_listener'), | ||
$this->container->findTaggedServiceIds($prefix.'_event_listener') | ||
); | ||
|
||
foreach ($listeners as $listenerId => $instances) { | ||
$events = array(); | ||
foreach ($instances as $attributes) { | ||
if (isset($attributes['event'])) { | ||
$events[] = $attributes['event']; | ||
} | ||
} | ||
|
||
if (0 < count($events)) { | ||
$definition->addMethodCall('addEventListener', array( | ||
$events, | ||
new Reference($listenerId), | ||
)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters