fix calendar css, take 2. (#213)
[openemr.git] / interface / modules / zend_modules / library / Zend / Stdlib / Hydrator / ObjectProperty.php
blobc9f5260a5e8e0d8c4c4bc4f56a4c0ff92621296b
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-2015 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;
13 use ReflectionClass;
14 use ReflectionProperty;
16 class ObjectProperty extends AbstractHydrator
18 /**
19 * @var array[] indexed by class name and then property name
21 private static $skippedPropertiesCache = array();
23 /**
24 * {@inheritDoc}
26 * Extracts the accessible non-static properties of the given $object.
28 * @throws Exception\BadMethodCallException for a non-object $object
30 public function extract($object)
32 if (!is_object($object)) {
33 throw new Exception\BadMethodCallException(
34 sprintf('%s expects the provided $object to be a PHP object)', __METHOD__)
38 $data = get_object_vars($object);
39 $filter = $this->getFilter();
41 foreach ($data as $name => $value) {
42 // Filter keys, removing any we don't want
43 if (! $filter->filter($name)) {
44 unset($data[$name]);
45 continue;
48 // Replace name if extracted differ
49 $extracted = $this->extractName($name, $object);
51 if ($extracted !== $name) {
52 unset($data[$name]);
53 $name = $extracted;
56 $data[$name] = $this->extractValue($name, $value, $object);
59 return $data;
62 /**
63 * {@inheritDoc}
65 * Hydrate an object by populating public properties
67 * Hydrates an object by setting public properties of the object.
69 * @throws Exception\BadMethodCallException for a non-object $object
71 public function hydrate(array $data, $object)
73 if (!is_object($object)) {
74 throw new Exception\BadMethodCallException(
75 sprintf('%s expects the provided $object to be a PHP object)', __METHOD__)
79 $properties = & self::$skippedPropertiesCache[get_class($object)];
81 if (! isset($properties)) {
82 $reflection = new ReflectionClass($object);
83 $properties = array_fill_keys(
84 array_map(
85 function (ReflectionProperty $property) {
86 return $property->getName();
88 $reflection->getProperties(
89 ReflectionProperty::IS_PRIVATE
90 + ReflectionProperty::IS_PROTECTED
91 + ReflectionProperty::IS_STATIC
94 true
98 foreach ($data as $name => $value) {
99 $property = $this->hydrateName($name, $data);
101 if (isset($properties[$property])) {
102 continue;
105 $object->$property = $this->hydrateValue($property, $value, $data);
108 return $object;