mirror of
https://gh.wpcy.net/https://github.com/fairpm/fair-plugin.git
synced 2026-06-10 01:04:28 +08:00
Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Signed-off-by: John Blackbourn <john@johnblackbourn.com> Signed-off-by: Andy Fragen <andy@thefragens.com> Signed-off-by: Carrie Dils <carriedils@gmail.com> Signed-off-by: Norcross <andrew.norcross@gmail.com> Signed-off-by: joedolson <joedolson@users.noreply.github.com> Signed-off-by: Joe Dolson <design@joedolson.com> Signed-off-by: Shadi Sharaf <shady@sharaf.me> Signed-off-by: Chuck Adams <chaz@chaz.works> Signed-off-by: Carrie Dils <cdils@users.noreply.github.com> Signed-off-by: Mika Ipstenu Epstein <ipstenu@halfelf.org> Signed-off-by: Ipstenu (Mika Epstein) <Ipstenu@users.noreply.github.com> Signed-off-by: Mika <ipstenu@halfelf.org> Signed-off-by: Mika Epstein <ipstenu@halfelf.org> Signed-off-by: Marc Armengou <83702259+marcarmengou@users.noreply.github.com> Signed-off-by: Namith Jawahar <48271037+namithj@users.noreply.github.com> Signed-off-by: Chris Reynolds <chris@jazzsequence.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: cdils <3099408+cdils@users.noreply.github.com> Co-authored-by: Chuck Adams <chaz@chaz.works> Co-authored-by: John Blackbourn <john@johnblackbourn.com> Co-authored-by: Andy Fragen <andy@thefragens.com> Co-authored-by: Norcross <andrew.norcross@gmail.com> Co-authored-by: rmccue <21655+rmccue@users.noreply.github.com> Co-authored-by: joedolson <joedolson@users.noreply.github.com> Co-authored-by: Joe Dolson <design@joedolson.com> Co-authored-by: Shady Sharaf <shady@sharaf.me> Co-authored-by: Mika Ipstenu Epstein <ipstenu@halfelf.org> Co-authored-by: Ipstenu (Mika Epstein) <Ipstenu@users.noreply.github.com> Co-authored-by: Marc Armengou <83702259+marcarmengou@users.noreply.github.com> Co-authored-by: Namith Jawahar <48271037+namithj@users.noreply.github.com> Co-authored-by: Kaspars Dambis <hi@kaspars.net> Co-authored-by: Chris Reynolds <chris@jazzsequence.com>
109 lines
2.2 KiB
PHP
109 lines
2.2 KiB
PHP
<?php
|
|
/**
|
|
* Package data container.
|
|
*
|
|
* @package FAIR
|
|
*/
|
|
|
|
namespace FAIR\Updater;
|
|
|
|
use FAIR\Packages;
|
|
|
|
/**
|
|
* Represents a registered FAIR package (plugin or theme).
|
|
*/
|
|
abstract class Package {
|
|
|
|
/**
|
|
* The DID of the package.
|
|
*
|
|
* @var string
|
|
*/
|
|
public string $did;
|
|
|
|
/**
|
|
* Absolute path to the main file.
|
|
*
|
|
* @var string
|
|
*/
|
|
public string $filepath;
|
|
|
|
/**
|
|
* Current installed version.
|
|
*
|
|
* @var string|null
|
|
*/
|
|
public ?string $local_version;
|
|
|
|
/**
|
|
* Cached metadata document.
|
|
*
|
|
* @var \FAIR\Packages\MetadataDocument|null
|
|
*/
|
|
private $metadata = null;
|
|
|
|
/**
|
|
* Cached release document.
|
|
*
|
|
* @var \FAIR\Packages\ReleaseDocument|null
|
|
*/
|
|
private $release = null;
|
|
|
|
/**
|
|
* Constructor.
|
|
*
|
|
* @param string $did The DID of the package.
|
|
* @param string $filepath Absolute path to the main file.
|
|
*/
|
|
public function __construct( string $did, string $filepath ) {
|
|
$this->did = $did;
|
|
$this->filepath = $filepath;
|
|
$this->local_version = $filepath ? get_file_data( $filepath, [ 'Version' => 'Version' ] )['Version'] : null;
|
|
}
|
|
|
|
/**
|
|
* Get the package slug.
|
|
*
|
|
* @return string The slug (directory name for plugins, stylesheet for themes).
|
|
*/
|
|
abstract public function get_slug(): string;
|
|
|
|
/**
|
|
* Get the relative path used in update transients.
|
|
*
|
|
* @return string The relative path.
|
|
*/
|
|
abstract public function get_relative_path(): string;
|
|
|
|
/**
|
|
* Get the metadata document, fetching and caching if needed.
|
|
*
|
|
* @return \FAIR\Packages\MetadataDocument|\WP_Error|null
|
|
*/
|
|
final public function get_metadata() {
|
|
if ( $this->metadata === null ) {
|
|
$metadata = Packages\fetch_package_metadata( $this->did );
|
|
if ( ! is_wp_error( $metadata ) ) {
|
|
$this->metadata = $metadata;
|
|
}
|
|
return $metadata;
|
|
}
|
|
return $this->metadata;
|
|
}
|
|
|
|
/**
|
|
* Get the release document, fetching and caching if needed.
|
|
*
|
|
* @return \FAIR\Packages\ReleaseDocument|\WP_Error|null
|
|
*/
|
|
final public function get_release() {
|
|
if ( $this->release === null ) {
|
|
$release = Packages\get_latest_release_from_did( $this->did );
|
|
if ( ! is_wp_error( $release ) ) {
|
|
$this->release = $release;
|
|
}
|
|
return $release;
|
|
}
|
|
return $this->release;
|
|
}
|
|
}
|