/** * @param object $object * * @param array $fieldsTobeFiltered * * @return array */ public function extract($object, $fieldsToInclude = []) { if (!is_object($object)) { return $object; } $hydrator = new Reflection(); $hydrator->addFilter('exclude', function ($property) use($fieldsToInclude) { if (0 == count($fieldsToInclude)) { return true; } if (!in_array($property, $fieldsToInclude)) { return false; } return true; }, FilterComposite::CONDITION_AND); $resultCopy = $result = $hydrator->extract($object); array_walk($resultCopy, function (&$value, $key) use(&$result) { if ($value instanceof AbstractModel) { $value = $value->getArrayCopy(); } if (is_null($value)) { unset($result[$key]); } if (is_array($value)) { array_walk($value, function (&$value) { $value = $this->extract($value); }); } }); return $result; }
/** * Creates a SettingsEntityHydrator */ public function __construct() { parent::__construct(); $this->addFilter('ignoreInternalProperties', function ($property) { return "_" != $property[0]; }); }
public function __construct($repOrganization, $repOrganizationName, $repOrganizationImage) { parent::__construct(); $this->repOrganization = $repOrganization; $this->repOrganizationName = $repOrganizationName; $this->repOrganizationImage = $repOrganizationImage; }
/** * Hydrate $object with the provided $data. * * @param array $data * @param object $object * @return object */ public function hydrate(array $data, $object) { $reflProperties = self::getReflProperties($object); foreach ($data as $key => $value) { if (strpos($key, '/') === 0) { $resource = new Resource(); $hydrator = new Reflection(); $hydrator->hydrate($value, $resource); /** @var Resources $resources */ $resources = $reflProperties['resources']->getValue($object); $resources->attach($resource, $key); // $resources->attach($this->hydrateValue('resource', $value, $data)); // $reflProperties['resources']->setValue($object, $resources); } else { $name = $this->hydrateName($key, $data); if (isset($reflProperties[$name])) { $reflProperties[$name]->setValue($object, $this->hydrateValue($name, $value, $data)); } } } return $object; }