Assert\Assertion::keyExists PHP Method

keyExists() public static method

Assert that key exists in an array
public static keyExists ( mixed $value, string | integer $key, string | null $message = null, string | null $propertyPath = null ) : boolean
$value mixed
$key string | integer
$message string | null
$propertyPath string | null
return boolean
    public static function keyExists($value, $key, $message = null, $propertyPath = null)
    {
        static::isArray($value, $message, $propertyPath);
        if (!array_key_exists($key, $value)) {
            $message = sprintf($message ?: 'Array does not contain an element with key "%s"', static::stringify($key));
            throw static::createException($value, $message, static::INVALID_KEY_EXISTS, $propertyPath, array('key' => $key));
        }
        return true;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @return \Jose\Object\JWKInterface[]
  */
 public function getKeys()
 {
     $content = json_decode($this->getContent(), true);
     Assertion::isArray($content, 'Invalid content.');
     Assertion::keyExists($content, 'keys', 'Invalid content.');
     return (new JWKSet($content))->getKeys();
 }
All Usage Examples Of Assert\Assertion::keyExists