diff --git a/src/ncc/Abstracts/ExceptionCodes.php b/src/ncc/Abstracts/ExceptionCodes.php index 11e305a..85f2e5e 100644 --- a/src/ncc/Abstracts/ExceptionCodes.php +++ b/src/ncc/Abstracts/ExceptionCodes.php @@ -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; } \ No newline at end of file diff --git a/src/ncc/Exceptions/ComponentVersionNotFoundException.php b/src/ncc/Exceptions/ComponentVersionNotFoundException.php new file mode 100644 index 0000000..ae57404 --- /dev/null +++ b/src/ncc/Exceptions/ComponentVersionNotFoundException.php @@ -0,0 +1,19 @@ +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']; diff --git a/src/ncc/Objects/NccVersionInformation/Component.php b/src/ncc/Objects/NccVersionInformation/Component.php new file mode 100644 index 0000000..35bbe79 --- /dev/null +++ b/src/ncc/Objects/NccVersionInformation/Component.php @@ -0,0 +1,80 @@ +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; + } + } \ No newline at end of file diff --git a/src/ncc/version.json b/src/ncc/version.json index 680b222..4ca1643 100644 --- a/src/ncc/version.json +++ b/src/ncc/version.json @@ -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 } \ No newline at end of file