Exception
2 weeks ago
PluginStorage.php
2 weeks ago
StaticStorage.php
2 weeks ago
StorageFactory.php
2 weeks ago
WordpressFilterStorage.php
2 weeks ago
StaticStorage.php
38 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FSVendor\WPDesk\PluginBuilder\Storage; |
| 4 | |
| 5 | use FSVendor\WPDesk\PluginBuilder\Plugin\AbstractPlugin; |
| 6 | /** |
| 7 | * Can store plugin instances in static variable |
| 8 | * |
| 9 | * @package WPDesk\PluginBuilder\Storage |
| 10 | */ |
| 11 | class StaticStorage implements PluginStorage |
| 12 | { |
| 13 | protected static $instances = []; |
| 14 | /** |
| 15 | * @param string $class |
| 16 | * @param AbstractPlugin $object |
| 17 | */ |
| 18 | public function add_to_storage($class, $object) |
| 19 | { |
| 20 | if (isset(self::$instances[$class])) { |
| 21 | throw new Exception\ClassAlreadyExists("Class {$class} already exists"); |
| 22 | } |
| 23 | self::$instances[$class] = $object; |
| 24 | } |
| 25 | /** |
| 26 | * @param string $class |
| 27 | * |
| 28 | * @return AbstractPlugin |
| 29 | */ |
| 30 | public function get_from_storage($class) |
| 31 | { |
| 32 | if (isset(self::$instances[$class])) { |
| 33 | return self::$instances[$class]; |
| 34 | } |
| 35 | throw new Exception\ClassNotExists("Class {$class} not exists in storage"); |
| 36 | } |
| 37 | } |
| 38 |