Skip to content
Snippets Groups Projects
Commit d6441247 authored by Luhur Abdi Rizal's avatar Luhur Abdi Rizal
Browse files

Issue #3433220 by el7cosmos: Make the service lazy

parent 45ec8df9
No related branches found
No related tags found
1 merge request!9Make the service lazy
Pipeline #127374 passed
parameters:
level: max
checkMissingIterableValueType: false
excludePaths:
analyseAndScan:
- src/ProxyClass
......@@ -3,6 +3,7 @@ services:
class: Drupal\redis_batch\Batch\BatchStorageFactory
public: false
redis.batch.storage:
class: Drupal\Core\Batch\BatchStorageInterface
class: Drupal\redis_batch\Batch\RedisBatchStorageInterface
factory: ['@redis.batch.factory', get]
arguments: ['@redis.factory', '@csrf_token', '@serialization.phpserialize', '@session']
lazy: true
......@@ -4,11 +4,10 @@ namespace Drupal\redis_batch\Batch;
use Drupal\Component\Serialization\SerializationInterface;
use Drupal\Core\Access\CsrfTokenGenerator;
use Drupal\Core\Batch\BatchStorageInterface;
use Drupal\redis\RedisPrefixTrait;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
abstract class BatchStorageBase implements BatchStorageInterface {
abstract class BatchStorageBase implements RedisBatchStorageInterface {
public const TTL = 864_000;
......@@ -96,12 +95,4 @@ abstract class BatchStorageBase implements BatchStorageInterface {
*/
public function cleanup(): void {}
/**
* Returns a new batch id.
*
* @return int
* A batch id.
*/
abstract public function getId(): int;
}
<?php
namespace Drupal\redis_batch\Batch;
use Drupal\Core\Batch\BatchStorageInterface;
interface RedisBatchStorageInterface extends BatchStorageInterface {
/**
* Returns a new batch id.
*
* @return int
* A batch id.
*/
public function getId(): int;
}
<?php
// phpcs:ignoreFile
/**
* This file was generated via php core/scripts/generate-proxy-class.php 'Drupal\redis_batch\Batch\RedisBatchStorageInterface' "modules/custom/redis_batch/src".
*/
namespace Drupal\redis_batch\ProxyClass\Batch {
/**
* Provides a proxy class for \Drupal\redis_batch\Batch\RedisBatchStorageInterface.
*
* @see \Drupal\Component\ProxyBuilder
*/
class RedisBatchStorageInterface implements \Drupal\Core\Batch\BatchStorageInterface
{
use \Drupal\Core\DependencyInjection\DependencySerializationTrait;
/**
* The id of the original proxied service.
*
* @var string
*/
protected $drupalProxyOriginalServiceId;
/**
* The real proxied service, after it was lazy loaded.
*
* @var \Drupal\redis_batch\Batch\RedisBatchStorageInterface
*/
protected $service;
/**
* The service container.
*
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
/**
* Constructs a ProxyClass Drupal proxy object.
*
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
* The container.
* @param string $drupal_proxy_original_service_id
* The service ID of the original service.
*/
public function __construct(\Symfony\Component\DependencyInjection\ContainerInterface $container, $drupal_proxy_original_service_id)
{
$this->container = $container;
$this->drupalProxyOriginalServiceId = $drupal_proxy_original_service_id;
}
/**
* Lazy loads the real service from the container.
*
* @return object
* Returns the constructed real service.
*/
protected function lazyLoadItself()
{
if (!isset($this->service)) {
$this->service = $this->container->get($this->drupalProxyOriginalServiceId);
}
return $this->service;
}
/**
* {@inheritdoc}
*/
public function getId(): int
{
return $this->lazyLoadItself()->getId();
}
/**
* {@inheritdoc}
*/
public function load($id)
{
return $this->lazyLoadItself()->load($id);
}
/**
* {@inheritdoc}
*/
public function create(array $batch)
{
return $this->lazyLoadItself()->create($batch);
}
/**
* {@inheritdoc}
*/
public function update(array $batch)
{
return $this->lazyLoadItself()->update($batch);
}
/**
* {@inheritdoc}
*/
public function delete($id)
{
return $this->lazyLoadItself()->delete($id);
}
/**
* {@inheritdoc}
*/
public function cleanup()
{
return $this->lazyLoadItself()->cleanup();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment