public function createProperty($name, $value) { $metadata = new PropertyMetadata(); $metadata->setName($name); $property = new Property($metadata, $value); return $property; }
public static function fromInstance($name = null, $instance) { $className = get_class($instance); $class = new \ReflectionClass($className); $metadata = new ObjectMetadata(); $metadata->setClassName($className); $metadata->setName($name); $properties = array(); $allProperties = \ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED | \ReflectionProperty::IS_PRIVATE; $reflectionProperties = $class->getProperties($allProperties); foreach ($reflectionProperties as $prop) { $prop->setAccessible(true); $name = $prop->getName(); $value = $prop->getValue($instance); $type = gettype($value) === 'object' ? get_class($value) : gettype($value); $propertyMeta = new PropertyMetadata(); $propertyMeta->setName($name); $propertyMeta->setType($type); $property = new Property($propertyMeta); $property->setValue($value); array_push($properties, $property); } $object = new Object($metadata); $object->setInstance($instance); $object->setProperties($properties); return $object; }