-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from mcaskill/feature/improve-error-handling
Improve error handling and abstract download classes
- Loading branch information
Showing
10 changed files
with
140 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* Abstract Easy Digital Downloads (EDD) Plugin. | ||
* | ||
* @package Junaidbhura\Composer\WPProPlugins\Plugins | ||
*/ | ||
|
||
namespace Junaidbhura\Composer\WPProPlugins\Plugins; | ||
|
||
use Composer\Semver\Semver; | ||
use UnexpectedValueException; | ||
|
||
/** | ||
* AbstractEddPlugin class. | ||
*/ | ||
abstract class AbstractEddPlugin extends AbstractPlugin { | ||
|
||
/** | ||
* Get the download URL for this plugin. | ||
* | ||
* @param array<string, mixed> $response The EDD API response. | ||
* @return string | ||
*/ | ||
protected function extractDownloadUrl( array $response ) { | ||
if ( empty( $response['download_link'] ) || ! is_string( $response['download_link'] ) ) { | ||
throw new UnexpectedValueException( sprintf( | ||
'Expected a valid download URL for package %s', | ||
'junaidbhura/' . $this->slug | ||
) ); | ||
} | ||
|
||
if ( empty( $response['new_version'] ) || ! is_scalar( $response['new_version'] ) ) { | ||
throw new UnexpectedValueException( sprintf( | ||
'Expected a valid download version number for package %s', | ||
'junaidbhura/' . $this->slug | ||
) ); | ||
} | ||
|
||
if ( ! Semver::satisfies( $response['new_version'], $this->version ) ) { | ||
throw new UnexpectedValueException( sprintf( | ||
'Expected download version (%s) to match installed version (%s) of package %s', | ||
$response['new_version'], | ||
$this->version, | ||
'junaidbhura/' . $this->slug | ||
) ); | ||
} | ||
|
||
return $response['download_link']; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
/** | ||
* Abstract Plugin. | ||
* | ||
* @package Junaidbhura\Composer\WPProPlugins\Plugins | ||
*/ | ||
|
||
namespace Junaidbhura\Composer\WPProPlugins\Plugins; | ||
|
||
/** | ||
* AbstractPlugin class. | ||
*/ | ||
abstract class AbstractPlugin { | ||
|
||
/** | ||
* The version number of the plugin to download. | ||
* | ||
* @var string Version number. | ||
*/ | ||
protected $version = ''; | ||
|
||
/** | ||
* The slug of which plugin to download. | ||
* | ||
* @var string Plugin slug. | ||
*/ | ||
protected $slug = ''; | ||
|
||
/** | ||
* AbstractPlugin constructor. | ||
* | ||
* @param string $version | ||
*/ | ||
public function __construct( $version = '', $slug = '' ) { | ||
$this->version = $version; | ||
$this->slug = $slug; | ||
} | ||
|
||
/** | ||
* Get the download URL for this plugin. | ||
* | ||
* @return string | ||
*/ | ||
abstract public function getDownloadUrl(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.