Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Stdlib / Hydrator / ObjectProperty.php
blobc0bf569a2fed3e96e0584ad8b77e5059cf3590dd
1 <?php
2 /**
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
8 */
10 namespace Zend\Stdlib\Hydrator;
12 use Zend\Stdlib\Exception;
14 class ObjectProperty extends AbstractHydrator
16 /**
17 * Extract values from an object
19 * Extracts the accessible non-static properties of the given $object.
21 * @param object $object
22 * @return array
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__
30 ));
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)) {
39 unset($data[$name]);
40 continue;
42 // Extract data
43 $data[$name] = $this->extractValue($name, $value);
46 return $data;
49 /**
50 * Hydrate an object by populating public properties
52 * Hydrates an object by setting public properties of the object.
54 * @param array $data
55 * @param object $object
56 * @return 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__
64 ));
66 foreach ($data as $property => $value) {
67 $object->$property = $this->hydrateValue($property, $value, $data);
69 return $object;