Added hasContext to StateEntity.
This commit is contained in:
@@ -646,6 +646,14 @@ final class StateEntity implements iState
|
||||
return ag($this->context, $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function hasContext(string $key): bool
|
||||
{
|
||||
return ag_exists($this->context, $key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the value of a given key in the entity object is equal to the corresponding value in the current object.
|
||||
* Some keys are special and require special logic to compare. For example, the updated and watched keys are special
|
||||
|
||||
@@ -401,4 +401,13 @@ interface StateInterface extends LoggerAwareInterface
|
||||
* @return mixed
|
||||
*/
|
||||
public function getContext(string|null $key = null, mixed $default = null): mixed;
|
||||
|
||||
/**
|
||||
* Check if entity has contextual data.
|
||||
*
|
||||
* @param string $key key
|
||||
*
|
||||
* @return bool Return true if the entity has contextual data related to the key.
|
||||
*/
|
||||
public function hasContext(string $key): bool;
|
||||
}
|
||||
|
||||
@@ -884,5 +884,13 @@ class StateEntityTest extends TestCase
|
||||
$entity->getContext(),
|
||||
'When getContext() is called with no parameters, all context data is returned'
|
||||
);
|
||||
$this->assertTrue(
|
||||
$entity->hasContext('test'),
|
||||
'When hasContext() is called with existing key, it returns true'
|
||||
);
|
||||
$this->assertFalse(
|
||||
$entity->hasContext('not_set'),
|
||||
'When hasContext() is called with non-existing key, it returns false'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user