Skip to content

Commit 92445df

Browse files
committed
renamed hydrator and normalizer container, updated README
1 parent b85ec40 commit 92445df

8 files changed

Lines changed: 46 additions & 44 deletions

File tree

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,22 @@ Serialization is controlled by registering callables used in normalization phase
4242
```php
4343
use Thunder\Serializard\Format\JsonFormat;
4444
use Thunder\Serializard\FormatContainer\FormatContainer;
45-
use Thunder\Serializard\HandlerContainer\HandlerContainer;
45+
use Thunder\Serializard\HydratorContainer\FallbackHydratorContainer;
46+
use Thunder\Serializard\NormalizerContainer\FallbackNormalizerContainer;
4647
use Thunder\Serializard\Serializard;
4748

4849
$formats = new FormatContainer();
4950
$formats->add('json', new JsonFormat());
5051

51-
$normalizers = new HandlerContainer();
52+
$normalizers = new FallbackNormalizerContainer();
5253
$normalizers->add(User::class, 'user', function(User $user) {
5354
return [
5455
'id' => $user->getId(),
5556
'name' => $user->getName(),
5657
];
5758
});
5859

59-
$hydrators = new HandlerContainer();
60+
$hydrators = new FallbackHydratorContainer();
6061

6162
$serializard = new Serializard($formats, $normalizers, $hydrators);
6263
echo $serializard->serialize(new User(1, 'Thomas'), 'json');
@@ -76,15 +77,16 @@ Unserialization can be controlled by registering callables able to reconstruct o
7677
```php
7778
use Thunder\Serializard\Format\JsonFormat;
7879
use Thunder\Serializard\FormatContainer\FormatContainer;
79-
use Thunder\Serializard\HandlerContainer\HandlerContainer;
80+
use Thunder\Serializard\HydratorContainer\FallbackHydratorContainer;
81+
use Thunder\Serializard\NormalizerContainer\FallbackNormalizerContainer;
8082
use Thunder\Serializard\Serializard;
8183

8284
$formats = new FormatContainer();
8385
$formats->add('json', new JsonFormat());
8486

85-
$normalizers = new HandlerContainer();
87+
$normalizers = new FallbackNormalizerContainer();
8688

87-
$hydrators = new HandlerContainer();
89+
$hydrators = new FallbackHydratorContainer();
8890
$hydrators->add(User::class, 'user', function(array $data) {
8991
return new User($data['id'], $data['name']);
9092
});

src/HydratorContainer/HydratorContainer.php renamed to src/HydratorContainer/FallbackHydratorContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/**
55
* @author Tomasz Kowalczyk <tomasz@kowalczyk.cc>
66
*/
7-
final class HydratorContainer implements HydratorContainerInterface
7+
final class FallbackHydratorContainer implements HydratorContainerInterface
88
{
99
private $handlers = array();
1010
private $interfaces = array();

src/NormalizerContainer/NormalizerContainer.php renamed to src/NormalizerContainer/FallbackNormalizerContainer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/**
55
* @author Tomasz Kowalczyk <tomasz@kowalczyk.cc>
66
*/
7-
final class NormalizerContainer implements NormalizerContainerInterface
7+
final class FallbackNormalizerContainer implements NormalizerContainerInterface
88
{
99
private $handlers = array();
1010
private $interfaces = array();

src/SerializardFacade.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,25 @@
77
use Thunder\Serializard\Format\XmlFormat;
88
use Thunder\Serializard\Format\YamlFormat;
99
use Thunder\Serializard\FormatContainer\FormatContainer;
10-
use Thunder\Serializard\HydratorContainer\HydratorContainer;
11-
use Thunder\Serializard\NormalizerContainer\NormalizerContainer;
10+
use Thunder\Serializard\HydratorContainer\FallbackHydratorContainer;
11+
use Thunder\Serializard\NormalizerContainer\FallbackNormalizerContainer;
1212

1313
/**
1414
* @author Tomasz Kowalczyk <tomasz@kowalczyk.cc>
1515
*/
1616
final class SerializardFacade
1717
{
18-
/** @var NormalizerContainer */
18+
/** @var FallbackNormalizerContainer */
1919
private $normalizers;
20-
/** @var HydratorContainer */
20+
/** @var FallbackHydratorContainer */
2121
private $hydrators;
2222
/** @var FormatContainer */
2323
private $formats;
2424

2525
public function __construct()
2626
{
27-
$this->normalizers = new NormalizerContainer();
28-
$this->hydrators = new HydratorContainer();
27+
$this->normalizers = new FallbackNormalizerContainer();
28+
$this->hydrators = new FallbackHydratorContainer();
2929

3030
$formats = new FormatContainer();
3131
$formats->add('json', new JsonFormat());

tests/FormatTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
namespace Thunder\Serializard\Tests;
33

44
use Thunder\Serializard\Format\ArrayFormat;
5-
use Thunder\Serializard\HydratorContainer\HydratorContainer;
6-
use Thunder\Serializard\NormalizerContainer\NormalizerContainer;
5+
use Thunder\Serializard\HydratorContainer\FallbackHydratorContainer;
6+
use Thunder\Serializard\NormalizerContainer\FallbackNormalizerContainer;
77

88
/**
99
* @author Tomasz Kowalczyk <tomasz@kowalczyk.cc>
@@ -14,13 +14,13 @@ public function testArrayUnserializeInvalidTypeException()
1414
{
1515
$format = new ArrayFormat();
1616
$this->setExpectedException('RuntimeException');
17-
$format->unserialize(new \stdClass(), 'stdClass', new HydratorContainer());
17+
$format->unserialize(new \stdClass(), 'stdClass', new FallbackHydratorContainer());
1818
}
1919

2020
public function testMissingUnserializationHandlerException()
2121
{
2222
$format = new ArrayFormat();
2323
$this->setExpectedException('RuntimeException');
24-
$format->unserialize(array(), 'stdClass', new HydratorContainer());
24+
$format->unserialize(array(), 'stdClass', new FallbackHydratorContainer());
2525
}
2626
}

tests/HydratorContainerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace Thunder\Serializard\Tests;
33

4-
use Thunder\Serializard\HydratorContainer\HydratorContainer;
4+
use Thunder\Serializard\HydratorContainer\FallbackHydratorContainer;
55

66
/**
77
* @author Tomasz Kowalczyk <tomasz@kowalczyk.cc>
@@ -10,7 +10,7 @@ class HydratorContainerTest extends \PHPUnit_Framework_TestCase
1010
{
1111
public function testAlias()
1212
{
13-
$handlers = new HydratorContainer();
13+
$handlers = new FallbackHydratorContainer();
1414
$handlers->add('stdClass', 'std', function() { return 'value'; });
1515
$handlers->addAlias('DateTime', 'stdClass');
1616

@@ -20,7 +20,7 @@ public function testAlias()
2020

2121
public function testInterface()
2222
{
23-
$hydrators = new HydratorContainer();
23+
$hydrators = new FallbackHydratorContainer();
2424
$interfaceName = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeInterface';
2525
$interfaceTypeA = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeA';
2626
$interfaceTypeB = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeB';
@@ -32,7 +32,7 @@ public function testInterface()
3232

3333
public function testInheritance()
3434
{
35-
$hydrators = new HydratorContainer();
35+
$hydrators = new FallbackHydratorContainer();
3636
$ancestorName = 'Thunder\Serializard\Tests\Fake\FakeUserParentParent';
3737
$parentName = 'Thunder\Serializard\Tests\Fake\FakeUserParent';
3838
$userName = 'Thunder\Serializard\Tests\Fake\FakeUser';
@@ -49,7 +49,7 @@ public function testMultipleInterfacesException()
4949
$typeAnother = 'Thunder\Serializard\Tests\Fake\Interfaces\AnotherTypeInterface';
5050
$typeMultiple = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeMultiple';
5151

52-
$hydrators = new HydratorContainer();
52+
$hydrators = new FallbackHydratorContainer();
5353
$hydrators->add($typeInterface, 'type', function() { return 'multiple'; });
5454
$hydrators->add($typeAnother, 'type', function() { return 'multiple'; });
5555

@@ -59,21 +59,21 @@ public function testMultipleInterfacesException()
5959

6060
public function testInvalidClassOrInterfaceName()
6161
{
62-
$handlers = new HydratorContainer();
62+
$handlers = new FallbackHydratorContainer();
6363
$this->setExpectedException('RuntimeException');
6464
$handlers->add('invalid', 'root', function() {});
6565
}
6666

6767
public function testAliasForInvalidClass()
6868
{
69-
$handlers = new HydratorContainer();
69+
$handlers = new FallbackHydratorContainer();
7070
$this->setExpectedException('RuntimeException');
7171
$handlers->addAlias('stdClass', 'DateTime');
7272
}
7373

7474
public function testInvalidHandler()
7575
{
76-
$handlers = new HydratorContainer();
76+
$handlers = new FallbackHydratorContainer();
7777
$this->setExpectedException('RuntimeException');
7878
$handlers->add('stdClass', 'name', 'invalid');
7979
}

tests/NormalizerContainerTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
namespace Thunder\Serializard\Tests;
33

4-
use Thunder\Serializard\NormalizerContainer\NormalizerContainer;
4+
use Thunder\Serializard\NormalizerContainer\FallbackNormalizerContainer;
55

66
/**
77
* @author Tomasz Kowalczyk <tomasz@kowalczyk.cc>
@@ -10,7 +10,7 @@ class NormalizerContainerTest extends \PHPUnit_Framework_TestCase
1010
{
1111
public function testAlias()
1212
{
13-
$handlers = new NormalizerContainer();
13+
$handlers = new FallbackNormalizerContainer();
1414
$handlers->add('stdClass', 'std', function() { return 'value'; });
1515
$handlers->addAlias('DateTime', 'stdClass');
1616

@@ -20,7 +20,7 @@ public function testAlias()
2020

2121
public function testInterface()
2222
{
23-
$hydrators = new NormalizerContainer();
23+
$hydrators = new FallbackNormalizerContainer();
2424
$interfaceName = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeInterface';
2525
$interfaceTypeA = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeA';
2626
$interfaceTypeB = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeB';
@@ -32,7 +32,7 @@ public function testInterface()
3232

3333
public function testInheritance()
3434
{
35-
$hydrators = new NormalizerContainer();
35+
$hydrators = new FallbackNormalizerContainer();
3636
$ancestorName = 'Thunder\Serializard\Tests\Fake\FakeUserParentParent';
3737
$parentName = 'Thunder\Serializard\Tests\Fake\FakeUserParent';
3838
$userName = 'Thunder\Serializard\Tests\Fake\FakeUser';
@@ -49,7 +49,7 @@ public function testMultipleInterfacesException()
4949
$typeAnother = 'Thunder\Serializard\Tests\Fake\Interfaces\AnotherTypeInterface';
5050
$typeMultiple = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeMultiple';
5151

52-
$hydrators = new NormalizerContainer();
52+
$hydrators = new FallbackNormalizerContainer();
5353
$hydrators->add($typeInterface, 'type', function() { return 'multiple'; });
5454
$hydrators->add($typeAnother, 'type', function() { return 'multiple'; });
5555

@@ -59,21 +59,21 @@ public function testMultipleInterfacesException()
5959

6060
public function testInvalidClassOrInterfaceName()
6161
{
62-
$handlers = new NormalizerContainer();
62+
$handlers = new FallbackNormalizerContainer();
6363
$this->setExpectedException('RuntimeException');
6464
$handlers->add('invalid', 'root', function() {});
6565
}
6666

6767
public function testAliasForInvalidClass()
6868
{
69-
$handlers = new NormalizerContainer();
69+
$handlers = new FallbackNormalizerContainer();
7070
$this->setExpectedException('RuntimeException');
7171
$handlers->addAlias('stdClass', 'DateTime');
7272
}
7373

7474
public function testInvalidHandler()
7575
{
76-
$handlers = new NormalizerContainer();
76+
$handlers = new FallbackNormalizerContainer();
7777
$this->setExpectedException('RuntimeException');
7878
$handlers->add('stdClass', 'name', 'invalid');
7979
}

tests/SerializardTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
use Thunder\Serializard\Format\XmlFormat;
77
use Thunder\Serializard\Format\YamlFormat;
88
use Thunder\Serializard\FormatContainer\FormatContainer;
9-
use Thunder\Serializard\HydratorContainer\HydratorContainer;
9+
use Thunder\Serializard\HydratorContainer\FallbackHydratorContainer;
1010
use Thunder\Serializard\HydratorContainer\HydratorContainerInterface as Hydrators;
1111
use Thunder\Serializard\Normalizer\ReflectionNormalizer;
12-
use Thunder\Serializard\NormalizerContainer\NormalizerContainer;
12+
use Thunder\Serializard\NormalizerContainer\FallbackNormalizerContainer;
1313
use Thunder\Serializard\Serializard;
1414
use Thunder\Serializard\Tests\Fake\FakeTag;
1515
use Thunder\Serializard\Tests\Fake\FakeUser;
@@ -73,15 +73,15 @@ public function provideExamples()
7373
public function testInterfaces()
7474
{
7575
$interface = 'Thunder\Serializard\Tests\Fake\Interfaces\TypeInterface';
76-
$normalizers = new NormalizerContainer();
76+
$normalizers = new FallbackNormalizerContainer();
7777
$normalizers->add($interface, 'type', function(TypeInterface $type) {
7878
return array(
7979
'type' => $type->getType(),
8080
'value' => $type->getValue(),
8181
);
8282
});
8383

84-
$hydrators = new HydratorContainer();
84+
$hydrators = new FallbackHydratorContainer();
8585

8686
$formats = new FormatContainer();
8787
$formats->add('array', new ArrayFormat());
@@ -98,11 +98,11 @@ public function testCycleException($var, $format)
9898
$userClass = 'Thunder\Serializard\Tests\Fake\FakeUser';
9999
$tagClass = 'Thunder\Serializard\Tests\Fake\FakeTag';
100100

101-
$normalizers = new NormalizerContainer();
101+
$normalizers = new FallbackNormalizerContainer();
102102
$normalizers->add($userClass, 'user', new ReflectionNormalizer());
103103
$normalizers->add($tagClass, 'tag', new ReflectionNormalizer());
104104

105-
$hydrators = new HydratorContainer();
105+
$hydrators = new FallbackHydratorContainer();
106106

107107
$formats = new FormatContainer();
108108
$formats->add('xml', new XmlFormat());
@@ -136,7 +136,7 @@ private function getSerializard()
136136
$userClass = 'Thunder\Serializard\Tests\Fake\FakeUser';
137137
$tagClass = 'Thunder\Serializard\Tests\Fake\FakeTag';
138138

139-
$normalizers = new NormalizerContainer();
139+
$normalizers = new FallbackNormalizerContainer();
140140
$normalizers->add($userClass, 'user', new ReflectionNormalizer());
141141
$normalizers->add($tagClass, 'tag', function(FakeTag $tag) {
142142
return array(
@@ -145,7 +145,7 @@ private function getSerializard()
145145
);
146146
});
147147

148-
$hydrators = new HydratorContainer();
148+
$hydrators = new FallbackHydratorContainer();
149149
$hydrators->add($userClass, 'user', function(array $data, Hydrators $handlers) use($tagClass) {
150150
$tagHandler = $handlers->getHandler($tagClass);
151151

@@ -176,8 +176,8 @@ public function testParent()
176176

177177
$formats = new FormatContainer();
178178
$formats->add('array', new ArrayFormat());
179-
$normalizers = new NormalizerContainer();
180-
$hydrators = new HydratorContainer();
179+
$normalizers = new FallbackNormalizerContainer();
180+
$hydrators = new FallbackHydratorContainer();
181181
$serializard = new Serializard($formats, $normalizers, $hydrators);
182182

183183
$normalizers->add($userClass.'ParentParent', 'user', function(FakeUserParentParent $user) { return 'ancestor'; });

0 commit comments

Comments
 (0)