-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[skip ci] create ApplicationStorage for async frameworks
- Loading branch information
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Ubiquity\utils\store; | ||
|
||
/** | ||
* Data storage for async platforms | ||
* | ||
* Ubiquity\core$Application | ||
* This class is part of Ubiquity | ||
* @author jc | ||
* @version 1.0.0 | ||
* | ||
*/ | ||
class ApplicationStorage { | ||
/** | ||
* @var array | ||
*/ | ||
private static $datas; | ||
|
||
/** | ||
* Put a value in storage at key position. | ||
* @param string $key | ||
* @param mixed $value | ||
*/ | ||
public static function put(string $key, $value){ | ||
self::$datas[$key=$value]; | ||
} | ||
|
||
/** | ||
* Return a value by key. | ||
* @param string $key | ||
* @param mixed $default | ||
* @return mixed | ||
*/ | ||
public static function get(string $key,$default=null){ | ||
return self::$datas[$key]??$default; | ||
} | ||
|
||
/** | ||
* Return all keys in storage. | ||
* @return array | ||
*/ | ||
public static function getAllKeys(){ | ||
return \array_keys(self::$datas); | ||
} | ||
|
||
/** | ||
* Return all datas in storage. | ||
* @return array | ||
*/ | ||
public static function getAll(){ | ||
return self::$datas; | ||
} | ||
|
||
/** | ||
* Check if a key exists or not. | ||
* @param string $key | ||
* @return boolean | ||
*/ | ||
public static function exists(string $key){ | ||
return isset(self::$datas[$key]); | ||
} | ||
|
||
/** | ||
* Search for a given value and returns the first corresponding key if successful. | ||
* @param mixed $value | ||
* @return string|boolean | ||
*/ | ||
public static function search($value){ | ||
return \array_search($value,self::$datas); | ||
} | ||
|
||
/** | ||
* Clear all values in storage. | ||
*/ | ||
public static function clear(){ | ||
self::$datas=[]; | ||
} | ||
|
||
/** | ||
* Remove a value by key. | ||
* @param string $key | ||
*/ | ||
public static function remove(string $key){ | ||
unset(self::$datas[$key]); | ||
} | ||
} | ||
|