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