1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace Zend\Stdlib\Hydrator;
- use Zend\Stdlib\Exception;
- class ObjectProperty extends AbstractHydrator
- {
-
- public function extract($object)
- {
- if (!is_object($object)) {
- throw new Exception\BadMethodCallException(sprintf(
- '%s expects the provided $object to be a PHP object)', __METHOD__
- ));
- }
- $data = get_object_vars($object);
- $filter = $this->getFilter();
- foreach ($data as $name => $value) {
-
- if (!$filter->filter($name)) {
- unset($data[$name]);
- continue;
- }
-
- $extracted = $this->extractName($name, $object);
- if ($extracted !== $name) {
- unset($data[$name]);
- $name = $extracted;
- }
- $data[$name] = $this->extractValue($name, $value, $object);
- }
- return $data;
- }
-
- public function hydrate(array $data, $object)
- {
- if (!is_object($object)) {
- throw new Exception\BadMethodCallException(sprintf(
- '%s expects the provided $object to be a PHP object)', __METHOD__
- ));
- }
- foreach ($data as $name => $value) {
- $property = $this->hydrateName($name, $data);
- $object->$property = $this->hydrateValue($property, $value, $data);
- }
- return $object;
- }
- }
|