Added components to NccVersionInformation
This commit is contained in:
parent
1685964232
commit
7926ef4077
5 changed files with 153 additions and 1 deletions
|
@ -3,6 +3,7 @@
|
|||
namespace ncc\Abstracts;
|
||||
|
||||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\ComponentVersionNotFoundException;
|
||||
use ncc\Exceptions\DirectoryNotFoundException;
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\InvalidCredentialsEntryException;
|
||||
|
@ -56,4 +57,9 @@
|
|||
* @see InvalidCredentialsEntryException
|
||||
*/
|
||||
const InvalidCredentialsEntryException = -1707;
|
||||
|
||||
/**
|
||||
* @see ComponentVersionNotFoundException
|
||||
*/
|
||||
const ComponentVersionNotFoundException = -1708;
|
||||
}
|
19
src/ncc/Exceptions/ComponentVersionNotFoundException.php
Normal file
19
src/ncc/Exceptions/ComponentVersionNotFoundException.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace ncc\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use ncc\Abstracts\ExceptionCodes;
|
||||
use Throwable;
|
||||
|
||||
class ComponentVersionNotFoundException extends Exception
|
||||
{
|
||||
/**
|
||||
* @param string $message
|
||||
* @param Throwable|null $previous
|
||||
*/
|
||||
public function __construct(string $message = "", ?Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, ExceptionCodes::ComponentVersionNotFoundException, $previous);
|
||||
}
|
||||
}
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace ncc\Objects;
|
||||
|
||||
use ncc\Objects\NccVersionInformation\Component;
|
||||
|
||||
class NccVersionInformation
|
||||
{
|
||||
/**
|
||||
|
@ -25,6 +27,13 @@
|
|||
*/
|
||||
public $Flags;
|
||||
|
||||
/**
|
||||
* An array of components that ncc uses and comes pre-built with
|
||||
*
|
||||
* @var Component[]
|
||||
*/
|
||||
public $Components;
|
||||
|
||||
/**
|
||||
* The remote source for where NCC can check for available updates and how to
|
||||
* install these updates
|
||||
|
@ -40,9 +49,17 @@
|
|||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$components = [];
|
||||
|
||||
foreach($this->Components as $component)
|
||||
{
|
||||
$components[] = $component->toArray();
|
||||
}
|
||||
|
||||
return [
|
||||
'version' => $this->Version,
|
||||
'branch' => $this->Branch,
|
||||
'components' =>$components,
|
||||
'flags' => $this->Flags
|
||||
];
|
||||
}
|
||||
|
@ -62,7 +79,15 @@
|
|||
|
||||
if(isset($data['branch']))
|
||||
$NccVersionInformationObject->Branch = $data['branch'];
|
||||
|
||||
|
||||
if(isset($data['components']))
|
||||
{
|
||||
foreach($data['components'] as $datum)
|
||||
{
|
||||
$NccVersionInformationObject->Components[] = Component::fromArray($datum);
|
||||
}
|
||||
}
|
||||
|
||||
if(isset($data['version']))
|
||||
$NccVersionInformationObject->Version = $data['version'];
|
||||
|
||||
|
|
80
src/ncc/Objects/NccVersionInformation/Component.php
Normal file
80
src/ncc/Objects/NccVersionInformation/Component.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace ncc\Objects\NccVersionInformation;
|
||||
|
||||
use ncc\Exceptions\ComponentVersionNotFoundException;
|
||||
|
||||
class Component
|
||||
{
|
||||
/**
|
||||
* The Vendor of the component
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $Vendor;
|
||||
|
||||
/**
|
||||
* The name of the package
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $PackageName;
|
||||
|
||||
/**
|
||||
* Attempts to resolve the component's build version
|
||||
*
|
||||
* @param string $ncc_installation_path
|
||||
* @return string
|
||||
* @throws ComponentVersionNotFoundException
|
||||
*/
|
||||
public function getVersion(string $ncc_installation_path): string
|
||||
{
|
||||
// Auto-resolve the trailing slash
|
||||
if(substr($ncc_installation_path, -1) !== '/')
|
||||
{
|
||||
$ncc_installation_path .= $ncc_installation_path . DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
$third_party_path = $ncc_installation_path . DIRECTORY_SEPARATOR . 'ThirdParty' . DIRECTORY_SEPARATOR;
|
||||
$component_path = $third_party_path . $this->Vendor . DIRECTORY_SEPARATOR . $this->PackageName . DIRECTORY_SEPARATOR;
|
||||
|
||||
if(file_exists($component_path . 'VERSION') == false)
|
||||
{
|
||||
throw new ComponentVersionNotFoundException('The file \'' . $component_path . 'VERSION' . '\' does not exist');
|
||||
}
|
||||
|
||||
return file_get_contents($component_path . 'VERSION');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array representation of the object
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [
|
||||
'vendor' => $this->Vendor,
|
||||
'package_name' => $this->PackageName
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs object from an array representation
|
||||
*
|
||||
* @param array $data
|
||||
* @return Component
|
||||
*/
|
||||
public static function fromArray(array $data): Component
|
||||
{
|
||||
$ComponentObject = new Component();
|
||||
|
||||
if(isset($data['vendor']))
|
||||
$ComponentObject->Vendor = $data['vendor'];
|
||||
|
||||
if(isset($data['package_name']))
|
||||
$ComponentObject->PackageName = $data['package_name'];
|
||||
|
||||
return $ComponentObject;
|
||||
}
|
||||
}
|
|
@ -2,5 +2,27 @@
|
|||
"version": "1.0.0",
|
||||
"branch": "master",
|
||||
"flags": ["UNSTABLE"],
|
||||
"components": [
|
||||
{
|
||||
"vendor": "defuse",
|
||||
"package_name": "php-encryption"
|
||||
},
|
||||
{
|
||||
"vendor": "Symfony",
|
||||
"package_name": "polyfill-ctype"
|
||||
},
|
||||
{
|
||||
"vendor": "Symfony",
|
||||
"package_name": "polyfill-mbstring"
|
||||
},
|
||||
{
|
||||
"vendor": "Symfony",
|
||||
"package_name": "polyfill-Process"
|
||||
},
|
||||
{
|
||||
"vendor": "Symfony",
|
||||
"package_name": "polyfill-uid"
|
||||
}
|
||||
],
|
||||
"update_source": null
|
||||
}
|
Loading…
Add table
Reference in a new issue