Пример #1
0
 /**
  *
  * Constructor.
  *
  * @param array $config Array of config.
  */
 public function __construct($config = [])
 {
     if (!empty($config['cacheTime'])) {
         $this->_cacheTime = $config['cacheTime'];
     }
     parent::__construct($config);
 }
Пример #2
0
 /**
  * Class constructor.
  *
  * @param array $config Configuration options
  */
 public function __construct($config = [])
 {
     $config += ['priority' => 1, 'message' => 'Rate limit exceeded', 'interval' => '+1 minute', 'limit' => 10, 'identifier' => function (Request $request) {
         return $request->clientIp();
     }, 'headers' => ['limit' => 'X-RateLimit-Limit', 'remaining' => 'X-RateLimit-Remaining', 'reset' => 'X-RateLimit-Reset']];
     parent::__construct($config);
 }
Пример #3
0
 /**
  * Constructor.
  *
  * @param array $config Settings for the filter.
  * @throws \Cake\Core\Exception\Exception When 'when' conditions are not callable.
  */
 public function __construct($config = [])
 {
     parent::__construct($config);
     if (!empty($config['locales'])) {
         $this->_locales = $config['locales'];
     }
 }
 public function __construct($config = [])
 {
     $defaults = ['validToken' => null, 'cookieName' => '__cakephp_test_connection'];
     if (is_string($config)) {
         $config = ['validToken' => $config];
     }
     parent::__construct(array_merge($defaults, $config));
 }
Пример #5
0
 public function __construct($config = [])
 {
     $config += ['priority' => 1, 'message' => 'Rate limit exceeded', 'interval' => '1 minute', 'rate' => 10, 'identifier' => function (Request $request) {
         return $request->clientIp();
     }];
     parent::__construct($config);
     $this->config('when', [$this, 'when']);
     $this->_initCache();
 }
Пример #6
0
 public function __construct($config = [])
 {
     $config += ['key' => 'APP_ENV', 'value' => 'production'];
     if (empty($config['when'])) {
         $config['when'] = function () use($config) {
             return $request->env($config['key']) === $config['value'];
         };
     }
     parent::__construct($config);
 }
Пример #7
0
 public function __construct($config = [])
 {
     $config += ['priority' => 1, 'path' => ROOT . DS . 'maintenance.html'];
     if (empty($config['when'])) {
         $config['when'] = function () use($config) {
             return file_exists($config['path']);
         };
     }
     parent::__construct($config);
 }
Пример #8
0
 /**
  * constructor
  *
  * @param array $config configuration
  */
 public function __construct($config = [])
 {
     parent::__construct($config);
     if (!empty($config['classes'])) {
         $this->_classes = $config['classes'];
         if (!is_array($this->_classes)) {
             $this->_classes = [$this->_classes];
         }
     }
 }
Пример #9
0
 public function __construct($config = [])
 {
     $config += ['message' => 'Forbidden (%s)', 'allow' => [], 'disallow' => []];
     if (empty($config['when'])) {
         $config['when'] = function (Request $request) use($config) {
             $ip = $request->clientIp();
             return !(in_array($ip, $config['allow']) || !in_array($ip, $config['disallow']));
         };
     }
     parent::__construct($config);
 }
Пример #10
0
 /**
  * beforeDispatch function
  * @param \Cake\Event\Event $event event
  * @return /Cake/Network/Response|null
  */
 public function beforeDispatch(Event $event)
 {
     parent::beforeDispatch($event);
     $maintenance = Setting::read('Maintenance');
     // Allow ip in the list only.
     // Allow all if empty restrict ip
     if (!$maintenance['enable'] || empty($maintenance['allowedIp'])) {
         return null;
     }
     $userIP = $this->_getUserIpAddr();
     $ips = explode(',', trim($maintenance['allowedIp']));
     foreach ($ips as $ip) {
         if ($this->_compareIp($userIP, trim($ip))) {
             return null;
         }
     }
     $view = $this->_getView();
     $body = $view->render('Public/maintenance', 'error');
     $response = $event->data['response'];
     $response->statusCode(503);
     $response->body($body);
     $event->stopPropagation();
     return $response;
 }
Пример #11
0
 /**
  * Test matching with for & when option.
  *
  * @return void
  * @triggers Dispatcher.beforeDispatch $this, compact('response', 'request')
  */
 public function testMatchesWithForAndWhen()
 {
     $request = new Request(['url' => '/articles/view']);
     $response = new Response();
     $matcher = function () {
         return true;
     };
     $event = new Event('Dispatcher.beforeDispatch', $this, compact('response', 'request'));
     $filter = new DispatcherFilter(['for' => '/admin', 'when' => $matcher]);
     $this->assertFalse($filter->matches($event));
     $filter = new DispatcherFilter(['for' => '/articles', 'when' => $matcher]);
     $this->assertTrue($filter->matches($event));
     $matcher = function () {
         return false;
     };
     $filter = new DispatcherFilter(['for' => '/admin', 'when' => $matcher]);
     $this->assertFalse($filter->matches($event));
     $filter = new DispatcherFilter(['for' => '/articles', 'when' => $matcher]);
     $this->assertFalse($filter->matches($event));
 }
Пример #12
0
 public function __construct($config = [])
 {
     parent::__construct($config);
 }
Пример #13
0
 /**
  * Constructor
  *
  * @param \Cake\Event\EventManager $events The event manager to use.
  * @param array $config The configuration data for DebugKit.
  */
 public function __construct(EventManager $events, array $config)
 {
     parent::__construct($config);
     $this->eventManager($events);
     $this->_registry = new PanelRegistry($events);
 }
 public function beforeDispatch(Event $event)
 {
     $request = $event->data['request'];
     IpBehavior::$_request = $request;
     parent::afterDispatch($event);
 }
 /**
  * Constructor.
  *
  * @param array $config Settings for the filter.
  * @throws \InvalidArgumentException When 'when' conditions are not callable.
  */
 public function __construct($config = [])
 {
     $this->_defaultConfig = $this->_defaultConfigExt + $this->_defaultConfig;
     parent::__construct($config);
 }
Пример #16
0
 /**
  * construct
  *
  * @param array $config
  */
 public function __construct($config = [])
 {
     $this->Visitors = TableRegistry::get('Analyzer.Visitors');
     $this->Requests = TableRegistry::get('Analyzer.Requests');
     parent::__construct($config);
 }