diff --git a/jsonapi.services.yml b/jsonapi.services.yml index 80f6782..73ec92d 100644 --- a/jsonapi.services.yml +++ b/jsonapi.services.yml @@ -184,15 +184,15 @@ services: - { name: event_subscriber, priority: 1000 } # Revision management. - plugin.manager.version_negotiation: - class: Drupal\jsonapi\Revisions\VersionNegotiationManager + plugin.manager.version_negotiator: + class: Drupal\jsonapi\Revisions\VersionNegotiatorManager public: false parent: default_plugin_manager jsonapi.resource_version.route_enhancer: class: Drupal\jsonapi\Revisions\ResourceVersionRouteEnhancer public: false arguments: - - '@plugin.manager.version_negotiation' + - '@plugin.manager.version_negotiator' tags: - { name: route_enhancer } diff --git a/src/Plugin/VersionNegotiation/VersionById.php b/src/Plugin/VersionNegotiator/VersionById.php similarity index 64% rename from src/Plugin/VersionNegotiation/VersionById.php rename to src/Plugin/VersionNegotiator/VersionById.php index e2d7d74..3cfbfba 100644 --- a/src/Plugin/VersionNegotiation/VersionById.php +++ b/src/Plugin/VersionNegotiator/VersionById.php @@ -1,27 +1,30 @@ versionNegotiationManager = $version_negotiation_manager; + public function __construct(VersionNegotiatorManager $version_negotiator_manager) { + $this->versionNegotiatorManager = $version_negotiator_manager; } /** @@ -97,9 +97,9 @@ class ResourceVersionRouteEnhancer implements EnhancerInterface { // Determine if the request is for a collection resource. if ($defaults[RouteObjectInterface::CONTROLLER_NAME] === Routes::CONTROLLER_SERVICE_NAME . ':getCollection') { - // @todo: If VersionNegotiation plugins become a public API, then this logic will need to be moved into the relevant plugins. - $latest_version_identifier = VersionByRel::NEGOTIATOR_NAME . VersionNegotiationManager::SEPARATOR . VersionByRel::LATEST_VERSION; - $working_copy_identifier = VersionByRel::NEGOTIATOR_NAME . VersionNegotiationManager::SEPARATOR . VersionByRel::WORKING_COPY; + // @todo: If VersionNegotiator plugins become a public API, then this logic will need to be moved into the relevant plugins. + $latest_version_identifier = VersionByRel::NEGOTIATOR_NAME . VersionNegotiatorManager::SEPARATOR . VersionByRel::LATEST_VERSION; + $working_copy_identifier = VersionByRel::NEGOTIATOR_NAME . VersionNegotiatorManager::SEPARATOR . VersionByRel::WORKING_COPY; // 'latest-version' and 'working-copy' are the only acceptable version // identifiers for a collection resource. if (!in_array($resource_version_identifier, [$latest_version_identifier, $working_copy_identifier])) { @@ -118,8 +118,8 @@ class ResourceVersionRouteEnhancer implements EnhancerInterface { /** @var \Drupal\Core\Entity\EntityInterface $entity */ $entity = $defaults['entity']; - /** @var \Drupal\jsonapi\Revisions\VersionNegotiationInterface $negotiator */ - $resolved_revision = $this->versionNegotiationManager->getRevision($entity, $resource_version_identifier); + /** @var \Drupal\jsonapi\Revisions\VersionNegotiatorInterface $negotiator */ + $resolved_revision = $this->versionNegotiatorManager->getRevision($entity, $resource_version_identifier); return ['entity' => $resolved_revision] + $defaults; } diff --git a/src/Revisions/VersionNegotiationInterface.php b/src/Revisions/VersionNegotiatorInterface.php similarity index 81% rename from src/Revisions/VersionNegotiationInterface.php rename to src/Revisions/VersionNegotiatorInterface.php index 30d1de1..dc37817 100644 --- a/src/Revisions/VersionNegotiationInterface.php +++ b/src/Revisions/VersionNegotiatorInterface.php @@ -5,14 +5,14 @@ namespace Drupal\jsonapi\Revisions; use Drupal\Core\Entity\EntityInterface; /** - * Defines the common interface for all version negotiation plugins. + * Defines the common interface for all version negotiator plugins. * - * @see \Drupal\jsonapi\Revisions\Annotation\VersionNegotiation - * @see \Drupal\jsonapi\Revisions\VersionNegotiationManager + * @see \Drupal\jsonapi\Revisions\Annotation\VersionNegotiator + * @see \Drupal\jsonapi\Revisions\VersionNegotiatorManager * @see plugin_api * @internal */ -interface VersionNegotiationInterface { +interface VersionNegotiatorInterface { /** * Gets the identified revision. @@ -25,7 +25,7 @@ interface VersionNegotiationInterface { * the "latest version" regardless of its ID. It is possible to imagine other * scenarios as well, like fetching a revision based on a date or time. * - * Each VersionNegotiation plugin provides one of these strategies and is able + * Each VersionNegotiator plugin provides one of these strategies and is able * to map a version argument to an existing revision. * * @param \Drupal\Core\Entity\EntityInterface $entity diff --git a/src/Revisions/VersionNegotiationManager.php b/src/Revisions/VersionNegotiatorManager.php similarity index 85% rename from src/Revisions/VersionNegotiationManager.php rename to src/Revisions/VersionNegotiatorManager.php index 6cf9dde..0de0b0c 100644 --- a/src/Revisions/VersionNegotiationManager.php +++ b/src/Revisions/VersionNegotiatorManager.php @@ -10,27 +10,27 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Http\Exception\CacheableBadRequestHttpException; use Drupal\Core\Http\Exception\CacheableNotFoundHttpException; use Drupal\Core\Plugin\DefaultPluginManager; -use Drupal\jsonapi\Revisions\Annotation\VersionNegotiation; +use Drupal\jsonapi\Revisions\Annotation\VersionNegotiator; /** - * Provides a version negotiation plugin manager. + * Provides a version negotiator plugin manager. * - * @see \Drupal\jsonapi\Revisions\Annotation\VersionNegotiation - * @see \Drupal\jsonapi\Revisions\VersionNegotiationInterface + * @see \Drupal\jsonapi\Revisions\Annotation\VersionNegotiator + * @see \Drupal\jsonapi\Revisions\VersionNegotiatorInterface * @see plugin_api * @internal */ -class VersionNegotiationManager extends DefaultPluginManager { +class VersionNegotiatorManager extends DefaultPluginManager { /** - * The separator between the negotiator name and the negotiation ID. + * The separator between the version negotiator name and the version argument. * * @var string */ const SEPARATOR = ':'; /** - * Constructs a VersionNegotiationManager object. + * Constructs a VersionNegotiatorManager object. * * @param \Traversable $namespaces * An object that implements \Traversable which contains the root paths @@ -43,8 +43,8 @@ class VersionNegotiationManager extends DefaultPluginManager { public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) { // Only discover plugins provided by JSON API. This is an internal API. $internal = new \ArrayIterator(array_intersect_key(iterator_to_array($namespaces), array_flip(['Drupal\jsonapi']))); - parent::__construct('Plugin/VersionNegotiation', $internal, $module_handler, VersionNegotiationInterface::class, VersionNegotiation::class); - $this->setCacheBackend($cache_backend, 'revision_id_negotiation_info_plugins'); + parent::__construct('Plugin/VersionNegotiator', $internal, $module_handler, VersionNegotiatorInterface::class, VersionNegotiator::class); + $this->setCacheBackend($cache_backend, 'revision_id_negotiator_info_plugins'); } /** @@ -65,9 +65,9 @@ class VersionNegotiationManager extends DefaultPluginManager { */ public function getRevision(EntityInterface $entity, $resource_version_identifier) { try { - list($version_negotiator, $version_argument) = explode(VersionNegotiationManager::SEPARATOR, $resource_version_identifier, 2); + list($version_negotiator, $version_argument) = explode(VersionNegotiatorManager::SEPARATOR, $resource_version_identifier, 2); $negotiator = $this->createInstance($version_negotiator); - assert($negotiator instanceof VersionNegotiationInterface); + assert($negotiator instanceof VersionNegotiatorInterface); return $negotiator->getRevision($entity, $version_argument); } catch (VersionNotFoundException $exception) { diff --git a/tests/src/Kernel/Plugin/VersionNegotiation/VersionByIdTest.php b/tests/src/Kernel/Plugin/VersionNegotiator/VersionByIdTest.php similarity index 71% rename from tests/src/Kernel/Plugin/VersionNegotiation/VersionByIdTest.php rename to tests/src/Kernel/Plugin/VersionNegotiator/VersionByIdTest.php index 1d9455d..e571bbc 100644 --- a/tests/src/Kernel/Plugin/VersionNegotiation/VersionByIdTest.php +++ b/tests/src/Kernel/Plugin/VersionNegotiator/VersionByIdTest.php @@ -1,22 +1,22 @@ getNegotiationPlugin('id'); + $plugin = $this->getNegotiatorPlugin('id'); $revision = $plugin->getRevision($this->node, $this->nodePreviousRevisionId); $this->assertEquals($this->node->id(), $revision->id()); $this->assertEquals($this->nodePreviousRevisionId, $revision->getRevisionId()); @@ -26,7 +26,7 @@ class VersionByIdTest extends VersionNegotiationTestBase { * @covers ::getRevision */ public function testInvalidRevision() { - $plugin = $this->getNegotiationPlugin('id'); + $plugin = $this->getNegotiatorPlugin('id'); $this->setExpectedException(VersionNotFoundException::class, sprintf('The requested resource does not have a version with ID %s.', $this->node2->getRevisionId())); $plugin->getRevision($this->node, $this->node2->getRevisionId()); } diff --git a/tests/src/Kernel/Plugin/VersionNegotiation/VersionByRelTest.php b/tests/src/Kernel/Plugin/VersionNegotiator/VersionByRelTest.php similarity index 72% rename from tests/src/Kernel/Plugin/VersionNegotiation/VersionByRelTest.php rename to tests/src/Kernel/Plugin/VersionNegotiator/VersionByRelTest.php index a17e36a..33661d6 100644 --- a/tests/src/Kernel/Plugin/VersionNegotiation/VersionByRelTest.php +++ b/tests/src/Kernel/Plugin/VersionNegotiator/VersionByRelTest.php @@ -1,23 +1,23 @@ getNegotiationPlugin('rel'); + $plugin = $this->getNegotiatorPlugin('rel'); $revision = $plugin->getRevision($this->node, VersionByRel::LATEST_VERSION); $this->assertEquals($this->node->id(), $revision->id()); $this->assertEquals($this->node->getRevisionId(), $revision->getRevisionId()); @@ -27,7 +27,7 @@ class VersionByRelTest extends VersionNegotiationTestBase { * @covers ::getRevision */ public function testCurrentVersion() { - $plugin = $this->getNegotiationPlugin('rel'); + $plugin = $this->getNegotiatorPlugin('rel'); $revision = $plugin->getRevision($this->node, VersionByRel::WORKING_COPY); $this->assertEquals($this->node->id(), $revision->id()); $this->assertEquals($this->node->getRevisionId(), $revision->getRevisionId()); @@ -37,7 +37,7 @@ class VersionByRelTest extends VersionNegotiationTestBase { * @covers ::getRevision */ public function testInvalidRevision() { - $plugin = $this->getNegotiationPlugin('rel'); + $plugin = $this->getNegotiatorPlugin('rel'); $this->setExpectedException(InvalidVersionIdentifierException::class, 'The version specifier must be either `latest-version` or `working-copy`, `erroneous-revision-name` given.'); $plugin->getRevision($this->node, 'erroneous-revision-name'); } diff --git a/tests/src/Kernel/Plugin/VersionNegotiation/VersionNegotiationTestBase.php b/tests/src/Kernel/Plugin/VersionNegotiator/VersionNegotiatorTestBase.php similarity index 81% rename from tests/src/Kernel/Plugin/VersionNegotiation/VersionNegotiationTestBase.php rename to tests/src/Kernel/Plugin/VersionNegotiator/VersionNegotiatorTestBase.php index e1eacd4..32dde6f 100644 --- a/tests/src/Kernel/Plugin/VersionNegotiation/VersionNegotiationTestBase.php +++ b/tests/src/Kernel/Plugin/VersionNegotiator/VersionNegotiatorTestBase.php @@ -1,17 +1,17 @@ node2->save(); - $this->pluginManager = new VersionNegotiationManager( + $this->pluginManager = new VersionNegotiatorManager( $this->container->get('container.namespaces'), $this->container->get('cache.discovery'), $this->container->get('module_handler') @@ -105,17 +105,17 @@ abstract class VersionNegotiationTestBase extends JsonapiKernelTestBase { } /** - * Returns an instance of a revision ID negotiation plugin. + * Returns an instance of a revision ID negotiator plugin. * * @param string $negotiator_name * The plugin ID. * - * @return \Drupal\jsonapi\Revisions\VersionNegotiationInterface + * @return \Drupal\jsonapi\Revisions\VersionNegotiatorInterface * The plugin instance. * * @throws \Exception */ - protected function getNegotiationPlugin($negotiator_name) { + protected function getNegotiatorPlugin($negotiator_name) { return $this->pluginManager->createInstance($negotiator_name); }