diff --git a/README.md b/README.md index a509a0f..a0c59dc 100644 --- a/README.md +++ b/README.md @@ -42,13 +42,14 @@ Serialization is controlled by registering callables used in normalization phase ```php use Thunder\Serializard\Format\JsonFormat; use Thunder\Serializard\FormatContainer\FormatContainer; -use Thunder\Serializard\HandlerContainer\HandlerContainer; +use Thunder\Serializard\HydratorContainer\FallbackHydratorContainer; +use Thunder\Serializard\NormalizerContainer\FallbackNormalizerContainer; use Thunder\Serializard\Serializard; $formats = new FormatContainer(); $formats->add('json', new JsonFormat()); -$normalizers = new HandlerContainer(); +$normalizers = new FallbackNormalizerContainer(); $normalizers->add(User::class, 'user', function(User $user) { return [ 'id' => $user->getId(), @@ -56,7 +57,7 @@ $normalizers->add(User::class, 'user', function(User $user) { ]; }); -$hydrators = new HandlerContainer(); +$hydrators = new FallbackHydratorContainer(); $serializard = new Serializard($formats, $normalizers, $hydrators); echo $serializard->serialize(new User(1, 'Thomas'), 'json'); @@ -76,15 +77,16 @@ Unserialization can be controlled by registering callables able to reconstruct o ```php use Thunder\Serializard\Format\JsonFormat; use Thunder\Serializard\FormatContainer\FormatContainer; -use Thunder\Serializard\HandlerContainer\HandlerContainer; +use Thunder\Serializard\HydratorContainer\FallbackHydratorContainer; +use Thunder\Serializard\NormalizerContainer\FallbackNormalizerContainer; use Thunder\Serializard\Serializard; $formats = new FormatContainer(); $formats->add('json', new JsonFormat()); -$normalizers = new HandlerContainer(); +$normalizers = new FallbackNormalizerContainer(); -$hydrators = new HandlerContainer(); +$hydrators = new FallbackHydratorContainer(); $hydrators->add(User::class, 'user', function(array $data) { return new User($data['id'], $data['name']); }); diff --git a/src/HydratorContainer/HydratorContainer.php b/src/HydratorContainer/FallbackHydratorContainer.php similarity index 96% rename from src/HydratorContainer/HydratorContainer.php rename to src/HydratorContainer/FallbackHydratorContainer.php index 2867dd3..4db849c 100644 --- a/src/HydratorContainer/HydratorContainer.php +++ b/src/HydratorContainer/FallbackHydratorContainer.php @@ -4,7 +4,7 @@ /** * @author Tomasz Kowalczyk */ -final class HydratorContainer implements HydratorContainerInterface +final class FallbackHydratorContainer implements HydratorContainerInterface { private $handlers = array(); private $interfaces = array(); diff --git a/src/NormalizerContainer/NormalizerContainer.php b/src/NormalizerContainer/FallbackNormalizerContainer.php similarity index 96% rename from src/NormalizerContainer/NormalizerContainer.php rename to src/NormalizerContainer/FallbackNormalizerContainer.php index 3ee96ad..206f7a8 100644 --- a/src/NormalizerContainer/NormalizerContainer.php +++ b/src/NormalizerContainer/FallbackNormalizerContainer.php @@ -4,7 +4,7 @@ /** * @author Tomasz Kowalczyk */ -final class NormalizerContainer implements NormalizerContainerInterface +final class FallbackNormalizerContainer implements NormalizerContainerInterface { private $handlers = array(); private $interfaces = array(); diff --git a/src/SerializardFacade.php b/src/SerializardFacade.php index 890e817..4203ee6 100644 --- a/src/SerializardFacade.php +++ b/src/SerializardFacade.php @@ -7,25 +7,25 @@ use Thunder\Serializard\Format\XmlFormat; use Thunder\Serializard\Format\YamlFormat; use Thunder\Serializard\FormatContainer\FormatContainer; -use Thunder\Serializard\HydratorContainer\HydratorContainer; -use Thunder\Serializard\NormalizerContainer\NormalizerContainer; +use Thunder\Serializard\HydratorContainer\FallbackHydratorContainer; +use Thunder\Serializard\NormalizerContainer\FallbackNormalizerContainer; /** * @author Tomasz Kowalczyk */ final class SerializardFacade { - /** @var NormalizerContainer */ + /** @var FallbackNormalizerContainer */ private $normalizers; - /** @var HydratorContainer */ + /** @var FallbackHydratorContainer */ private $hydrators; /** @var FormatContainer */ private $formats; public function __construct() { - $this->normalizers = new NormalizerContainer(); - $this->hydrators = new HydratorContainer(); + $this->normalizers = new FallbackNormalizerContainer(); + $this->hydrators = new FallbackHydratorContainer(); $formats = new FormatContainer(); $formats->add('json', new JsonFormat()); diff --git a/tests/FormatTest.php b/tests/FormatTest.php index 795ad20..9078650 100644 --- a/tests/FormatTest.php +++ b/tests/FormatTest.php @@ -2,8 +2,8 @@ namespace Thunder\Serializard\Tests; use Thunder\Serializard\Format\ArrayFormat; -use Thunder\Serializard\HydratorContainer\HydratorContainer; -use Thunder\Serializard\NormalizerContainer\NormalizerContainer; +use Thunder\Serializard\HydratorContainer\FallbackHydratorContainer; +use Thunder\Serializard\NormalizerContainer\FallbackNormalizerContainer; /** * @author Tomasz Kowalczyk @@ -14,13 +14,13 @@ public function testArrayUnserializeInvalidTypeException() { $format = new ArrayFormat(); $this->setExpectedException('RuntimeException'); - $format->unserialize(new \stdClass(), 'stdClass', new HydratorContainer()); + $format->unserialize(new \stdClass(), 'stdClass', new FallbackHydratorContainer()); } public function testMissingUnserializationHandlerException() { $format = new ArrayFormat(); $this->setExpectedException('RuntimeException'); - $format->unserialize(array(), 'stdClass', new HydratorContainer()); + $format->unserialize(array(), 'stdClass', new FallbackHydratorContainer()); } } diff --git a/tests/HydratorContainerTest.php b/tests/HydratorContainerTest.php index 8400283..04b5133 100644 --- a/tests/HydratorContainerTest.php +++ b/tests/HydratorContainerTest.php @@ -1,7 +1,7 @@ @@ -10,7 +10,7 @@ class HydratorContainerTest extends \PHPUnit_Framework_TestCase { public function testAlias() { - $handlers = new HydratorContainer(); + $handlers = new FallbackHydratorContainer(); $handlers->add('stdClass', 'std', function() { return 'value'; }); $handlers->addAlias('DateTime', 'stdClass'); @@ -20,7 +20,7 @@ public function testAlias() public function testInterface() { - $hydrators = new HydratorContainer(); + $hydrators = new FallbackHydratorContainer(); $interfaceName = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeInterface'; $interfaceTypeA = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeA'; $interfaceTypeB = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeB'; @@ -32,7 +32,7 @@ public function testInterface() public function testInheritance() { - $hydrators = new HydratorContainer(); + $hydrators = new FallbackHydratorContainer(); $ancestorName = 'Thunder\Serializard\Tests\Fake\FakeUserParentParent'; $parentName = 'Thunder\Serializard\Tests\Fake\FakeUserParent'; $userName = 'Thunder\Serializard\Tests\Fake\FakeUser'; @@ -49,7 +49,7 @@ public function testMultipleInterfacesException() $typeAnother = 'Thunder\Serializard\Tests\Fake\Interfaces\AnotherTypeInterface'; $typeMultiple = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeMultiple'; - $hydrators = new HydratorContainer(); + $hydrators = new FallbackHydratorContainer(); $hydrators->add($typeInterface, 'type', function() { return 'multiple'; }); $hydrators->add($typeAnother, 'type', function() { return 'multiple'; }); @@ -59,21 +59,21 @@ public function testMultipleInterfacesException() public function testInvalidClassOrInterfaceName() { - $handlers = new HydratorContainer(); + $handlers = new FallbackHydratorContainer(); $this->setExpectedException('RuntimeException'); $handlers->add('invalid', 'root', function() {}); } public function testAliasForInvalidClass() { - $handlers = new HydratorContainer(); + $handlers = new FallbackHydratorContainer(); $this->setExpectedException('RuntimeException'); $handlers->addAlias('stdClass', 'DateTime'); } public function testInvalidHandler() { - $handlers = new HydratorContainer(); + $handlers = new FallbackHydratorContainer(); $this->setExpectedException('RuntimeException'); $handlers->add('stdClass', 'name', 'invalid'); } diff --git a/tests/NormalizerContainerTest.php b/tests/NormalizerContainerTest.php index 64d6e3a..9f14395 100644 --- a/tests/NormalizerContainerTest.php +++ b/tests/NormalizerContainerTest.php @@ -1,7 +1,7 @@ @@ -10,7 +10,7 @@ class NormalizerContainerTest extends \PHPUnit_Framework_TestCase { public function testAlias() { - $handlers = new NormalizerContainer(); + $handlers = new FallbackNormalizerContainer(); $handlers->add('stdClass', 'std', function() { return 'value'; }); $handlers->addAlias('DateTime', 'stdClass'); @@ -20,7 +20,7 @@ public function testAlias() public function testInterface() { - $hydrators = new NormalizerContainer(); + $hydrators = new FallbackNormalizerContainer(); $interfaceName = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeInterface'; $interfaceTypeA = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeA'; $interfaceTypeB = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeB'; @@ -32,7 +32,7 @@ public function testInterface() public function testInheritance() { - $hydrators = new NormalizerContainer(); + $hydrators = new FallbackNormalizerContainer(); $ancestorName = 'Thunder\Serializard\Tests\Fake\FakeUserParentParent'; $parentName = 'Thunder\Serializard\Tests\Fake\FakeUserParent'; $userName = 'Thunder\Serializard\Tests\Fake\FakeUser'; @@ -49,7 +49,7 @@ public function testMultipleInterfacesException() $typeAnother = 'Thunder\Serializard\Tests\Fake\Interfaces\AnotherTypeInterface'; $typeMultiple = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeMultiple'; - $hydrators = new NormalizerContainer(); + $hydrators = new FallbackNormalizerContainer(); $hydrators->add($typeInterface, 'type', function() { return 'multiple'; }); $hydrators->add($typeAnother, 'type', function() { return 'multiple'; }); @@ -59,21 +59,21 @@ public function testMultipleInterfacesException() public function testInvalidClassOrInterfaceName() { - $handlers = new NormalizerContainer(); + $handlers = new FallbackNormalizerContainer(); $this->setExpectedException('RuntimeException'); $handlers->add('invalid', 'root', function() {}); } public function testAliasForInvalidClass() { - $handlers = new NormalizerContainer(); + $handlers = new FallbackNormalizerContainer(); $this->setExpectedException('RuntimeException'); $handlers->addAlias('stdClass', 'DateTime'); } public function testInvalidHandler() { - $handlers = new NormalizerContainer(); + $handlers = new FallbackNormalizerContainer(); $this->setExpectedException('RuntimeException'); $handlers->add('stdClass', 'name', 'invalid'); } diff --git a/tests/SerializardTest.php b/tests/SerializardTest.php index c481eb3..c3f3715 100644 --- a/tests/SerializardTest.php +++ b/tests/SerializardTest.php @@ -6,10 +6,10 @@ use Thunder\Serializard\Format\XmlFormat; use Thunder\Serializard\Format\YamlFormat; use Thunder\Serializard\FormatContainer\FormatContainer; -use Thunder\Serializard\HydratorContainer\HydratorContainer; +use Thunder\Serializard\HydratorContainer\FallbackHydratorContainer; use Thunder\Serializard\HydratorContainer\HydratorContainerInterface as Hydrators; use Thunder\Serializard\Normalizer\ReflectionNormalizer; -use Thunder\Serializard\NormalizerContainer\NormalizerContainer; +use Thunder\Serializard\NormalizerContainer\FallbackNormalizerContainer; use Thunder\Serializard\Serializard; use Thunder\Serializard\Tests\Fake\FakeTag; use Thunder\Serializard\Tests\Fake\FakeUser; @@ -73,7 +73,7 @@ public function provideExamples() public function testInterfaces() { $interface = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeInterface'; - $normalizers = new NormalizerContainer(); + $normalizers = new FallbackNormalizerContainer(); $normalizers->add($interface, 'type', function(TypeInterface $type) { return array( 'type' => $type->getType(), @@ -81,7 +81,7 @@ public function testInterfaces() ); }); - $hydrators = new HydratorContainer(); + $hydrators = new FallbackHydratorContainer(); $formats = new FormatContainer(); $formats->add('array', new ArrayFormat()); @@ -98,11 +98,11 @@ public function testCycleException($var, $format) $userClass = 'Thunder\Serializard\Tests\Fake\FakeUser'; $tagClass = 'Thunder\Serializard\Tests\Fake\FakeTag'; - $normalizers = new NormalizerContainer(); + $normalizers = new FallbackNormalizerContainer(); $normalizers->add($userClass, 'user', new ReflectionNormalizer()); $normalizers->add($tagClass, 'tag', new ReflectionNormalizer()); - $hydrators = new HydratorContainer(); + $hydrators = new FallbackHydratorContainer(); $formats = new FormatContainer(); $formats->add('xml', new XmlFormat()); @@ -136,7 +136,7 @@ private function getSerializard() $userClass = 'Thunder\Serializard\Tests\Fake\FakeUser'; $tagClass = 'Thunder\Serializard\Tests\Fake\FakeTag'; - $normalizers = new NormalizerContainer(); + $normalizers = new FallbackNormalizerContainer(); $normalizers->add($userClass, 'user', new ReflectionNormalizer()); $normalizers->add($tagClass, 'tag', function(FakeTag $tag) { return array( @@ -145,7 +145,7 @@ private function getSerializard() ); }); - $hydrators = new HydratorContainer(); + $hydrators = new FallbackHydratorContainer(); $hydrators->add($userClass, 'user', function(array $data, Hydrators $handlers) use($tagClass) { $tagHandler = $handlers->getHandler($tagClass); @@ -176,8 +176,8 @@ public function testParent() $formats = new FormatContainer(); $formats->add('array', new ArrayFormat()); - $normalizers = new NormalizerContainer(); - $hydrators = new HydratorContainer(); + $normalizers = new FallbackNormalizerContainer(); + $hydrators = new FallbackHydratorContainer(); $serializard = new Serializard($formats, $normalizers, $hydrators); $normalizers->add($userClass.'ParentParent', 'user', function(FakeUserParentParent $user) { return 'ancestor'; });