Dependency_Service.php
1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php
namespace Wpo\Services;
// Prevent public access to this script
defined( 'ABSPATH' ) or die( );
if ( !class_exists( '\Wpo\Services\Dependency_Service' ) ) {
class Dependency_Service {
private static $instance = null;
private $dependencies = array();
private function __construct() {
}
public static function get_instance() {
if ( empty( self::$instance ) ) {
self::$instance = new Dependency_Service();
}
return self::$instance;
}
public function add( $name, $dependency ) {
$this->dependencies[ $name ] = $dependency;
}
public function get( $request_id, $name ) {
if ( array_key_exists( $name, $this->dependencies ) ) {
return $this->dependencies[ $name ];
}
return false;
}
public function remove( $request_id, $name ) {
if ( array_key_exists( $name, $this->dependencies ) ) {
unset( $this->dependencies[ $name ] );
}
}
}
}