lithium\util\Set::check PHP Method

check() public static method

embed:lithium\tests\cases\util\SetTest::testCheck(1-4)
public static check ( mixed $data, mixed $path = null ) : boolean
$data mixed Data to check on.
$path mixed A dot-delimited string.
return boolean `true` if path is found, `false` otherwise.
    public static function check($data, $path = null)
    {
        if (!$path) {
            return $data;
        }
        $path = is_array($path) ? $path : explode('.', $path);
        foreach ($path as $i => $key) {
            if (is_numeric($key) && (int) $key > 0 || $key === '0') {
                $key = (int) $key;
            }
            if ($i === count($path) - 1) {
                return is_array($data) && isset($data[$key]);
            } else {
                if (!is_array($data) || !isset($data[$key])) {
                    return false;
                }
                $data =& $data[$key];
            }
        }
    }

Usage Example

Beispiel #1
0
 /**
  * Delete value from the session
  *
  * @param string $key The key to be deleted
  * @param array $options Options array. Not used for this adapter method.
  * @return closure Function returning boolean `true` if the key no longer exists
  *         in the session, `false` otherwise
  */
 public static function delete($key, array $options = array())
 {
     if (!static::isStarted() && !static::_start()) {
         throw new RuntimeException("Could not start session.");
     }
     $class = __CLASS__;
     return function ($self, $params) use($class) {
         $key = $params['key'];
         $class::overwrite($_SESSION, Set::remove($_SESSION, $key));
         return !Set::check($_SESSION, $key);
     };
 }
All Usage Examples Of lithium\util\Set::check