You are here

class OpenApiUiParamConverter in OpenAPI UI 8

Defines a ParamConverter for openapi_ui Plugins.

Hierarchy

Expanded class hierarchy of OpenApiUiParamConverter

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

File

src/ParamConverter/OpenApiUiParamConverter.php, line 14

Namespace

Drupal\openapi_ui\ParamConverter
View source
class OpenApiUiParamConverter implements ParamConverterInterface {

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

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

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

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

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

}

Members

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