You are here

class EnsureSubscriber in Flysystem 2.0.x

Same name and namespace in other branches
  1. 8 src/EventSubscriber/EnsureSubscriber.php \Drupal\flysystem\EventSubscriber\EnsureSubscriber
  2. 3.x src/EventSubscriber/EnsureSubscriber.php \Drupal\flysystem\EventSubscriber\EnsureSubscriber
  3. 3.0.x src/EventSubscriber/EnsureSubscriber.php \Drupal\flysystem\EventSubscriber\EnsureSubscriber

Event listener that listens to Flysystem ensure() calls.

Hierarchy

  • class \Drupal\flysystem\EventSubscriber\EnsureSubscriber implements \Symfony\Component\EventDispatcher\EventSubscriberInterface

Expanded class hierarchy of EnsureSubscriber

1 file declares its use of EnsureSubscriber
EnsureSubscriberTest.php in tests/src/Unit/EventSubscriber/EnsureSubscriberTest.php
1 string reference to 'EnsureSubscriber'
flysystem.services.yml in ./flysystem.services.yml
flysystem.services.yml
1 service uses EnsureSubscriber
flysystem.ensure_subscriber in ./flysystem.services.yml
Drupal\flysystem\EventSubscriber\EnsureSubscriber

File

src/EventSubscriber/EnsureSubscriber.php, line 15

Namespace

Drupal\flysystem\EventSubscriber
View source
class EnsureSubscriber implements EventSubscriberInterface {

  /**
   * The logger to use.
   *
   * @var \Psr\Log\LoggerInterface
   */
  protected $logger;

  /**
   * {@inheritdoc}
   */
  public static function getSubscribedEvents() {
    $events = [];
    $events[FlysystemEvents::ENSURE][] = 'onEnsure';
    return $events;
  }

  /**
   * Constructs an EnsureSubscriber object.
   *
   * @param \Psr\Log\LoggerInterface $logger
   *   The logger.
   */
  public function __construct(LoggerInterface $logger) {
    $this->logger = $logger;
  }

  /**
   * Responds to FlysystemFactory::ensure().
   */
  public function onEnsure(EnsureEvent $event, $event_name, EventDispatcherInterface $dispatcher) {

    // We only want to log failures, since this runs frequently.
    switch ($event
      ->getSeverity()) {
      case RfcLogLevel::NOTICE:
      case RfcLogLevel::INFO:
        return;
    }
    $this->logger
      ->log($event
      ->getSeverity(), $event
      ->getMessage(), $event
      ->getContext());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EnsureSubscriber::$logger protected property The logger to use.
EnsureSubscriber::getSubscribedEvents public static function
EnsureSubscriber::onEnsure public function Responds to FlysystemFactory::ensure().
EnsureSubscriber::__construct public function Constructs an EnsureSubscriber object.