Addon
8 years ago
Admin
8 years ago
Column
8 years ago
Helper
8 years ago
ListScreen
8 years ago
Meta
8 years ago
Notice
8 years ago
Plugin
8 years ago
Relation
8 years ago
Settings
8 years ago
ThirdParty
8 years ago
API.php
8 years ago
Addon.php
8 years ago
Addons.php
8 years ago
Admin.php
8 years ago
Autoloader.php
8 years ago
Collection.php
8 years ago
Column.php
8 years ago
Container.php
8 years ago
Groups.php
8 years ago
Helper.php
8 years ago
ListScreen.php
8 years ago
ListScreenPost.php
8 years ago
Plugin.php
8 years ago
PluginInformation.php
8 years ago
Preferences.php
8 years ago
Relation.php
8 years ago
TableScreen.php
8 years ago
View.php
8 years ago
ViewInterface.php
8 years ago
Container.php
56 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | class AC_Container { |
| 8 | |
| 9 | /** |
| 10 | * @var object[] |
| 11 | */ |
| 12 | protected $services = array(); |
| 13 | |
| 14 | /** |
| 15 | * @param string $id |
| 16 | * |
| 17 | * @return false|object |
| 18 | */ |
| 19 | public function get( $id ) { |
| 20 | return $this->has( $id ) ? $this->services[ $id ] : false; |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * @param string $id |
| 25 | * @param object $service |
| 26 | * |
| 27 | * @return $this |
| 28 | */ |
| 29 | public function set( $id, $service ) { |
| 30 | if ( ! is_object( $service ) ) { |
| 31 | throw new InvalidArgumentException( sprintf( 'The %s service is not an object.', $id ) ); |
| 32 | } |
| 33 | |
| 34 | $this->services[ $id ] = $service; |
| 35 | |
| 36 | return $this; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * @param string $id |
| 41 | * |
| 42 | * @return bool |
| 43 | */ |
| 44 | public function has( $id ) { |
| 45 | return array_key_exists( $id, $this->services ); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * @return string[] |
| 50 | */ |
| 51 | public function get_ids() { |
| 52 | return array_keys( $this->services ); |
| 53 | } |
| 54 | |
| 55 | } |
| 56 |