Skip to content
This repository was archived by the owner on May 24, 2018. It is now read-only.

Feature/zend.stdlib.hydrator.namingstrategy.mapnamingstrategy #1479

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
# built documents.
#
# The short X.Y version.
version = '2.4'
version = '2.5'
# The full version, including alpha/beta/rc tags.
release = '2.4.1dev'
release = '2.5.0dev'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 2 additions & 0 deletions docs/src/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ Programmer's Reference Guide of Zend Framework 2
modules/zend.stdlib.hydrator.filter
modules/zend.stdlib.hydrator.strategy
modules/zend.stdlib.hydrator.aggregate
modules/zend.stdlib.hydrator.namingstrategy.mapnamingstrategy
modules/zend.tag.introduction
modules/zend.tag.cloud
modules/zend.test.introduction
Expand Down Expand Up @@ -895,6 +896,7 @@ Zend\\Stdlib
* :doc:`modules/zend.stdlib.hydrator.filter`
* :doc:`modules/zend.stdlib.hydrator.strategy`
* :doc:`modules/zend.stdlib.hydrator.aggregate`
* :doc:`modules/zend.stdlib.hydrator.namingstrategy.mapnamingstrategy`

.. _zend.tag:

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.. _zend.stdlib.hydrator.namingstrategy.mapnamingstrategy:

MapNamingStrategy
=================

``Zend\Stdlib\Hydrator\NamingStrategy\MapNamingStrategy`` Maps keys based on a given map.

Example Usage
-------------

.. code:: php

<?php
$namingStrategy = new \Zend\Stdlib\Hydrator\NamingStrategy\MapNamingStrategy([
'foo' => 'bar',
'baz' => 'bash'
]);
echo $namingStrategy->hydrate('foo'); // outputs: foo
echo $namingStrategy->hydrate('baz'); // outputs: bash

echo $namingStrategy->extract('bar'); // outputs: foo
echo $namingStrategy->extract('bash'); // outputs: baz
?>

This strategy can be used in hydrators to dictate how keys should be mapped:

.. code:: php

<?php
class Foo {
public $bar;
}

$namingStrategy = new \Zend\Stdlib\Hydrator\NamingStrategy\MapNamingStrategy([
'foo' => 'bar',
'baz' => 'bash'
]);
$hydrator = new \Zend\Stdlib\Hydrator\ObjectProperty();
$hydrator->setNamingStrategy($namingStrategy);

$foo = new Foo();
$hydrator->hydrate(['foo' => 123],$foo);

print_r($foo); // Foo Object ( [bar] => 123 )
print_r($hydrator->extract($foo)); // Array ( [foo] => 123 )
?>
2 changes: 1 addition & 1 deletion docs/src/modules/zend.stdlib.hydrator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ HydratorInterface
*
* @param array $data
* @param object $object
* @return void
* @return object
*/
public function hydrate(array $data, $object);
}
Expand Down