Assert\Assertion::keyNotExists PHP Method

keyNotExists() public static method

Assert that key does not exist in an array
public static keyNotExists ( 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 keyNotExists($value, $key, $message = null, $propertyPath = null)
    {
        static::isArray($value, $message, $propertyPath);
        if (array_key_exists($key, $value)) {
            $message = sprintf($message ?: 'Array contains an element with key "%s"', self::stringify($key));
            throw static::createException($value, $message, static::INVALID_KEY_NOT_EXISTS, $propertyPath, array('key' => $key));
        }
        return true;
    }

Usage Example

 /**
  * @param array $request_parameters
  */
 private function checkPreservedParameters(array $request_parameters)
 {
     $preserved_parameters = $this->getClientRuleManager()->getPreserverParameters();
     foreach ($preserved_parameters as $preserved_parameter) {
         Assertion::keyNotExists($request_parameters, $preserved_parameter, sprintf('The parameters "%s" is not allowed.', $preserved_parameter));
     }
 }