예제 #1
0
 /**
  * Callback for Routing.beforeDispatch event.
  *
  * @param \Cake\Event\Event $event The event instance.
  *
  * @return \Cake\Network\Response Response instance.
  */
 public function beforeDispatch(Event $event)
 {
     $request = $event->data['request'];
     $response = $event->data['response'];
     $path = urldecode($request->url);
     if (Configure::read('Glide.secureUrls')) {
         SignatureFactory::create(Security::salt())->validateRequest('/' . $path, $request->query);
     }
     $server = ServerFactory::create(Configure::read('Glide.serverConfig'));
     $cache = Configure::read('Glide.cache');
     if ($cache) {
         $timestamp = $server->getSource()->getTimestamp($server->getSourcePath($path));
         $response->modified($timestamp);
         if (!$response->checkNotModified($request)) {
             $response = $server->getImageResponse($path, $request->query);
         }
         $response->cache($timestamp, $cache);
     } else {
         $response = $server->getImageResponse($path, $request->query);
     }
     $headers = Hash::filter((array) Configure::read('Glide.headers'));
     foreach ($headers as $key => $value) {
         $response->header($key, $value);
     }
     return $response;
 }
예제 #2
0
 /**
  * Filters the params from POST data and merges in the whitelisted query string ones.
  *
  * @return array
  */
 protected function _filterParams()
 {
     $params = Hash::filter($this->request->data);
     if (!$this->config('queryStringWhitelist')) {
         return $params;
     }
     foreach ($this->config('queryStringWhitelist') as $field) {
         if (!isset($params[$field]) && $this->request->query($field) !== null) {
             $params[$field] = $this->request->query($field);
         }
     }
     return $params;
 }
예제 #3
0
 /**
  * Extracts nested validation errors
  *
  * @param EntityInterface $entity Entity to extract
  *
  * @return array
  */
 protected function _getErrors(EntityInterface $entity)
 {
     $errors = $entity->errors();
     foreach ($entity->visibleProperties() as $property) {
         $v = $entity[$property];
         if ($v instanceof EntityInterface) {
             $errors[$property] = $this->_getErrors($v);
         } elseif (is_array($v)) {
             foreach ($v as $key => $varValue) {
                 if ($varValue instanceof EntityInterface) {
                     $errors[$property][$key] = $this->_getErrors($varValue);
                 }
             }
         }
     }
     return Hash::filter($errors);
 }
예제 #4
0
 /**
  * Determine which fields of a form should be used for hash.
  * Populates $this->fields
  *
  * @param bool $lock Whether this field should be part of the validation
  *   or excluded as part of the unlockedFields.
  * @param string|array $field Reference to field to be secured. Can be dot
  *   separated string to indicate nesting or array of fieldname parts.
  * @param mixed $value Field value, if value should not be tampered with.
  * @return void
  */
 protected function _secure($lock, $field, $value = null)
 {
     if (empty($field) && $field !== '0') {
         return;
     }
     if (is_string($field)) {
         $field = Hash::filter(explode('.', $field));
     }
     foreach ($this->_unlockedFields as $unlockField) {
         $unlockParts = explode('.', $unlockField);
         if (array_values(array_intersect($field, $unlockParts)) === $unlockParts) {
             return;
         }
     }
     $field = implode('.', $field);
     $field = preg_replace('/(\\.\\d+)+$/', '', $field);
     if ($lock) {
         if (!in_array($field, $this->fields)) {
             if ($value !== null) {
                 return $this->fields[$field] = $value;
             } elseif (isset($this->fields[$field]) && $value === null) {
                 unset($this->fields[$field]);
             }
             $this->fields[] = $field;
         }
     } else {
         $this->unlockField($field);
     }
 }
예제 #5
0
 /**
  * testFilter method
  *
  * @return void
  */
 public function testFilter()
 {
     $result = Hash::filter(['0', false, true, 0, ['one thing', 'I can tell you', 'is you got to be', false]]);
     $expected = ['0', 2 => true, 3 => 0, 4 => ['one thing', 'I can tell you', 'is you got to be']];
     $this->assertSame($expected, $result);
     $result = Hash::filter([1, [false]]);
     $expected = [1];
     $this->assertEquals($expected, $result);
     $result = Hash::filter([1, [false, false]]);
     $expected = [1];
     $this->assertEquals($expected, $result);
     $result = Hash::filter([1, ['empty', false]]);
     $expected = [1, ['empty']];
     $this->assertEquals($expected, $result);
     $result = Hash::filter([1, ['2', false, [3, null]]]);
     $expected = [1, ['2', 2 => [3]]];
     $this->assertEquals($expected, $result);
     $this->assertSame([], Hash::filter([]));
 }
예제 #6
0
 /**
  * Extracts all parameters for wich a filter with a matching field
  * name exists.
  *
  * @param array $params The parameters array to extract from.
  * @param \Search\Model\Filter\Base[] $filters The filters to match against.
  * @return array The extracted parameters.
  */
 protected function _extractParams($params, $filters)
 {
     return array_intersect_key(Hash::filter($params), $filters);
 }
예제 #7
0
파일: AclExtras.php 프로젝트: cakephp/acl
 /**
  * Get the namespace for a given class.
  *
  * @param string $className The class you want a namespace for.
  * @param string $pluginPath The plugin path.
  * @param string $prefixPath The prefix path.
  * @return string
  */
 protected function _getNamespace($className, $pluginPath = null, $prefixPath = null)
 {
     $namespace = preg_replace('/(.*)Controller\\//', '', $className);
     $namespace = preg_replace('/\\//', '\\', $namespace);
     $namespace = preg_replace('/\\.php/', '', $namespace);
     $prefixPath = preg_replace('/\\//', '\\', Inflector::camelize($prefixPath));
     if (!$pluginPath) {
         $rootNamespace = Configure::read('App.namespace');
     } else {
         $rootNamespace = preg_replace('/\\//', '\\', $pluginPath);
     }
     $namespace = [$rootNamespace, 'Controller', $prefixPath, $namespace];
     return implode('\\', Hash::filter($namespace));
 }
예제 #8
0
 /**
  * testFilter method
  *
  * @return void
  */
 public function testFilter()
 {
     $result = Hash::filter(array('0', false, true, 0, array('one thing', 'I can tell you', 'is you got to be', false)));
     $expected = array('0', 2 => true, 3 => 0, 4 => array('one thing', 'I can tell you', 'is you got to be'));
     $this->assertSame($expected, $result);
     $result = Hash::filter(array(1, array(false)));
     $expected = array(1);
     $this->assertEquals($expected, $result);
     $result = Hash::filter(array(1, array(false, false)));
     $expected = array(1);
     $this->assertEquals($expected, $result);
     $result = Hash::filter(array(1, array('empty', false)));
     $expected = array(1, array('empty'));
     $this->assertEquals($expected, $result);
     $result = Hash::filter(array(1, array('2', false, array(3, null))));
     $expected = array(1, array('2', 2 => array(3)));
     $this->assertEquals($expected, $result);
     $this->assertSame(array(), Hash::filter(array()));
 }
예제 #9
0
 protected function cleanup($rows)
 {
     $rows = Hash::filter($rows);
     foreach ($rows as $key => $row) {
         unset($rows[$key]['id'], $rows[$key]['value']);
     }
     return $rows;
 }