/**
  * Parses a given Permit route to see if it matches the current request
  *
  * @param object $controller A reference to the instantiating controller object
  * @param array $route A Permit Route
  * @return boolean true if current request matches Permit route, false otherwise
  */
 protected function _parse($route)
 {
     if (is_string($route)) {
         $this->_ensureHere();
         $url = parse_url($route);
         $_path = rtrim($url['path'], '/');
         if ($_path . '?' . Hash::get($url, 'query') === $this->_here_query) {
             return true;
         }
         if ($_path === $this->_here) {
             return true;
         }
         return false;
     }
     $count = count($route);
     if ($count == 0) {
         return false;
     }
     foreach ($route as $key => $value) {
         if (array_key_exists($key, $this->request->params)) {
             $values = (array) $value;
             $check = (array) $this->request->params[$key];
             $hasNullValues = count($values) != count(array_filter($values)) || count($values) == 0;
             $currentValueIsNullish = in_array(null, $check) || in_array('', $check) || count($check) == 0;
             if ($hasNullValues && $currentValueIsNullish) {
                 $count--;
                 continue;
             }
             if (in_array($key, array('controller', 'plugin'))) {
                 foreach ($check as $k => $_check) {
                     $check[$k] = Inflector::underscore(strtolower($_check));
                 }
             } else {
                 foreach ($check as $k => $_check) {
                     $check[$k] = strtolower($_check);
                 }
             }
             if (count($values) > 0) {
                 foreach ($values as $k => $v) {
                     if (in_array(strtolower($v), $check)) {
                         $count--;
                         break;
                     }
                 }
             } elseif (count($check) === 0) {
                 $count--;
             }
         } elseif (is_numeric($key) && isset($this->request->params['pass'])) {
             if (is_array($this->request->params['pass'])) {
                 if (Hash::contains($this->request->params['pass'], $value)) {
                     $count--;
                 }
             }
         }
     }
     return $count == 0;
 }
Exemple #2
0
 /**
  * testContains method
  *
  * @return void
  */
 public function testContains()
 {
     $data = array('apple', 'bee', 'cyclops');
     $this->assertTrue(Hash::contains($data, array('apple')));
     $this->assertFalse(Hash::contains($data, array('data')));
     $a = array(0 => array('name' => 'main'), 1 => array('name' => 'about'));
     $b = array(0 => array('name' => 'main'), 1 => array('name' => 'about'), 2 => array('name' => 'contact'), 'a' => 'b');
     $this->assertTrue(Hash::contains($a, $a));
     $this->assertFalse(Hash::contains($a, $b));
     $this->assertTrue(Hash::contains($b, $a));
     $a = array(array('User' => array('id' => 1)), array('User' => array('id' => 2)));
     $b = array(array('User' => array('id' => 1)), array('User' => array('id' => 2)), array('User' => array('id' => 3)));
     $this->assertTrue(Hash::contains($b, $a));
     $this->assertFalse(Hash::contains($a, $b));
     $a = array(0 => 'test', 'string' => null);
     $this->assertTrue(Hash::contains($a, array('string' => null)));
     $a = array(0 => 'test', 'string' => null);
     $this->assertTrue(Hash::contains($a, array('test')));
 }
 /**
  * Admin process
  *
  * @return void
  * @access public
  */
 public function admin_process()
 {
     $action = $this->request->data[$this->modelClass]['action'];
     $ids = array();
     foreach ($this->request->data[$this->modelClass] as $key => $value) {
         if (is_array($value)) {
             if (Hash::contains($value, array('id' => 1))) {
                 $ids[] = $key;
             }
         }
     }
     if (count($ids) == 0 || $action == null) {
         $this->Session->setFlash(__d('clear_session', 'No Session selected.'), 'flash', array('class' => 'error'));
         return $this->redirect(array('action' => 'index'));
     }
     if ($action == 'delete' && $this->{$this->modelClass}->deleteAll(array($this->modelClass . '.' . 'id' => $ids), true, true)) {
         $this->Session->setFlash(__d('clear_session', 'Session deleted successfully.'), 'flash', array('class' => 'success'));
     } else {
         $this->Session->setFlash(__d('clear_session', 'An error occurred. Please, try again.'), 'flash', array('class' => 'error'));
     }
     return $this->redirect(array('action' => 'index'));
 }