You are here

abstract class ParameterFactoryBase in JSON-RPC 8

Same name and namespace in other branches
  1. 2.x src/ParameterFactory/ParameterFactoryBase.php \Drupal\jsonrpc\ParameterFactory\ParameterFactoryBase

Base class for parameter factories.

Hierarchy

Expanded class hierarchy of ParameterFactoryBase

File

src/ParameterFactory/ParameterFactoryBase.php, line 16

Namespace

Drupal\jsonrpc\ParameterFactory
View source
abstract class ParameterFactoryBase extends TransformationBase implements ParameterFactoryInterface {

  /**
   * The schema validator to ensure the input data adheres to the expectation.
   *
   * @var \JsonSchema\Validator
   */
  protected $validator;

  /**
   * The validation class for shaper interactions.
   *
   * @var \Shaper\Validator\ValidateableInterface
   */
  protected $inputValidator;

  /**
   * The parameter definition.
   *
   * @var \Drupal\jsonrpc\ParameterDefinitionInterface
   */
  protected $definition;

  /**
   * ParameterFactoryBase constructor.
   *
   * @param \Drupal\jsonrpc\ParameterDefinitionInterface $definition
   *   The parameter definition.
   * @param \JsonSchema\Validator $validator
   *   The JSON Schema validation object.
   */
  public function __construct(ParameterDefinitionInterface $definition, Validator $validator) {
    $this->validator = $validator;
    $this->definition = $definition;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ParameterDefinitionInterface $definition, ContainerInterface $container) {
    return new static($definition, $container
      ->get('jsonrpc.schema_validator'));
  }

  /**
   * {@inheritdoc}
   */
  public function getInputValidator() {
    if (!$this->inputValidator) {
      $schema = $this->definition
        ->getSchema();
      $this->inputValidator = new JsonSchemaValidator($schema, $this->validator, Constraint::CHECK_MODE_TYPE_CAST);
    }
    return $this->inputValidator;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ParameterFactoryBase::$definition protected property The parameter definition.
ParameterFactoryBase::$inputValidator protected property The validation class for shaper interactions.
ParameterFactoryBase::$validator protected property The schema validator to ensure the input data adheres to the expectation.
ParameterFactoryBase::create public static function Instantiates a new instance of this class. Overrides ParameterFactoryInterface::create 1
ParameterFactoryBase::getInputValidator public function
ParameterFactoryBase::__construct public function ParameterFactoryBase constructor. 1
ParameterFactoryInterface::schema public static function An array representing the JSON Schema for acceptable input to the factory. 3