3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Stdlib\Hydrator
;
12 use Zend\Stdlib\Exception
;
14 class ObjectProperty
extends AbstractHydrator
17 * Extract values from an object
19 * Extracts the accessible non-static properties of the given $object.
21 * @param object $object
23 * @throws Exception\BadMethodCallException for a non-object $object
25 public function extract($object)
27 if (!is_object($object)) {
28 throw new Exception\
BadMethodCallException(sprintf(
29 '%s expects the provided $object to be a PHP object)', __METHOD__
33 $data = get_object_vars($object);
35 $filter = $this->getFilter();
36 foreach ($data as $name => $value) {
37 // Filter keys, removing any we don't want
38 if (!$filter->filter($name)) {
43 $data[$name] = $this->extractValue($name, $value);
50 * Hydrate an object by populating public properties
52 * Hydrates an object by setting public properties of the object.
55 * @param object $object
57 * @throws Exception\BadMethodCallException for a non-object $object
59 public function hydrate(array $data, $object)
61 if (!is_object($object)) {
62 throw new Exception\
BadMethodCallException(sprintf(
63 '%s expects the provided $object to be a PHP object)', __METHOD__
66 foreach ($data as $property => $value) {
67 $object->$property = $this->hydrateValue($property, $value, $data);