/** * * @return array */ public function dismount() { if (is_a($this->object, 'Lightwork\\Foundation\\Model\\Model')) { return $this->object->toArray(); } $array = array(); foreach ($this->reflectionClass->getProperties() as $property) { $property->setAccessible(true); $value = $property->getValue($this->object); if (is_object($value)) { if (is_a($value, 'Lightwork\\Foundation\\Model\\Model')) { $value = $value->toArray(); } else { $reflection = new ReflectionUtility($value); $value = $reflection->dismount(); } } else { if (is_array($value)) { foreach ($value as $k => $v) { if (is_object($v)) { $reflection = new ReflectionUtility($v); $value[$k] = $reflection->dismount(); } } } } $array[$property->getName()] = $value; $property->setAccessible(false); } return $array; }
/** * * @return array */ public function toArray() { $reflection = new ReflectionClass(get_class($this)); $array = array(); do { foreach ($reflection->getProperties() as $property) { if ($property->getName() != 'validators') { $property->setAccessible(true); $value = $property->getValue($this); if (is_object($value)) { if (is_a($value, 'Lightwork\\Foundation\\Model\\Model')) { $value = $value->toArray(); } else { $r = new ReflectionUtility($value); $value = $r->dismount(); } } else { if (is_array($value)) { foreach ($value as $k => $v) { if (is_object($v)) { $r = new ReflectionUtility($v); $value[$k] = $r->dismount(); } } } } $array[$property->getName()] = $value; $property->setAccessible(false); } } } while ($reflection = $reflection->getParentClass()); return $array; }
/** * * @param string $key * @param object $object * @return object */ public function getObject($key, $object) { if (!is_string($key)) { throw new InvalidArgumentException(I18n::text("Argument 'key' is invalid.")); } if (array_key_exists($key, $_REQUEST)) { $reflexUtil = new ReflectionUtility($object); $reflexUtil->mount($_REQUEST[$key]); } return $object; }