Skip to content

Commit

Permalink
infer accessor order if not explicitly set in YML
Browse files Browse the repository at this point in the history
The accessor order is now inferred if a ``custom_accessor_order`` is given and
``accessor_order`` has not been explicitly defined:

```
SomeClass:
    accessor_order: custom # Can be ommitted now if custom_accessor_order is set.
    custom_accessor_order: ["a", "b", "c"]
```
  • Loading branch information
schmittjoh committed Jan 22, 2014
1 parent 5f9fb57 commit 740c63a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/JMS/Serializer/Metadata/Driver/YamlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ protected function getExtension()

private function addClassProperties(ClassMetadata $metadata, array $config)
{
if (isset($config['custom_accessor_order']) && ! isset($config['accessor_order'])) {
$config['accessor_order'] = 'custom';
}

if (isset($config['accessor_order'])) {
$metadata->setAccessorOrder($config['accessor_order'], isset($config['custom_accessor_order']) ? $config['custom_accessor_order'] : array());
}
Expand Down
6 changes: 6 additions & 0 deletions tests/JMS/Serializer/Tests/Metadata/Driver/YamlDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@

class YamlDriverTest extends BaseDriverTest
{
public function testAccessorOrderIsInferred()
{
$m = $this->getDriverForSubDir('accessor_inferred')->loadMetadataForClass(new \ReflectionClass('JMS\Serializer\Tests\Fixtures\Person'));
$this->assertEquals(array('age', 'name'), array_keys($m->propertyMetadata));
}

public function testShortExposeSyntax()
{
$m = $this->getDriverForSubDir('short_expose')->loadMetadataForClass(new \ReflectionClass('JMS\Serializer\Tests\Fixtures\Person'));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
JMS\Serializer\Tests\Fixtures\Person:
custom_accessor_order: ["age", "name"]

properties:
age: ~
name: ~

0 comments on commit 740c63a

Please sign in to comment.