This repository has been archived by the owner on May 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 567
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Zend\Stdlib\Hydrator\NamingStrategy\UnderscoreNamingStrategy doc
- Loading branch information
NathanS
authored and
NathanS
committed
May 6, 2015
1 parent
17bccb5
commit 80dcf76
Showing
2 changed files
with
47 additions
and
0 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
41 changes: 41 additions & 0 deletions
41
docs/src/modules/zend.stdlib.hydrator.namingstrategy.underscorenamingstrategy.rst
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,41 @@ | ||
.. _zend.stdlib.hydrator.namingstrategy.underscorenamingstrategy: | ||
|
||
UnderscoreNamingStrategy | ||
======================== | ||
|
||
``Zend\Stdlib\Hydrator\NamingStrategy\UnderscoreNamingStrategy`` Converts snake case strings (e.g. foo_bar_baz) to studly case strings (e.g. fooBarBaz) and vice versa. | ||
|
||
Example Usage | ||
------------- | ||
|
||
.. code:: php | ||
<?php | ||
$namingStrategy = new \Zend\Stdlib\Hydrator\NamingStrategy\UnderscoreNamingStrategy(); | ||
echo $namingStrategy->extract('foo_bar'); // outputs: foo_bar | ||
echo $namingStrategy->extract('Foo_Bar'); // outputs: foo_bar | ||
echo $namingStrategy->extract('FooBar'); // outputs: foo_bar | ||
echo $namingStrategy->hydrate('fooBar'); // outputs: fooBar | ||
echo $namingStrategy->hydrate('FooBar'); // outputs: fooBar | ||
echo $namingStrategy->hydrate('Foo_Bar'); // outputs: fooBar | ||
?> | ||
This strategy can be used in hydrators to dictate how keys should be mapped. | ||
|
||
.. code:: php | ||
<?php | ||
class Foo { | ||
public $fooBar; | ||
} | ||
$hydrator = new \Zend\Stdlib\Hydrator\ObjectProperty(); | ||
$hydrator->setNamingStrategy(new \Zend\Stdlib\Hydrator\NamingStrategy\UnderscoreNamingStrategy()); | ||
$foo = new Foo(); | ||
$hydrator->hydrate(['foo_bar' => 123],$foo); | ||
print_r($foo); // Foo Object ( [fooBar] => 123 ) | ||
print_r($hydrator->extract($foo)); // Array ( [foo_bar] => 123 ) | ||
?> |