Documentation

MapNamingStrategy — Zend Framework 2 2.4.9 documentation

Zend\Stdlib

MapNamingStrategy

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

Basic Usage

1
2
3
4
5
6
7
8
9
 $namingStrategy = new Zend\Stdlib\Hydrator\NamingStrategy\MapNamingStrategy(array(
     'foo' => 'bar',
     'baz' => 'bash'
 ));
 echo $namingStrategy->hydrate('foo'); // outputs: bar
 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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
 class Foo
 {
     public $bar;
 }

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

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

 print_r($foo); // Foo Object ( [bar] => 123 )
 print_r($hydrator->extract($foo)); // Array ( [foo] => 123 )

Copyright

© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts