diff --git a/CHANGELOG.md b/CHANGELOG.md index 8df5cb0..4e1183d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -135,6 +135,8 @@ features and reduced the number of exceptions down to 15 exceptions. - Updated class `\ncc\Objects\ProjectConfiguration > Compiler` to use method calls rather than direct property access - Updated class `\ncc\Objects\ProjectConfiguration > ExecutionPolicy` to use method calls rather than direct property access - Updated class `\ncc\Objects\ProjectConfiguration > Installer` to use method calls rather than direct property access + - Updated class `\ncc\Objects\ProjectConfiguration > Project` to use method calls rather than direct property access + - Updated class `\ncc\Objects\ProjectConfiguration > UpdateSource` to use method calls rather than direct property access ### Removed - Removed `FileNotFoundException` and `DirectoryNotFoundException` from `\ncc\Exceptions` diff --git a/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php b/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php index dbeb48d..e8fe334 100644 --- a/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php +++ b/src/ncc/Classes/ComposerExtension/ComposerSourceBuiltin.php @@ -336,9 +336,9 @@ $project_configuration->assembly->setPackage(self::toPackageName($composer_package->name)); // Add the update source - $project_configuration->project->update_source = new ProjectConfiguration\UpdateSource(); - $project_configuration->project->update_source->source = sprintf('%s@composer', str_ireplace('\\', '/', $composer_package->name)); - $project_configuration->project->update_source->repository = null; + $project_configuration->project->setUpdateSource(new ProjectConfiguration\UpdateSource()); + $project_configuration->project->getUpdateSource()?->setSource(sprintf('%s@composer', str_ireplace('\\', '/', $composer_package->name))); + $project_configuration->project->getUpdateSource()?->setRepository(null); // Process the dependencies if($composer_package->require !== null && count($composer_package->require) > 0) @@ -373,9 +373,9 @@ $project_configuration->build->setSourcePath('.src'); // Apply a compiler extension - $project_configuration->project->compiler->setExtension(CompilerExtensions::PHP); - $project_configuration->project->compiler->setMaximumVersion(CompilerExtensionSupportedVersions::PHP[0]); - $project_configuration->project->compiler->setMinimumVersion(CompilerExtensionSupportedVersions::PHP[(count(CompilerExtensionSupportedVersions::PHP) - 1)]); + $project_configuration->project->getCompiler()->setExtension(CompilerExtensions::PHP); + $project_configuration->project->getCompiler()->setMaximumVersion(CompilerExtensionSupportedVersions::PHP[0]); + $project_configuration->project->getCompiler()->setMinimumVersion(CompilerExtensionSupportedVersions::PHP[(count(CompilerExtensionSupportedVersions::PHP) - 1)]); return $project_configuration; } @@ -758,7 +758,7 @@ if (count($static_files) > 0) { - $project_configuration->project->options['static_files'] = $static_files; + $project_configuration->project->addOption('static_files', $static_files); foreach ($static_files as $file) { diff --git a/src/ncc/Classes/NccExtension/PackageCompiler.php b/src/ncc/Classes/NccExtension/PackageCompiler.php index 69df3cd..a8b2312 100644 --- a/src/ncc/Classes/NccExtension/PackageCompiler.php +++ b/src/ncc/Classes/NccExtension/PackageCompiler.php @@ -71,21 +71,21 @@ { Console::outDebug(sprintf('assembly.%s: %s', $prop, ($value ?? 'n/a'))); } - foreach($configuration->project->compiler->toArray() as $prop => $value) + foreach($configuration->project->getCompiler()->toArray() as $prop => $value) { Console::outDebug(sprintf('compiler.%s: %s', $prop, ($value ?? 'n/a'))); } } // Select the correct compiler for the specified extension - if (strtolower($configuration->project->compiler->getExtension()) === CompilerExtensions::PHP) + if (strtolower($configuration->project->getCompiler()->getExtension()) === CompilerExtensions::PHP) { /** @var CompilerInterface $Compiler */ $Compiler = new PhpCompiler($configuration, $manager->getProjectPath()); } else { - throw new NotSupportedException('The compiler extension \'' . $configuration->project->compiler->getExtension() . '\' is not supported'); + throw new NotSupportedException('The compiler extension \'' . $configuration->project->getCompiler()->getExtension() . '\' is not supported'); } $build_configuration = $configuration->build->getBuildConfiguration($build_configuration)->getName(); diff --git a/src/ncc/Classes/PhpExtension/PhpCompiler.php b/src/ncc/Classes/PhpExtension/PhpCompiler.php index 944a238..e79d35a 100644 --- a/src/ncc/Classes/PhpExtension/PhpCompiler.php +++ b/src/ncc/Classes/PhpExtension/PhpCompiler.php @@ -112,7 +112,7 @@ $this->package->main_execution_policy = $this->project->build->getMain(); // Add the option to create a symbolic link to the package - if(isset($this->project->project->options['create_symlink']) && $this->project->project->options['create_symlink'] === True) + if(isset($this->project->project->getOptions()['create_symlink']) && $this->project->project->getOptions()['create_symlink'] === True) { $this->package->header->Options['create_symlink'] = true; } @@ -126,13 +126,13 @@ ($this->package->header->RuntimeConstants ?? []) ); - $this->package->header->CompilerExtension = $this->project->project->compiler; + $this->package->header->CompilerExtension = $this->project->project->getCompiler(); $this->package->header->CompilerVersion = NCC_VERSION_NUMBER; - $this->package->header->Options = $this->project->project->options; + $this->package->header->Options = $this->project->project->getOptions(); - if($this->project->project->update_source !== null) + if($this->project->project->getUpdateSource() !== null) { - $this->package->header->UpdateSource = $this->project->project->update_source; + $this->package->header->UpdateSource = $this->project->project->getUpdateSource(); } Console::outDebug('scanning project files'); diff --git a/src/ncc/Managers/PackageManager.php b/src/ncc/Managers/PackageManager.php index 8d2e478..aef1cf3 100644 --- a/src/ncc/Managers/PackageManager.php +++ b/src/ncc/Managers/PackageManager.php @@ -415,18 +415,18 @@ Console::outDebug('no post-installation units to execute'); } - if($package->header->UpdateSource !== null && $package->header->UpdateSource->repository !== null) + if($package->header->UpdateSource !== null && $package->header->UpdateSource->getRepository() !== null) { $sources_manager = new RemoteSourcesManager(); - if($sources_manager->getRemoteSource($package->header->UpdateSource->repository->getName()) === null) + if($sources_manager->getRemoteSource($package->header->UpdateSource->getRepository()->getName()) === null) { - Console::outVerbose('Adding remote source ' . $package->header->UpdateSource->repository->getName()); + Console::outVerbose('Adding remote source ' . $package->header->UpdateSource->getRepository()->getName()); $defined_remote_source = new DefinedRemoteSource(); - $defined_remote_source->name = $package->header->UpdateSource->repository->getName(); - $defined_remote_source->host = $package->header->UpdateSource->repository->getHost(); - $defined_remote_source->type = $package->header->UpdateSource->repository->getType(); - $defined_remote_source->ssl = $package->header->UpdateSource->repository->isSsl(); + $defined_remote_source->name = $package->header->UpdateSource->getRepository()->getName(); + $defined_remote_source->host = $package->header->UpdateSource->getRepository()->getHost(); + $defined_remote_source->type = $package->header->UpdateSource->getRepository()->getType(); + $defined_remote_source->ssl = $package->header->UpdateSource->getRepository()->isSsl(); $sources_manager->addRemoteSource($defined_remote_source); } diff --git a/src/ncc/Managers/ProjectManager.php b/src/ncc/Managers/ProjectManager.php index 5dc297f..78ba2ef 100644 --- a/src/ncc/Managers/ProjectManager.php +++ b/src/ncc/Managers/ProjectManager.php @@ -125,7 +125,7 @@ $this->project_configuration = new ProjectConfiguration(); // Set the compiler information - $this->project_configuration->project->compiler = $compiler; + $this->project_configuration->project->setCompiler($compiler); // Set the assembly information $this->project_configuration->assembly->setName($name); diff --git a/src/ncc/Objects/ProjectConfiguration/Project.php b/src/ncc/Objects/ProjectConfiguration/Project.php index 63a1723..b6fe5b1 100644 --- a/src/ncc/Objects/ProjectConfiguration/Project.php +++ b/src/ncc/Objects/ProjectConfiguration/Project.php @@ -38,17 +38,17 @@ /** * @var Compiler */ - public $compiler; + private $compiler; /** * @var array */ - public $options; + private $options; /** * @var UpdateSource|null */ - public $update_source; + private $update_source; /** * Public Constructor @@ -59,6 +59,73 @@ $this->options = []; } + /** + * @return Compiler + */ + public function getCompiler(): Compiler + { + return $this->compiler; + } + + /** + * @param Compiler $compiler + */ + public function setCompiler(Compiler $compiler): void + { + $this->compiler = $compiler; + } + + /** + * @return array + */ + public function getOptions(): array + { + return $this->options; + } + + /** + * @param array $options + */ + public function setOptions(array $options): void + { + $this->options = $options; + } + + /** + * @param string $key + * @param mixed $value + * @return void + */ + public function addOption(string $key, mixed $value): void + { + $this->options[$key] = $value; + } + + /** + * @param string $key + * @return void + */ + public function removeOption(string $key): void + { + unset($this->options[$key]); + } + + /** + * @return UpdateSource|null + */ + public function getUpdateSource(): ?UpdateSource + { + return $this->update_source; + } + + /** + * @param UpdateSource|null $update_source + */ + public function setUpdateSource(?UpdateSource $update_source): void + { + $this->update_source = $update_source; + } + /** * Validates the Project object * diff --git a/src/ncc/Objects/ProjectConfiguration/UpdateSource.php b/src/ncc/Objects/ProjectConfiguration/UpdateSource.php index a16c6d3..bd41e6d 100644 --- a/src/ncc/Objects/ProjectConfiguration/UpdateSource.php +++ b/src/ncc/Objects/ProjectConfiguration/UpdateSource.php @@ -35,14 +35,46 @@ * * @var string */ - public $source; + private $source; /** * The repository to use for the source * * @var Repository|null */ - public $repository; + private $repository; + + /** + * @return string + */ + public function getSource(): string + { + return $this->source; + } + + /** + * @param string $source + */ + public function setSource(string $source): void + { + $this->source = $source; + } + + /** + * @return Repository|null + */ + public function getRepository(): ?Repository + { + return $this->repository; + } + + /** + * @param Repository|null $repository + */ + public function setRepository(?Repository $repository): void + { + $this->repository = $repository; + } /** * Returns an array representation of the object