CartResourceBase.php in Commerce Cart API 8
File
src/Plugin/rest/resource/CartResourceBase.php
View source
<?php
namespace Drupal\commerce_cart_api\Plugin\rest\resource;
use Drupal\commerce_cart\CartManagerInterface;
use Drupal\commerce_cart\CartProviderInterface;
use Drupal\rest\Plugin\ResourceBase;
use Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
abstract class CartResourceBase extends ResourceBase {
protected $cartProvider;
protected $cartManager;
public function __construct(array $configuration, $plugin_id, $plugin_definition, array $serializer_formats, LoggerInterface $logger, CartProviderInterface $cart_provider, CartManagerInterface $cart_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $serializer_formats, $logger);
$this->cartProvider = $cart_provider;
$this->cartManager = $cart_manager;
}
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->getParameter('serializer.formats'), $container
->get('logger.factory')
->get('rest'), $container
->get('commerce_cart.cart_provider'), $container
->get('commerce_cart.cart_manager'));
}
public function permissions() {
return [];
}
protected function getBaseRouteRequirements($method) {
$requirements = parent::getBaseRouteRequirements($method);
$requirements['_cart_api'] = 'TRUE';
return $requirements;
}
}