[ Index ]

PHP Cross Reference of phpBB-3.3.5-deutsch

title

Body

[close]

/vendor/zendframework/zend-eventmanager/src/ -> FilterChain.php (source)

   1  <?php
   2  /**
   3   * Zend Framework (http://framework.zend.com/)
   4   *
   5   * @link      http://github.com/zendframework/zend-eventmanager for the canonical source repository
   6   * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
   7   * @license   https://github.com/zendframework/zend-eventmanager/blob/master/LICENSE.md
   8   */
   9  
  10  namespace Zend\EventManager;
  11  
  12  /**
  13   * FilterChain: intercepting filter manager
  14   */
  15  class FilterChain implements Filter\FilterInterface
  16  {
  17      /**
  18       * @var Filter\FilterIterator All filters
  19       */
  20      protected $filters;
  21  
  22      /**
  23       * Constructor
  24       *
  25       * Initializes Filter\FilterIterator in which filters will be aggregated
  26       */
  27      public function __construct()
  28      {
  29          $this->filters = new Filter\FilterIterator();
  30      }
  31  
  32      /**
  33       * Apply the filters
  34       *
  35       * Begins iteration of the filters.
  36       *
  37       * @param  mixed $context Object under observation
  38       * @param  mixed $argv Associative array of arguments
  39       * @return mixed
  40       */
  41      public function run($context, array $argv = [])
  42      {
  43          $chain = clone $this->getFilters();
  44  
  45          if ($chain->isEmpty()) {
  46              return;
  47          }
  48  
  49          $next = $chain->extract();
  50  
  51          return $next($context, $argv, $chain);
  52      }
  53  
  54      /**
  55       * Connect a filter to the chain
  56       *
  57       * @param  callable $callback PHP Callback
  58       * @param  int $priority Priority in the queue at which to execute;
  59       *     defaults to 1 (higher numbers == higher priority)
  60       * @return CallbackHandler (to allow later unsubscribe)
  61       * @throws Exception\InvalidCallbackException
  62       */
  63      public function attach(callable $callback, $priority = 1)
  64      {
  65          $this->filters->insert($callback, $priority);
  66          return $callback;
  67      }
  68  
  69      /**
  70       * Detach a filter from the chain
  71       *
  72       * @param  callable $filter
  73       * @return bool Returns true if filter found and unsubscribed; returns false otherwise
  74       */
  75      public function detach(callable $filter)
  76      {
  77          return $this->filters->remove($filter);
  78      }
  79  
  80      /**
  81       * Retrieve all filters
  82       *
  83       * @return Filter\FilterIterator
  84       */
  85      public function getFilters()
  86      {
  87          return $this->filters;
  88      }
  89  
  90      /**
  91       * Clear all filters
  92       *
  93       * @return void
  94       */
  95      public function clearFilters()
  96      {
  97          $this->filters = new Filter\FilterIterator();
  98      }
  99  
 100      /**
 101       * Return current responses
 102       *
 103       * Only available while the chain is still being iterated. Returns the
 104       * current ResponseCollection.
 105       *
 106       * @return null|ResponseCollection
 107       */
 108      public function getResponses()
 109      {
 110          return;
 111      }
 112  }


Generated: Mon Oct 4 17:42:11 2021 Cross-referenced by PHPXref 0.7.1