WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface::createRelationshipTypeInappropriateException PHP Method

createRelationshipTypeInappropriateException() public method

public createRelationshipTypeInappropriateException ( string $relationshipName, string $currentRelationshipType, string $expectedRelationshipType ) : Exception
$relationshipName string
$currentRelationshipType string
$expectedRelationshipType string
return Exception
    public function createRelationshipTypeInappropriateException($relationshipName, $currentRelationshipType, $expectedRelationshipType);

Usage Example

示例#1
0
 /**
  * @param string $relationshipName
  * @param \Closure $hydrator
  * @param mixed $domainObject
  * @param ToOneRelationship|ToManyRelationship $relationshipObject
  * @param array $data
  * @param \WoohooLabs\Yin\JsonApi\Exception\ExceptionFactoryInterface $exceptionFactory
  * @return mixed
  * @throws \WoohooLabs\Yin\JsonApi\Exception\RelationshipTypeInappropriate
  * @throws \Exception
  */
 protected function getRelationshipHydratorResult($relationshipName, \Closure $hydrator, $domainObject, $relationshipObject, array $data, ExceptionFactoryInterface $exceptionFactory)
 {
     // Checking if the current and expected relationship types match
     $relationshipType = $this->getRelationshipType($relationshipObject);
     $expectedRelationshipType = $this->getRelationshipType($this->getArgumentTypeHintFromClosure($hydrator));
     if ($expectedRelationshipType !== null && $relationshipType !== $expectedRelationshipType) {
         throw $exceptionFactory->createRelationshipTypeInappropriateException($relationshipName, $relationshipType, $expectedRelationshipType);
     }
     // Returning if the hydrator returns the hydrated domain object
     $value = $hydrator($domainObject, $relationshipObject, $data);
     if ($value) {
         return $value;
     }
     // Returning the domain object which was mutated but not returned by the hydrator
     return $domainObject;
 }