本文整理汇总了PHP中Hash::contains方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::contains方法的具体用法?PHP Hash::contains怎么用?PHP Hash::contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hash
的用法示例。
在下文中一共展示了Hash::contains方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _parse
/**
* 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;
}
示例2: testContains
/**
* 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')));
}
示例3: admin_process
/**
* 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'));
}