getInstance() public method

public getInstance ( ) : object
return object
Example #1
0
 /**
  * Creates a new instance which will contain the given object. If an object with the same reference already exists,
  * it will be overridden by the new object.
  * 
  * @param ObjectInterface $object
  *
  * @return self
  */
 public function with(ObjectInterface $object) : self
 {
     $clone = clone $this;
     $clone->objects[$object->getId()] = $object;
     $clone->array[$object->getId()] = $object->getInstance();
     return $clone;
 }
 /**
  * {@inheritdoc}
  *
  * @throws NoSuchPropertyException
  * @throws InaccessiblePropertyException
  * @throws InvalidArgumentException When the typehint does not match for example
  * @throws HydrationException
  */
 public function hydrate(ObjectInterface $object, Property $property, GenerationContext $context) : ObjectInterface
 {
     $instance = $object->getInstance();
     try {
         $this->propertyAccessor->setValue($instance, $property->getName(), $property->getValue());
     } catch (SymfonyNoSuchPropertyException $exception) {
         throw HydrationExceptionFactory::createForCouldNotHydrateObjectWithProperty($object, $property, 0, $exception);
     } catch (SymfonyAccessException $exception) {
         throw HydrationExceptionFactory::createForInaccessibleProperty($object, $property, 0, $exception);
     } catch (SymfonyInvalidArgumentException $exception) {
         throw HydrationExceptionFactory::createForInvalidProperty($object, $property, 0, $exception);
     } catch (SymfonyPropertyAccessException $exception) {
         throw HydrationExceptionFactory::create($object, $property, 0, $exception);
     }
     return new SimpleObject($object->getId(), $instance);
 }
Example #3
0
 /**
  * @inheritdoc
  */
 public function getInstance()
 {
     return $this->object->getInstance();
 }
 public static function createForCouldNotHydrateObjectWithProperty(ObjectInterface $object, Property $property, int $code = 0, \Throwable $previous = null) : NoSuchPropertyException
 {
     return new NoSuchPropertyException(sprintf('Could not hydrate the property "%s" of the object "%s" (class: %s).', $property->getName(), $object->getId(), get_class($object->getInstance())), $code, $previous);
 }