Seditio Source
Root |
./othercms/croogo-4.0.7/vendor/neomerx/json-api/src/Parser/RelationshipData/RelationshipDataIsResource.php
<?php declare(strict_types=1);

namespace
Neomerx\JsonApi\Parser\RelationshipData;

/**
 * Copyright 2015-2019 info@neomerx.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

use Neomerx\JsonApi\Contracts\Factories\FactoryInterface;
use
Neomerx\JsonApi\Contracts\Parser\IdentifierInterface;
use
Neomerx\JsonApi\Contracts\Parser\PositionInterface;
use
Neomerx\JsonApi\Contracts\Parser\RelationshipDataInterface;
use
Neomerx\JsonApi\Contracts\Parser\ResourceInterface;
use
Neomerx\JsonApi\Contracts\Schema\SchemaContainerInterface;
use
Neomerx\JsonApi\Exceptions\LogicException;
use function
Neomerx\JsonApi\I18n\format as _;

/**
 * @package Neomerx\JsonApi
 */
class RelationshipDataIsResource extends BaseRelationshipData implements RelationshipDataInterface
{
   
/** @var string */
   
public const MSG_INVALID_OPERATION = 'Invalid operation.';

   
/**
     * @var mixed
     */
   
private $resource;

   
/**
     * @var null|ResourceInterface
     */
   
private $parsedResource = null;

   
/**
     * @param FactoryInterface          $factory
     * @param SchemaContainerInterface  $schemaContainer
     * @param PositionInterface         $position
     * @param mixed                     $resource
     */
   
public function __construct(
       
FactoryInterface $factory,
       
SchemaContainerInterface $schemaContainer,
       
PositionInterface $position,
       
$resource
   
) {
       
parent::__construct($factory, $schemaContainer, $position);

       
$this->resource = $resource;
    }

   
/**
     * @inheritdoc
     */
   
public function isCollection(): bool
   
{
        return
false;
    }

   
/**
     * @inheritdoc
     */
   
public function isNull(): bool
   
{
        return
false;
    }

   
/**
     * @inheritdoc
     */
   
public function isResource(): bool
   
{
        return
true;
    }

   
/**
     * @inheritdoc
     */
   
public function isIdentifier(): bool
   
{
        return
false;
    }

   
/**
     * @inheritdoc
     */
   
public function getIdentifier(): IdentifierInterface
   
{
        throw new
LogicException(_(static::MSG_INVALID_OPERATION));
    }

   
/**
     * @inheritdoc
     */
   
public function getIdentifiers(): iterable
   
{
        throw new
LogicException(_(static::MSG_INVALID_OPERATION));
    }

   
/**
     * @inheritdoc
     */
   
public function getResource(): ResourceInterface
   
{
        if (
$this->parsedResource === null) {
           
$this->parsedResource = $this->createParsedResource($this->resource);
        }

        return
$this->parsedResource;
    }

   
/**
     * @inheritdoc
     */
   
public function getResources(): iterable
   
{
        throw new
LogicException(_(static::MSG_INVALID_OPERATION));
    }
}