You are here

class OpenApiParamConverter in OpenAPI 8

Same name and namespace in other branches
  1. 8.2 src/ParamConverter/OpenApiParamConverter.php \Drupal\openapi\ParamConverter\OpenApiParamConverter

Defines a ParamConverter for Openapi Plugins.

Hierarchy

Expanded class hierarchy of OpenApiParamConverter

1 string reference to 'OpenApiParamConverter'
openapi.services.yml in ./openapi.services.yml
openapi.services.yml
1 service uses OpenApiParamConverter
openapi.parm_parser in ./openapi.services.yml
Drupal\openapi\ParamConverter\OpenApiParamConverter

File

src/ParamConverter/OpenApiParamConverter.php, line 14

Namespace

Drupal\openapi\ParamConverter
View source
class OpenApiParamConverter implements ParamConverterInterface {

  /**
   * Current openapi generator plugin manager.
   *
   * @var \Drupal\Component\Plugin\PluginManagerInterface
   */
  public $openApiGeneratorManager;

  /**
   * Creates a new OpenApiParamConverter.
   *
   * @param \Drupal\Component\Plugin\PluginManagerInterface $open_api_generator_manager
   *   The current openapi generator plugin manager instance.
   */
  public function __construct(PluginManagerInterface $open_api_generator_manager) {
    $this->openApiGeneratorManager = $open_api_generator_manager;
  }

  /**
   * {@inheritdoc}
   */
  public function convert($value, $definition, $name, array $defaults) {
    try {
      $generator = $this->openApiGeneratorManager
        ->createInstance($value);
    } catch (PluginNotFoundException $e) {

      // Plugin Not found, we can't convert it the param.
      return NULL;
    }
    return $generator;
  }

  /**
   * {@inheritdoc}
   */
  public function applies($definition, $name, Route $route) {
    return !empty($definition['type']) && $definition['type'] == 'openapi_generator';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
OpenApiParamConverter::$openApiGeneratorManager public property Current openapi generator plugin manager.
OpenApiParamConverter::applies public function Determines if the converter applies to a specific route and variable. Overrides ParamConverterInterface::applies
OpenApiParamConverter::convert public function Converts path variables to their corresponding objects. Overrides ParamConverterInterface::convert
OpenApiParamConverter::__construct public function Creates a new OpenApiParamConverter.