-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from ruslan-polutsygan/patch-1
Optional class loader & update symfony options in runtime
- Loading branch information
Showing
10 changed files
with
254 additions
and
20 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,4 +39,3 @@ public function process(ContainerBuilder $container) | |
} | ||
|
||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Theodo\Evolution\Bundle\LegacyWrapperBundle\Kernel\Event; | ||
|
||
use Symfony\Component\EventDispatcher\Event; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
class LegacyKernelBootEvent extends Event | ||
{ | ||
/** | ||
* @var Request | ||
*/ | ||
protected $request; | ||
|
||
/** | ||
* @var array - legacy kernel options | ||
*/ | ||
protected $options; | ||
|
||
/** | ||
* @param Request $request | ||
* @param array $options | ||
*/ | ||
public function __construct(Request $request, array $options = array()) | ||
{ | ||
$this->request = $request; | ||
$this->options = $options; | ||
} | ||
|
||
/** | ||
* @return Request | ||
*/ | ||
public function getRequest() | ||
{ | ||
return $this->request; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getOptions() | ||
{ | ||
return $this->options; | ||
} | ||
|
||
/** | ||
* @param array $options | ||
*/ | ||
public function setOptions($options) | ||
{ | ||
$this->options = $options; | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @param string $value | ||
*/ | ||
public function setOption($name, $value) | ||
{ | ||
$this->options[$name] = $value; | ||
} | ||
|
||
} |
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,8 @@ | ||
<?php | ||
|
||
namespace Theodo\Evolution\Bundle\LegacyWrapperBundle\Kernel; | ||
|
||
final class LegacyKernelEvents | ||
{ | ||
const BOOT = 'legacy_kernel.boot'; | ||
} |
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
68 changes: 68 additions & 0 deletions
68
Tests/DependencyInjection/Compiler/KernelConfigurationPassTest.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,68 @@ | ||
<?php | ||
|
||
namespace Theodo\Evolution\Bundle\LegacyWrapperBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class KernelConfigurationPassTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testShouldConfigureKernelBasedOnParameters() | ||
{ | ||
$container = new ContainerBuilder(); | ||
|
||
$container->setDefinition('legacy_kernel_id', new Definition()); | ||
|
||
$container->setParameter('theodo_evolution_legacy_wrapper.legacy_kernel.id', $kernel = 'legacy_kernel_id'); | ||
$container->setParameter('theodo_evolution_legacy_wrapper.legacy_kernel.options', $options = array('key' => 'value')); | ||
$container->setParameter('theodo_evolution_legacy_wrapper.autoload.class_loader.id', $loader = 'class_loader'); | ||
|
||
$compiler = new KernelConfigurationPass(); | ||
$compiler->process($container); | ||
|
||
$kernelDefinition = $container->findDefinition('theodo_evolution_legacy_wrapper.legacy_kernel'); | ||
|
||
$this->assertSame($container->findDefinition('legacy_kernel_id'), $kernelDefinition, 'Legacy kernel alias has not been set correctly'); | ||
$this->assertAttributeContains(array('setOptions', array($options)), 'calls', $kernelDefinition, 'Method setOptions has not been set to call'); | ||
$this->assertAttributeContains(array('setClassLoader', array(new Reference('class_loader'))), 'calls', $kernelDefinition, 'Method setClassLoader has not been set to call'); | ||
} | ||
|
||
public function testShouldNotCallSetOptionsIfEmpty() | ||
{ | ||
$container = new ContainerBuilder(); | ||
|
||
$container->setDefinition('legacy_kernel_id', new Definition()); | ||
|
||
$container->setParameter('theodo_evolution_legacy_wrapper.legacy_kernel.id', $kernel = 'legacy_kernel_id'); | ||
$container->setParameter('theodo_evolution_legacy_wrapper.legacy_kernel.options', $options = array()); | ||
$container->setParameter('theodo_evolution_legacy_wrapper.autoload.class_loader.id', $loader = 'class_loader'); | ||
|
||
$compiler = new KernelConfigurationPass(); | ||
$compiler->process($container); | ||
|
||
$kernelDefinition = $container->findDefinition('theodo_evolution_legacy_wrapper.legacy_kernel'); | ||
|
||
$this->assertSame($container->findDefinition('legacy_kernel_id'), $kernelDefinition, 'Legacy kernel alias has not been set correctly'); | ||
$this->assertAttributeNotContains(array('setOptions', array($options)), 'calls', $kernelDefinition, 'Method setOptions should not be set to call'); | ||
} | ||
|
||
public function testShouldNotCallSetClassLoaderIfNull() | ||
{ | ||
$container = new ContainerBuilder(); | ||
|
||
$container->setDefinition('legacy_kernel_id', new Definition()); | ||
|
||
$container->setParameter('theodo_evolution_legacy_wrapper.legacy_kernel.id', $kernel = 'legacy_kernel_id'); | ||
$container->setParameter('theodo_evolution_legacy_wrapper.legacy_kernel.options', $options = array('key' => 'value')); | ||
$container->setParameter('theodo_evolution_legacy_wrapper.autoload.class_loader.id', $loader = null); | ||
|
||
$compiler = new KernelConfigurationPass(); | ||
$compiler->process($container); | ||
|
||
$kernelDefinition = $container->findDefinition('theodo_evolution_legacy_wrapper.legacy_kernel'); | ||
|
||
$this->assertSame($container->findDefinition('legacy_kernel_id'), $kernelDefinition, 'Legacy kernel alias has not been set correctly'); | ||
$this->assertAttributeNotContains(array('setClassLoader', array(new Reference('class_loader'))), 'calls', $kernelDefinition, 'Method setClassLoader should not be set to call'); | ||
} | ||
} |
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