@@ 78-90 (lines=13) @@ | ||
75 | * |
|
76 | * @return array An array of instantiated classes |
|
77 | */ |
|
78 | private static function instantiate( $classname ) { |
|
79 | ||
80 | if ( ! class_exists( $classname ) ) |
|
81 | return new \WP_Error( 'hmbkp_invalid_type_error', sprintf( __( 'Argument 1 for %s must be a valid class', 'backupwordpress' ) ), __METHOD__ ); |
|
82 | ||
83 | /** |
|
84 | * @var HMBKP_Service |
|
85 | */ |
|
86 | $class = new $classname( self::instance()->schedule ); |
|
87 | ||
88 | return $class; |
|
89 | ||
90 | } |
|
91 | ||
92 | } |
|
93 |
@@ 79-87 (lines=9) @@ | ||
76 | * @param $classname |
|
77 | * @return \WP_Error|boolean |
|
78 | */ |
|
79 | public static function register( $filepath, $classname ) { |
|
80 | if ( ! file_exists( $filepath ) ) { |
|
81 | return new \WP_Error( 'hmbkp_invalid_path_error', sprintf( __( 'Argument 1 for %s must be a valid filepath', 'backupwordpress' ), __METHOD__ ) ); |
|
82 | } |
|
83 | ||
84 | self::instance()->services[ $filepath ] = $classname; |
|
85 | ||
86 | return true; |
|
87 | } |
|
88 | ||
89 | /** |
|
90 | * De-register an existing service |
|
@@ 94-103 (lines=10) @@ | ||
91 | * @param string $filepath |
|
92 | * @return \WP_Error|boolean |
|
93 | */ |
|
94 | public static function unregister( $filepath ) { |
|
95 | ||
96 | if ( ! isset( self::instance()->services[ $filepath ] ) ) { |
|
97 | return new \WP_Error( 'hmbkp_unrecognized_service_error', sprintf( __( 'Argument 1 for %s must be a registered service', 'backupwordpress' ), __METHOD__ ) ); |
|
98 | } |
|
99 | ||
100 | unset( self::instance()->services[ $filepath ] ); |
|
101 | ||
102 | return true; |
|
103 | } |
|
104 | ||
105 | /** |
|
106 | * Instantiate the individual service classes |
|
@@ 112-125 (lines=14) @@ | ||
109 | * |
|
110 | * @return array An array of instantiated classes |
|
111 | */ |
|
112 | private static function instantiate( $classname ) { |
|
113 | ||
114 | if ( ! class_exists( $classname ) ) { |
|
115 | return new \WP_Error( 'hmbkp_invalid_type_error', sprintf( __( 'Argument 1 for %s must be a valid class', 'backupwordpress' ), __METHOD__ ) ); |
|
116 | } |
|
117 | ||
118 | /** |
|
119 | * @var Service |
|
120 | */ |
|
121 | $class = new $classname( self::instance()->schedule ); |
|
122 | ||
123 | return $class; |
|
124 | ||
125 | } |
|
126 | } |
|
127 |