本文整理汇总了PHP中Cake\Utility\Hash::check方法的典型用法代码示例。如果您正苦于以下问题:PHP Hash::check方法的具体用法?PHP Hash::check怎么用?PHP Hash::check使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Cake\Utility\Hash
的用法示例。
在下文中一共展示了Hash::check方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authorize
/**
* Check if the user is superuser
*
* @param type $user User information object.
* @param Request $request Cake request object.
* @return bool
*/
public function authorize($user, Request $request)
{
$user = (array) $user;
$superuserField = $this->config('superuser_field');
if (Hash::check($user, $superuserField)) {
return (bool) Hash::get($user, $superuserField);
}
return false;
}
示例2: authorize
/**
* Match the current plugin/controller/action against loaded permissions
* Set a default role if no role is provided
*
* @param array $user user data
* @param Request $request request
* @return bool
*/
public function authorize($user, Request $request)
{
$roleField = $this->config('role_field');
$role = $this->config('default_role');
if (Hash::check($user, $roleField)) {
$role = Hash::get($user, $roleField);
}
$allowed = $this->_checkRules($user, $role, $request);
return $allowed;
}
示例3: getEntity
/**
* @param string $entityName
* @param array $data
* @return Entity\EntityInterface
* @throws Exception\LogicException
*/
public function getEntity($entityName, array $data = [])
{
$class = '';
$classCandidates = [__NAMESPACE__ . '\\Entity\\' . trim($entityName, '\\'), __NAMESPACE__ . '\\Entity\\Subset\\' . trim($entityName, '\\')];
foreach ($classCandidates as $classCandidate) {
if (class_exists($classCandidate)) {
$class = $classCandidate;
break;
}
}
if (!$class) {
throw new LogicException("Entity \"{$entityName}\" is undefined.");
}
$entity = new $class();
if (!$entity instanceof EntityInterface) {
throw new LogicException("Class \"{$class}\" isn't an implement of EntityInterface.");
}
foreach ($data as $key => $value) {
if (is_array($value)) {
$childEntityName = Inflector::singularize((string) Inflector::camelize($key));
if (Hash::check($value, '{s}')) {
// has string key => entity.
$value = $this->getEntity($childEntityName, $value);
} elseif (Hash::check($value, '{n}.{s}')) {
// has string key under number key => array of entities.
$children = [];
foreach ($value as $child) {
$children[] = $this->getEntity($childEntityName, $child);
}
$value = $children;
} else {
// else => array of scalar.
}
}
if (property_exists($entity, $key)) {
$entity->{$key} = $value;
}
}
return $entity;
}
示例4: hasError
/**
* Check whether or not a field has an error attached to it
*
* @param string $field A dot separated path to check errors on.
* @return bool Returns true if the errors for the field are not empty.
*/
public function hasError($field)
{
if (empty($this->_context['errors'])) {
return false;
}
return (bool) Hash::check($this->_context['errors'], $field);
}
示例5: testCheck
/**
* testCheck method
*
* @return void
*/
public function testCheck()
{
$set = ['My Index 1' => ['First' => 'The first item']];
$this->assertTrue(Hash::check($set, 'My Index 1.First'));
$this->assertTrue(Hash::check($set, 'My Index 1'));
$set = ['My Index 1' => ['First' => ['Second' => ['Third' => ['Fourth' => 'Heavy. Nesting.']]]]];
$this->assertTrue(Hash::check($set, 'My Index 1.First.Second'));
$this->assertTrue(Hash::check($set, 'My Index 1.First.Second.Third'));
$this->assertTrue(Hash::check($set, 'My Index 1.First.Second.Third.Fourth'));
$this->assertFalse(Hash::check($set, 'My Index 1.First.Seconds.Third.Fourth'));
}
示例6: processCount
public function processCount($oneEnd, $query)
{
$countTotalOnDay = [];
foreach ($query as $key => $row) {
$dateFormat = $row->date_result->i18nFormat('yyyy-MM-dd');
if ($row->one_end == $oneEnd) {
$countTotalOnDay[$dateFormat] = Hash::check($countTotalOnDay, $dateFormat) ? $countTotalOnDay[$dateFormat] + 1 : 1;
}
}
$arrDurationPresent = [];
$space = 0;
foreach ($countTotalOnDay as $key => $value) {
if ($value > 3) {
} else {
$space++;
continue;
}
$arrDurationPresent[$space]['count'] = Hash::check($arrDurationPresent, "{$space}.count") ? $arrDurationPresent[$space]['count'] + 1 : 1;
//$arrDurationPresent[$space]['date'][] = $key;
$arrDurationPresent[$space]['index'] = $space;
$space = 0;
}
$arrDurationPresent = Hash::sort($arrDurationPresent, '{n}.index', 'asc');
return $arrDurationPresent;
}
示例7: add
/**
* Add a menu item.
*
* @param $menu
* @param $path
* @param array $options
*/
public static function add($menu, $path, $options = [])
{
// Juggle argument for backward compatibility
if (is_array($path)) {
$options = $path;
$path = $menu;
$menu = self::activeMenu();
} else {
self::activeMenu($menu);
}
$pathE = explode('.', $path);
$pathE = array_splice($pathE, 0, count($pathE) - 2);
$parent = join('.', $pathE);
if (!empty($parent) && !Hash::check(self::$_items[$menu], $parent)) {
$title = Inflector::humanize(end($pathE));
$opt = ['title' => $title];
self::_setupOptions($opt);
self::add($parent, $opt);
}
self::_setupOptions($options);
$current = Hash::extract(self::$_items[$menu], $path);
if (!empty($current)) {
self::_replace(self::$_items[$menu], $path, $options);
} else {
self::$_items[$menu] = Hash::insert(self::$_items[$menu], $path, $options);
}
}
示例8: hasJraOption
/**
* Checks if a particular option is available.
*
* @param string $path
*
* @return bool
*/
public function hasJraOption($path)
{
return Hash::check($this->getJraOptions(), $path);
}