forked from KnpLabs/DictionaryBundle
-
Notifications
You must be signed in to change notification settings - Fork 10
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 #58 from KnpLabs/refactoring/remove-serializable-d…
…ictionaries Dictionaries are not serializable anymore
- Loading branch information
Showing
13 changed files
with
306 additions
and
101 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
84 changes: 84 additions & 0 deletions
84
spec/Knp/DictionaryBundle/Dictionary/TraceableDictionarySpec.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,84 @@ | ||
<?php | ||
|
||
namespace spec\Knp\DictionaryBundle\Dictionary; | ||
|
||
use Knp\DictionaryBundle\DataCollector\DictionaryDataCollector; | ||
use Knp\DictionaryBundle\Dictionary\SimpleDictionary; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class TraceableDictionarySpec extends ObjectBehavior | ||
{ | ||
function let(DictionaryDataCollector $collector) | ||
{ | ||
$dictionary = new SimpleDictionary('name', [ | ||
'foo' => 'bar', | ||
'baz' => null, | ||
]); | ||
|
||
$this->beConstructedWith($dictionary, $collector); | ||
} | ||
|
||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType('Knp\DictionaryBundle\Dictionary\TraceableDictionary'); | ||
} | ||
|
||
function it_is_a_dictionary() | ||
{ | ||
$this->shouldImplement('Knp\DictionaryBundle\Dictionary'); | ||
} | ||
|
||
function it_has_a_name() | ||
{ | ||
$this->getName()->shouldReturn('name'); | ||
} | ||
|
||
function it_traces_keys($collector) | ||
{ | ||
$collector->addDictionary('name', ['foo', 'baz'], ['bar', null])->shouldbeCalled(); | ||
|
||
$this->getKeys()->shouldReturn(['foo', 'baz']); | ||
} | ||
|
||
function it_traces_values($collector) | ||
{ | ||
$collector->addDictionary('name', ['foo', 'baz'], ['bar', null])->shouldbeCalled(); | ||
|
||
$this->getValues()->shouldReturn(['foo' => 'bar', 'baz' => null]); | ||
} | ||
|
||
function it_traces_values_get($collector) | ||
{ | ||
$collector->addDictionary('name', ['foo', 'baz'], ['bar', null])->shouldbeCalled(); | ||
|
||
$this['foo']->shouldReturn('bar'); | ||
} | ||
|
||
function it_traces_value_set($collector) | ||
{ | ||
$collector->addDictionary('name', ['foo', 'baz', 'yo'], ['bar', null, 'lo'])->shouldbeCalled(); | ||
|
||
$this['yo'] = 'lo'; | ||
} | ||
|
||
function it_traces_value_unset($collector) | ||
{ | ||
$collector->addDictionary('name', ['baz'], [null])->shouldbeCalled(); | ||
|
||
unset($this['foo']); | ||
} | ||
|
||
function it_traces_key_exists($collector) | ||
{ | ||
$collector->addDictionary('name', ['foo', 'baz'], ['bar', null])->shouldbeCalled(); | ||
|
||
expect(isset($this['baz']))->toBe(true); | ||
} | ||
|
||
function it_trace_iteration($collector) | ||
{ | ||
$collector->addDictionary('name', ['foo', 'baz'], ['bar', null])->shouldbeCalled(); | ||
|
||
expect(iterator_to_array($this->getIterator()->getWrappedObject()))->toBe(['foo' => 'bar', 'baz' => null]); | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/Knp/DictionaryBundle/DependencyInjection/Compiler/DictionaryTracePass.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,35 @@ | ||
<?php | ||
|
||
namespace Knp\DictionaryBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
|
||
class DictionaryTracePass implements CompilerPassInterface | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (false === $container->has('knp_dictionary.data_collector.dictionary_data_collector')) { | ||
return; | ||
} | ||
|
||
$collector = new Reference('knp_dictionary.data_collector.dictionary_data_collector'); | ||
$services = $container->findTaggedServiceIds(DictionaryRegistrationPass::TAG_DICTIONARY); | ||
|
||
foreach ($services as $id => $tags) { | ||
$serviceId = sprintf('%s.%s.traceable', $id, md5($id)); | ||
|
||
$dictionary = new Reference(sprintf('%s.inner', $serviceId)); | ||
|
||
$traceable = new Definition('Knp\DictionaryBundle\Dictionary\TraceableDictionary', [$dictionary, $collector]); | ||
$traceable->setDecoratedService($id); | ||
|
||
$container->setDefinition($serviceId, $traceable); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.