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