Webmozart\KeyValueStore\Api\KeyValueStore::get PHP Method

get() public method

If a key does not exist in the store, the default value passed in the second parameter is returned. Any integer or string value is accepted as key. If any other type is passed for the key, an {@link InvalidKeyException} is thrown. You should make sure that you only pass valid keys to the store. If the backend of the store cannot be read, a {@link ReadException} is thrown. You should always handle this exception in your code: php try { $value = $store->get($key); } catch (ReadException $e) { read failed }
public get ( integer | string $key, mixed $default = null ) : mixed
$key integer | string The key to get.
$default mixed The default value to return if the key does not exist.
return mixed The value of the key or the default value if the key does not exist.
    public function get($key, $default = null);

Usage Example

 /**
  * {@inheritdoc}
  */
 public function getVersions($path, ResourceRepository $repository = null)
 {
     $versions = $this->store->get($path, array());
     if (empty($versions)) {
         throw NoVersionFoundException::forPath($path);
     }
     if (null !== $repository) {
         foreach ($versions as $key => $resource) {
             $resource = clone $resource;
             $resource->attachTo($repository);
             $versions[$key] = $resource;
         }
     }
     return new VersionList($path, $versions);
 }
All Usage Examples Of Webmozart\KeyValueStore\Api\KeyValueStore::get