/**
  * @inheritdoc
  */
 public function accept(ResourceIdentifierInterface $identifier, $record = null, $key = null, ResourceInterface $resource = null)
 {
     if (!$this->current) {
         return true;
     }
     return $this->current->getType() == $identifier->getType() && $this->current->getId() == $identifier->getId();
 }
 /**
  * @inheritDoc
  */
 public function get(ResourceIdentifierInterface $identifier)
 {
     /** @var ResourceInterface $resource */
     foreach ($this as $resource) {
         if ($identifier->isSame($resource->getIdentifier())) {
             return $resource;
         }
     }
     throw new RuntimeException('No matching resource in collection: ' . $identifier->toString());
 }
 /**
  * @param ResourceIdentifierInterface $identifier
  * @return object|null
  *      the record, or null if it does not exist.
  */
 public function find(ResourceIdentifierInterface $identifier)
 {
     $model = $this->resolve($identifier->getType());
     $key = $this->resolveQualifiedKeyName($model, $identifier->getType());
     return $this->newQuery($model)->where($key, $identifier->getId())->first();
 }
 /**
  * @inheritdoc
  */
 public function relationshipNotAcceptable(ResourceIdentifierInterface $identifier, $relationshipKey = null, $error = null)
 {
     $base = $this->repository->errorWithPointer(self::RELATIONSHIP_NOT_ACCEPTABLE, $relationshipKey ? P::relationship($relationshipKey) : P::data(), ['type' => $identifier->getType(), 'id' => $identifier->getId()]);
     $errors = new MutableErrorCollection();
     /** @var MutableErrorInterface $err */
     foreach (MutableErrorCollection::cast($error ?: $base) as $err) {
         $add = clone $base;
         $errors->add($add->merge($err));
     }
     return $errors;
 }
 /**
  * RecordNotFoundException constructor.
  * @param ResourceIdentifierInterface $identifier
  * @param int $code
  * @param Exception|null $previous
  */
 public function __construct(ResourceIdentifierInterface $identifier, $code = 0, Exception $previous = null)
 {
     $message = sprintf('Cannot find Record %s:%s', $identifier->getType(), $identifier->getId());
     parent::__construct($message, $code, $previous);
     $this->identifier = $identifier;
 }
 /**
  * @param ResourceIdentifierInterface $identifier
  * @param string|null $key
  * @return bool
  */
 protected function validateIdentifier(ResourceIdentifierInterface $identifier, $key = null)
 {
     $valid = true;
     /** Must have a type */
     if (!$identifier->hasType()) {
         $this->addError($this->errorFactory->memberRequired(ResourceIdentifierInterface::TYPE, $key ? P::relationshipData($key) : P::data()));
         $valid = false;
     } elseif (!$this->isSupportedType($identifier->getType())) {
         $this->addError($this->errorFactory->relationshipUnsupportedType($this->expectedTypes, $identifier->getType(), $key));
         $valid = false;
     }
     /** Must have an id */
     if (!$identifier->hasId()) {
         $this->addError($this->errorFactory->memberRequired(ResourceIdentifierInterface::ID, $key ? P::relationshipId($key) : P::data()));
         $valid = false;
     }
     return $valid;
 }
Esempio n. 7
0
 /**
  * @param ResourceIdentifierInterface $identifier
  * @return object|bool|null
  */
 private function lookup(ResourceIdentifierInterface $identifier)
 {
     $key = $identifier->toString();
     return isset($this->map[$key]) ? $this->map[$key] : null;
 }
 /**
  * @inheritDoc
  */
 public function isSame(ResourceIdentifierInterface $identifier)
 {
     return $this->getType() === $identifier->getType() && $this->getId() == $identifier->getId();
 }