- Updated class \ncc\Objects\ProjectConfiguration\Build > BuildConfiguration to use method calls rather than direct

property access
 - Updated class `\ncc\Objects\ProjectConfiguration\ExecutionPolicy > Execute` to use method calls rather than direct
   property access
 - Changed all uppercase occurrences of `NCC` to `ncc` in the entire project
 - Corrected code-smell and code style issues in `\ncc\Utilities > Base64`
 - Corrected code-smell and code style issues in `\ncc\Utilities > Console`
 - Updated class `\ncc\Objects\ProjectConfiguration\ExecutionPolicy > ExitHandle` to use method calls rather than direct
   property access
 - Updated class `\ncc\Objects\ProjectConfiguration\ExecutionPolicy > ExitHandlers` to use method calls rather than
   direct property access
 - Updated class `\ncc\Objects\ProjectConfiguration\UpdateSource > Repository` to use method calls rather than direct
   property access
 - Updated class `\ncc\Objects\ProjectConfiguration > Assembly` to use method calls rather than direct property access
 - Updated class `\ncc\Objects\ProjectConfiguration > Build` to use method calls rather than direct property access
 - 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
 - Fixed all @throw tags in the project to use the correct exception class
 - Removed unused `scope` property from `\ncc\Objects\ProjectConfiguration > Build`
This commit is contained in:
Netkas 2023-08-27 01:04:35 -04:00
parent 9c76d31de9
commit dc7fcfc757
No known key found for this signature in database
GPG key ID: 5DAF58535614062B
63 changed files with 2178 additions and 972 deletions

View file

@ -23,6 +23,7 @@
namespace ncc\CLI;
use ncc\Exceptions\IOException;
use ncc\Exceptions\PathNotFoundException;
use ncc\Objects\CliHelpSection;
use ncc\Utilities\Console;
use ncc\Utilities\Functions;
@ -35,6 +36,7 @@
* @param $args
* @return void
* @throws IOException
* @throws PathNotFoundException
*/
public static function start($args): void
{
@ -69,11 +71,11 @@
Console::out('Options:');
Console::outHelpSections([
new CliHelpSection(['{command} --help'], 'Displays help information about a specific command'),
new CliHelpSection(['-v', '--version'], 'Display NCC version information'),
new CliHelpSection(['-v', '--version'], 'Display ncc version information'),
new CliHelpSection(['-l', '--log-level={silent|debug|verbose|info|warn|error|fatal}'], 'Set the logging level', 'info'),
new CliHelpSection(['--basic-ascii'], 'Uses basic ascii characters'),
new CliHelpSection(['--no-color'], 'Omits the use of colors'),
new CliHelpSection(['--no-banner'], 'Omits displaying the NCC ascii banner')
new CliHelpSection(['--no-banner'], 'Omits displaying the ncc ascii banner')
]);
}
@ -89,7 +91,7 @@
new CliHelpSection(['project'], 'Manages the current project'),
new CliHelpSection(['package'], 'Manages the package system'),
new CliHelpSection(['cred'], 'Manages credentials'),
new CliHelpSection(['config'], 'Changes NCC configuration values'),
new CliHelpSection(['config'], 'Changes ncc configuration values'),
new CliHelpSection(['source'], 'Manages remote sources'),
]);
}

View file

@ -65,18 +65,18 @@
if(isset(self::$args['ncc-cli']))
{
// Initialize NCC
// Initialize ncc
try
{
ncc::initialize();
}
catch (PathNotFoundException $e)
{
Console::outException('Cannot initialize NCC, one or more files were not found.', $e, 1);
Console::outException('Cannot initialize ncc, one or more files were not found.', $e, 1);
}
catch (Exception $e)
{
Console::outException('Cannot initialize NCC due to an unexpected error.', $e, 1);
Console::outException('Cannot initialize ncc due to an unexpected error.', $e, 1);
}
define('NCC_CLI_MODE', 1);
@ -118,7 +118,7 @@
if(in_array(NccBuildFlags::UNSTABLE, NCC_VERSION_FLAGS, true))
{
Console::outWarning('This is an unstable build of NCC, expect some features to not work as expected');
Console::outWarning('This is an unstable build of ncc, expect some features to not work as expected');
}
if(isset(self::$args['version']))
@ -184,17 +184,17 @@
}
/**
* Displays the current version of NCC
* Displays the current version of ncc
*
* @return void
*/
private static function displayVersion(): void
{
Console::out(sprintf('NCC version %s (%s)', NCC_VERSION_NUMBER, NCC_VERSION_BRANCH));
Console::out(sprintf('ncc version %s (%s)', ncc_VERSION_NUMBER, ncc_VERSION_BRANCH));
}
/**
* Returns the arguments passed to NCC
* Returns the arguments passed to ncc
*
* @return array
*/
@ -241,7 +241,7 @@
}
catch (Exception $e)
{
Console::outWarning('An error occurred while shutting down NCC, ' . $e->getMessage());
Console::outWarning('An error occurred while shutting down ncc, ' . $e->getMessage());
}
}

View file

@ -24,6 +24,7 @@
use JsonException;
use ncc\Enums\Scopes;
use ncc\Exceptions\AuthenticationException;
use ncc\Exceptions\IOException;
use ncc\Managers\ConfigurationManager;
use ncc\Objects\CliHelpSection;
@ -40,6 +41,7 @@
* @param $args
* @return void
* @throws IOException
* @throws AuthenticationException
*/
public static function start($args): void
{

View file

@ -134,29 +134,21 @@ namespace ncc\CLI\Management;
while(true)
{
try
$password = Console::passwordInput('Password/Secret: ');
if (!$entry->unlock($password))
{
$password = Console::passwordInput('Password/Secret: ');
if (!$entry->unlock($password))
$tries++;
if ($tries >= 3)
{
$tries++;
if ($tries >= 3)
{
Console::outError('Too many failed attempts.', true, 1);
return;
}
Console::outError('Invalid password.', true, 1);
}
else
{
Console::out('Authentication successful.');
Console::outError('Too many failed attempts.', true, 1);
return;
}
Console::outError('Invalid password.', true, 1);
}
catch (RuntimeException $e)
else
{
Console::outException('Cannot unlock entry.', $e, 1);
Console::out('Authentication successful.');
return;
}
}

View file

@ -315,7 +315,7 @@
Console::out(sprintf('%s=%s (%s)',
Console::formatColor($package, ConsoleColors::LIGHT_GREEN),
Console::formatColor($version, ConsoleColors::LIGHT_MAGENTA),
$package_manager->getPackageVersion($package, $version)->Compiler->extension
$package_manager->getPackageVersion($package, $version)->Compiler->getExtension()
));
}
catch(Exception $e)
@ -458,49 +458,49 @@
Console::out('Package installation details' . PHP_EOL);
if(!is_null($package->assembly->uuid))
if(!is_null($package->assembly->getUuid()))
{
Console::out(' UUID: ' . Console::formatColor($package->assembly->uuid, ConsoleColors::LIGHT_GREEN));
Console::out(' UUID: ' . Console::formatColor($package->assembly->getUuid(), ConsoleColors::LIGHT_GREEN));
}
if(!is_null($package->assembly->package))
if(!is_null($package->assembly->getPackage()))
{
Console::out(' Package: ' . Console::formatColor($package->assembly->package, ConsoleColors::LIGHT_GREEN));
Console::out(' Package: ' . Console::formatColor($package->assembly->getPackage(), ConsoleColors::LIGHT_GREEN));
}
if(!is_null($package->assembly->name))
if(!is_null($package->assembly->getName()))
{
Console::out(' Name: ' . Console::formatColor($package->assembly->name, ConsoleColors::LIGHT_GREEN));
Console::out(' Name: ' . Console::formatColor($package->assembly->getName(), ConsoleColors::LIGHT_GREEN));
}
if(!is_null($package->assembly->version))
if(!is_null($package->assembly->getVersion()))
{
Console::out(' Version: ' . Console::formatColor($package->assembly->version, ConsoleColors::LIGHT_GREEN));
Console::out(' Version: ' . Console::formatColor($package->assembly->getVersion(), ConsoleColors::LIGHT_GREEN));
}
if(!is_null($package->assembly->description))
if(!is_null($package->assembly->getDescription()))
{
Console::out(' Description: ' . Console::formatColor($package->assembly->description, ConsoleColors::LIGHT_GREEN));
Console::out(' Description: ' . Console::formatColor($package->assembly->getDescription(), ConsoleColors::LIGHT_GREEN));
}
if(!is_null($package->assembly->product))
if(!is_null($package->assembly->getProduct()))
{
Console::out(' Product: ' . Console::formatColor($package->assembly->product, ConsoleColors::LIGHT_GREEN));
Console::out(' Product: ' . Console::formatColor($package->assembly->getProduct(), ConsoleColors::LIGHT_GREEN));
}
if(!is_null($package->assembly->company))
if(!is_null($package->assembly->getCompany()))
{
Console::out(' Company: ' . Console::formatColor($package->assembly->company, ConsoleColors::LIGHT_GREEN));
Console::out(' Company: ' . Console::formatColor($package->assembly->getCompany(), ConsoleColors::LIGHT_GREEN));
}
if(!is_null($package->assembly->copyright))
if(!is_null($package->assembly->getCopyright()))
{
Console::out(' Copyright: ' . Console::formatColor($package->assembly->copyright, ConsoleColors::LIGHT_GREEN));
Console::out(' Copyright: ' . Console::formatColor($package->assembly->getCopyright(), ConsoleColors::LIGHT_GREEN));
}
if(!is_null($package->assembly->trademark))
if(!is_null($package->assembly->getTrademark()))
{
Console::out(' Trademark: ' . Console::formatColor($package->assembly->trademark, ConsoleColors::LIGHT_GREEN));
Console::out(' Trademark: ' . Console::formatColor($package->assembly->getTrademark(), ConsoleColors::LIGHT_GREEN));
}
Console::out((string)null);
@ -559,28 +559,28 @@
}
Console::out(sprintf('Extension: %s',
Console::formatColor($package->header->CompilerExtension->extension, ConsoleColors::GREEN)
Console::formatColor($package->header->CompilerExtension->getExtension(), ConsoleColors::GREEN)
));
if($package->header->CompilerExtension->maximum_version !== null)
if($package->header->CompilerExtension->getMinimumVersion() !== null)
{
Console::out(sprintf('Maximum Version: %s',
Console::formatColor($package->header->CompilerExtension->maximum_version, ConsoleColors::LIGHT_MAGENTA)
Console::formatColor($package->header->CompilerExtension->getMinimumVersion(), ConsoleColors::LIGHT_MAGENTA)
));
}
if($package->header->CompilerExtension->minimum_version !== null)
if($package->header->CompilerExtension->getMinimumVersion() !== null)
{
Console::out(sprintf('Minimum Version: %s',
Console::formatColor($package->header->CompilerExtension->minimum_version, ConsoleColors::LIGHT_MAGENTA)
Console::formatColor($package->header->CompilerExtension->getMinimumVersion(), ConsoleColors::LIGHT_MAGENTA)
));
}
if(!$user_confirmation)
{
$user_confirmation = Console::getBooleanInput(sprintf('Do you want to install %s', $package->assembly->package));
$user_confirmation = Console::getBooleanInput(sprintf('Do you want to install %s', $package->assembly->getPackage()));
}
if($user_confirmation)
@ -588,7 +588,7 @@
try
{
$package_manager->install($package_path, $credential, $installer_options);
Console::out(sprintf('Package %s installed successfully', $package->assembly->package));
Console::out(sprintf('Package %s installed successfully', $package->assembly->getPackage()));
}
catch(Exception $e)
{

View file

@ -114,7 +114,7 @@
if(in_array($compiler_extension, CompilerExtensions::ALL))
{
$Compiler->extension = $compiler_extension;
$Compiler->setExtension($compiler_extension);
}
else
{
@ -125,7 +125,7 @@
else
{
// Default PHP Extension
$Compiler->extension = CompilerExtensions::PHP;
$Compiler->setExtension(CompilerExtensions::PHP);
}
// If a minimum and maximum version is specified
@ -137,28 +137,28 @@
$max_version = strtolower($args['max-version'] ?? $args['max-ver']);
$min_version = strtolower($args['min-version'] ?? $args['min-ver']);
switch($Compiler->extension)
switch($Compiler->getExtension())
{
case CompilerExtensions::PHP:
if(!in_array($max_version, CompilerExtensionSupportedVersions::PHP))
{
Console::outError('The extension \'' . $Compiler->extension . '\' does not support version ' . $max_version, true, 1);
Console::outError('The extension \'' . $Compiler->getExtension() . '\' does not support version ' . $max_version, true, 1);
return;
}
if(!in_array($min_version, CompilerExtensionSupportedVersions::PHP))
{
Console::outError('The extension \'' . $Compiler->extension . '\' does not support version ' . $min_version, true, 1);
Console::outError('The extension \'' . $Compiler->getExtension() . '\' does not support version ' . $min_version, true, 1);
return;
}
$Compiler->maximum_version = $max_version;
$Compiler->minimum_version = $min_version;
$Compiler->setMaximumVersion($max_version);
$Compiler->setMinimumVersion($min_version);
break;
default:
Console::outError('Unsupported extension: ' . $Compiler->extension, true, 1);
Console::outError('Unsupported extension: ' . $Compiler->getExtension(), true, 1);
return;
}
}
@ -166,37 +166,37 @@
elseif(isset($args['version']) || isset($args['ver']))
{
$version = strtolower($args['version'] ?? $args['ver']);
switch($Compiler->extension)
switch($Compiler->getExtension())
{
case CompilerExtensions::PHP:
if(!in_array($version, CompilerExtensionSupportedVersions::PHP))
{
Console::outError('The extension \'' . $Compiler->extension . '\' does not support version ' . $version, true, 1);
Console::outError('The extension \'' . $Compiler->getExtension() . '\' does not support version ' . $version, true, 1);
return;
}
$Compiler->maximum_version = $version;
$Compiler->minimum_version = $version;
$Compiler->setMaximumVersion($version);
$Compiler->setMinimumVersion($version);
break;
default:
Console::outError('Unsupported extension: ' . $Compiler->extension, true, 1);
Console::outError('Unsupported extension: ' . $Compiler->getExtension(), true, 1);
return;
}
}
// If no version is specified, use the default version
else
{
switch($Compiler->extension)
switch($Compiler->getExtension())
{
case CompilerExtensions::PHP:
$Compiler->minimum_version = CompilerExtensionDefaultVersions::PHP[0];
$Compiler->maximum_version = CompilerExtensionDefaultVersions::PHP[1];
$Compiler->setMinimumVersion(CompilerExtensionDefaultVersions::PHP[0]);
$Compiler->setMaximumVersion(CompilerExtensionDefaultVersions::PHP[1]);
break;
default:
Console::outError('Unsupported extension: ' . $Compiler->extension, true, 1);
Console::outError('Unsupported extension: ' . $Compiler->getExtension(), true, 1);
return;
}
}

View file

@ -46,8 +46,6 @@ namespace ncc\Classes\BashExtension;
$execution_unit->execution_policy = $policy;
$execution_unit->Data = IO::fread($path);
$policy->execute->target = null;
return $execution_unit;
}

View file

@ -214,13 +214,13 @@
foreach ($composer_lock->Packages as $package)
{
$package_path = $base_dir . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $package->Name;
$package_path = $base_dir . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $package->name;
// Load the composer lock file
$composer_package = $composer_lock->getPackage($package->Name);
$composer_package = $composer_lock->getPackage($package->name);
if ($composer_package === null)
{
throw new PackageException(sprintf('Package "%s" not found in composer lock file', $package->Name));
throw new PackageException(sprintf('Package "%s" not found in composer lock file', $package->name));
}
// Convert it to an NCC project configuration
@ -232,10 +232,10 @@
$built_package = $project_manager->build();
// Copy the project to the build directory
$out_path = $base_dir . DIRECTORY_SEPARATOR . 'build' . DIRECTORY_SEPARATOR . sprintf('%s.ncc', $project_configuration->assembly->package);
$out_path = $base_dir . DIRECTORY_SEPARATOR . 'build' . DIRECTORY_SEPARATOR . sprintf('%s.ncc', $project_configuration->assembly->getPackage());
$filesystem->copy($built_package, $out_path);
$filesystem->remove($built_package);
$built_packages[$project_configuration->assembly->package] = $out_path;
$built_packages[$project_configuration->assembly->getPackage()] = $out_path;
}
return $built_packages;
@ -252,7 +252,7 @@
$version_map = [];
foreach($composerLock->Packages as $package)
{
$version_map[$package->Name] = $package->Version;
$version_map[$package->name] = $package->version;
}
return $version_map;
}
@ -311,42 +311,42 @@
// Generate a new project configuration object
$project_configuration = new ProjectConfiguration();
if (isset($composer_package->Name))
if (isset($composer_package->name))
{
$project_configuration->assembly->name = $composer_package->Name;
$project_configuration->assembly->setName($composer_package->name);
}
if (isset($composer_package->Description))
if (isset($composer_package->description))
{
$project_configuration->assembly->description = $composer_package->Description;
$project_configuration->assembly->setDescription($composer_package->description);
}
if(isset($version_map[$composer_package->Name]))
if(isset($version_map[$composer_package->name]))
{
$project_configuration->assembly->version = self::versionMap($composer_package->Name, $version_map);
$project_configuration->assembly->setVersion(self::versionMap($composer_package->name, $version_map));
}
if($project_configuration->assembly->version === null || $project_configuration->assembly->version === '')
if($project_configuration->assembly->getVersion() === null || $project_configuration->assembly->getVersion() === '')
{
$project_configuration->assembly->version = '1.0.0';
$project_configuration->assembly->setVersion('1.0.0');
}
$project_configuration->assembly->uuid = Uuid::v1()->toRfc4122();
$project_configuration->assembly->package = self::toPackageName($composer_package->Name);
$project_configuration->assembly->setUuid(Uuid::v1()->toRfc4122());
$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->source = sprintf('%s@composer', str_ireplace('\\', '/', $composer_package->name));
$project_configuration->project->update_source->repository = null;
// Process the dependencies
if($composer_package->Require !== null && count($composer_package->Require) > 0)
if($composer_package->require !== null && count($composer_package->require) > 0)
{
foreach ($composer_package->Require as $item)
foreach ($composer_package->require as $item)
{
// Check if the dependency is already in the project configuration
$package_name = self::toPackageName($item->PackageName);
$package_name = self::toPackageName($item->package_name);
if($package_name === null)
{
@ -356,7 +356,7 @@
$dependency = new ProjectConfiguration\Dependency();
$dependency->setName($package_name);
$dependency->setSourceType(DependencySourceType::LOCAL);
$dependency->setVersion(self::versionMap($item->PackageName, $version_map));
$dependency->setVersion(self::versionMap($item->package_name, $version_map));
$dependency->setSource($package_name . '.ncc');
$project_configuration->build->addDependency($dependency);
}
@ -364,18 +364,18 @@
// Create a build configuration
$build_configuration = new ProjectConfiguration\Build\BuildConfiguration();
$build_configuration->name = 'default';
$build_configuration->output_path = 'build';
$build_configuration->setName('default');
$build_configuration->setOutputPath('build');
// Apply the final properties
$project_configuration->build->build_configurations[] = $build_configuration;
$project_configuration->build->default_configuration = 'default';
$project_configuration->build->source_path = '.src';
$project_configuration->build->addBuildConfiguration($build_configuration);
$project_configuration->build->setDefaultConfiguration('default');
$project_configuration->build->setSourcePath('.src');
// Apply a compiler extension
$project_configuration->project->compiler->extension = CompilerExtensions::PHP;
$project_configuration->project->compiler->minimum_version = CompilerExtensionSupportedVersions::PHP[0];
$project_configuration->project->compiler->maximum_version = CompilerExtensionSupportedVersions::PHP[(count(CompilerExtensionSupportedVersions::PHP) - 1)];
$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)]);
return $project_configuration;
}
@ -674,7 +674,7 @@
$filesystem = new Filesystem();
// Process the source files
if ($composer_package->Autoload !== null)
if ($composer_package->autoload !== null)
{
$source_directory = $package_path . DIRECTORY_SEPARATOR . '.src';
@ -688,10 +688,10 @@
$static_files = [];
// Extract all the source directories
if ($composer_package->Autoload->Psr4 !== null && count($composer_package->Autoload->Psr4) > 0)
if ($composer_package->autoload->psr_4 !== null && count($composer_package->autoload->psr_4) > 0)
{
Console::outVerbose('Extracting PSR-4 source directories');
foreach ($composer_package->Autoload->Psr4 as $namespace_pointer)
foreach ($composer_package->autoload->psr_4 as $namespace_pointer)
{
if ($namespace_pointer->Path !== null && !in_array($namespace_pointer->Path, $source_directories, true))
{
@ -700,10 +700,10 @@
}
}
if ($composer_package->Autoload->Psr0 !== null && count($composer_package->Autoload->Psr0) > 0)
if ($composer_package->autoload->psr_0 !== null && count($composer_package->autoload->psr_0) > 0)
{
Console::outVerbose('Extracting PSR-0 source directories');
foreach ($composer_package->Autoload->Psr0 as $namespace_pointer)
foreach ($composer_package->autoload->psr_0 as $namespace_pointer)
{
if ($namespace_pointer->Path !== null && !in_array($namespace_pointer->Path, $source_directories, true))
{
@ -712,10 +712,10 @@
}
}
if ($composer_package->Autoload->Files !== null && count($composer_package->Autoload->Files) > 0)
if ($composer_package->autoload->files !== null && count($composer_package->autoload->files) > 0)
{
Console::outVerbose('Extracting static files');
foreach ($composer_package->Autoload->Files as $file)
foreach ($composer_package->autoload->files as $file)
{
$static_files[] = $package_path . DIRECTORY_SEPARATOR . $file;
}
@ -751,7 +751,7 @@
$parsed_path = str_ireplace($package_path . DIRECTORY_SEPARATOR, '', $item->getPathName());
Console::outDebug(sprintf('copying file %s for package %s', $parsed_path, $composer_package->Name));
Console::outDebug(sprintf('copying file %s for package %s', $parsed_path, $composer_package->name));
$filesystem->copy($item->getPathName(), $source_directory . DIRECTORY_SEPARATOR . $parsed_path);
}
}
@ -763,7 +763,7 @@
foreach ($static_files as $file)
{
$parsed_path = str_ireplace($package_path . DIRECTORY_SEPARATOR, '', $file);
Console::outDebug(sprintf('copying file %s for package %s', $parsed_path, $composer_package->Name));
Console::outDebug(sprintf('copying file %s for package %s', $parsed_path, $composer_package->name));
$filesystem->copy($file, $source_directory . DIRECTORY_SEPARATOR . $parsed_path);
unset($file);
}
@ -789,16 +789,16 @@
// Check configuration if composer.extension.display_licenses is set
if($filesystem->exists($package_path . DIRECTORY_SEPARATOR . $license_file) && Functions::cbool(Functions::getConfigurationProperty('composer.extension.display_licenses')))
{
Console::out(sprintf('License for package %s:', $composer_package->Name));
Console::out(sprintf('License for package %s:', $composer_package->name));
Console::out(IO::fread($package_path . DIRECTORY_SEPARATOR . $license_file));
break;
}
}
if(Functions::cbool(!is_null($composer_package->Authors) && count($composer_package->Authors) > 0 && Functions::getConfigurationProperty('composer.extension.display_authors')))
if(Functions::cbool(!is_null($composer_package->authors) && count($composer_package->authors) > 0 && Functions::getConfigurationProperty('composer.extension.display_authors')))
{
Console::out(sprintf('Authors for package %s:', $composer_package->Name));
foreach($composer_package->Authors as $author)
Console::out(sprintf('Authors for package %s:', $composer_package->name));
foreach($composer_package->authors as $author)
{
Console::out(sprintf(' - %s', $author->Name));

View file

@ -27,6 +27,7 @@
use ncc\Classes\HttpClient;
use ncc\Exceptions\AuthenticationException;
use ncc\Exceptions\GitException;
use ncc\Exceptions\IOException;
use ncc\Exceptions\NetworkException;
use ncc\Interfaces\RepositorySourceInterface;
use ncc\Objects\DefinedRemoteSource;
@ -49,6 +50,7 @@
* @throws AuthenticationException
* @throws GitException
* @throws NetworkException
* @throws IOException
*/
public static function getGitRepository(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults
{
@ -80,6 +82,7 @@
* @throws AuthenticationException
* @throws GitException
* @throws NetworkException
* @throws IOException
*/
public static function getRelease(RemotePackageInput $package_input, DefinedRemoteSource $defined_remote_source, ?Entry $entry = null): RepositoryQueryResults
{
@ -94,6 +97,7 @@
* @throws AuthenticationException
* @throws GitException
* @throws NetworkException
* @throws IOException
*/
public static function getNccPackage(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults
{
@ -110,6 +114,7 @@
* @throws AuthenticationException
* @throws GitException
* @throws NetworkException
* @throws IOException
*/
private static function getReleases(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): array
{
@ -180,6 +185,7 @@
* @return array
* @throws AuthenticationException
* @throws GitException
* @throws IOException
* @throws NetworkException
*/
private static function getJsonResponse(HttpRequest $httpRequest, ?Entry $entry): array
@ -207,6 +213,7 @@
* @throws AuthenticationException
* @throws GitException
* @throws NetworkException
* @throws IOException
*/
private static function processReleases(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry): mixed
{

View file

@ -26,6 +26,7 @@
use ncc\Classes\HttpClient;
use ncc\Exceptions\AuthenticationException;
use ncc\Exceptions\GitException;
use ncc\Exceptions\IOException;
use ncc\Exceptions\NetworkException;
use ncc\Exceptions\NotSupportedException;
use ncc\Interfaces\RepositorySourceInterface;
@ -49,6 +50,7 @@
* @return RepositoryQueryResults
* @throws AuthenticationException
* @throws GitException
* @throws IOException
* @throws NetworkException
*/
public static function getGitRepository(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry=null): RepositoryQueryResults
@ -91,6 +93,7 @@
* @throws AuthenticationException
* @throws GitException
* @throws NetworkException
* @throws IOException
*/
public static function getRelease(RemotePackageInput $package_input, DefinedRemoteSource $defined_remote_source, ?Entry $entry = null): RepositoryQueryResults
{
@ -181,6 +184,7 @@
* @return array
* @throws AuthenticationException
* @throws GitException
* @throws IOException
* @throws NetworkException
*/
private static function getReleases(string $owner, string $repository, DefinedRemoteSource $definedRemoteSource, ?Entry $entry): array

View file

@ -22,6 +22,7 @@
namespace ncc\Classes\LuaExtension;
use ncc\Exceptions\PathNotFoundException;
use ncc\Interfaces\RunnerInterface;
use ncc\Objects\Package\ExecutionUnit;
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
@ -32,11 +33,11 @@ namespace ncc\Classes\LuaExtension;
/**
* @inheritDoc
* @throws PathNotFoundException
*/
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
{
$execution_unit = new ExecutionUnit();
$policy->execute->target = null;
$execution_unit->execution_policy = $policy;
$execution_unit->Data = IO::fread($path);

View file

@ -46,49 +46,49 @@ namespace ncc\Classes\NccExtension;
return null;
}
if($assembly->name !== null)
if($assembly->getName() !== null)
{
$input = str_replace(AssemblyConstants::ASSEMBLY_NAME, $assembly->name, $input);
$input = str_replace(AssemblyConstants::ASSEMBLY_NAME, $assembly->getName(), $input);
}
if($assembly->package !== null)
if($assembly->getPackage() !== null)
{
$input = str_replace(AssemblyConstants::ASSEMBLY_PACKAGE, $assembly->package, $input);
$input = str_replace(AssemblyConstants::ASSEMBLY_PACKAGE, $assembly->getPackage(), $input);
}
if($assembly->description !== null)
if($assembly->getDescription() !== null)
{
$input = str_replace(AssemblyConstants::ASSEMBLY_DESCRIPTION, $assembly->description, $input);
$input = str_replace(AssemblyConstants::ASSEMBLY_DESCRIPTION, $assembly->getDescription(), $input);
}
if($assembly->company !== null)
if($assembly->getCompany() !== null)
{
$input = str_replace(AssemblyConstants::ASSEMBLY_COMPANY, $assembly->company, $input);
$input = str_replace(AssemblyConstants::ASSEMBLY_COMPANY, $assembly->getCompany(), $input);
}
if($assembly->product !== null)
if($assembly->getProduct() !== null)
{
$input = str_replace(AssemblyConstants::ASSEMBLY_PRODUCT, $assembly->product, $input);
$input = str_replace(AssemblyConstants::ASSEMBLY_PRODUCT, $assembly->getProduct(), $input);
}
if($assembly->copyright !== null)
if($assembly->getCopyright() !== null)
{
$input = str_replace(AssemblyConstants::ASSEMBLY_COPYRIGHT, $assembly->copyright, $input);
$input = str_replace(AssemblyConstants::ASSEMBLY_COPYRIGHT, $assembly->getCopyright(), $input);
}
if($assembly->trademark !== null)
if($assembly->getTrademark() !== null)
{
$input =str_replace(AssemblyConstants::ASSEMBLY_TRADEMARK, $assembly->trademark, $input);
$input =str_replace(AssemblyConstants::ASSEMBLY_TRADEMARK, $assembly->getTrademark(), $input);
}
if($assembly->version !== null)
if($assembly->getVersion() !== null)
{
$input = str_replace(AssemblyConstants::ASSEMBLY_VERSION, $assembly->version, $input);
$input = str_replace(AssemblyConstants::ASSEMBLY_VERSION, $assembly->getVersion(), $input);
}
if($assembly->uuid !== null)
if($assembly->getUuid() !== null)
{
$input = str_replace(AssemblyConstants::ASSEMBLY_UID, $assembly->uuid, $input);
$input = str_replace(AssemblyConstants::ASSEMBLY_UID, $assembly->getUuid(), $input);
}
return $input;

View file

@ -78,18 +78,18 @@
}
// Select the correct compiler for the specified extension
if (strtolower($configuration->project->compiler->extension) === CompilerExtensions::PHP)
if (strtolower($configuration->project->compiler->getExtension()) === CompilerExtensions::PHP)
{
/** @var CompilerInterface $Compiler */
$Compiler = new PhpCompiler($configuration, $manager->getProjectPath());
}
else
{
throw new NotSupportedException('The compiler extension \'' . $configuration->project->compiler->extension . '\' is not supported');
throw new NotSupportedException('The compiler extension \'' . $configuration->project->compiler->getExtension() . '\' is not supported');
}
$build_configuration = $configuration->build->getBuildConfiguration($build_configuration)->name;
Console::out(sprintf('Building %s=%s', $configuration->assembly->package, $configuration->assembly->version));
$build_configuration = $configuration->build->getBuildConfiguration($build_configuration)->getName();
Console::out(sprintf('Building %s=%s', $configuration->assembly->getPackage(), $configuration->assembly->getVersion()));
$Compiler->prepare($build_configuration);
$Compiler->build();
@ -120,7 +120,7 @@
elseif($project_type->ProjectType === ProjectType::NCC)
{
$project_manager = new ProjectManager($project_type->ProjectPath);
$project_manager->getProjectConfiguration()->assembly->version = $version;
$project_manager->getProjectConfiguration()->assembly->setVersion($version);
$project_path = $project_manager->build();
}
else
@ -131,7 +131,7 @@
if($version !== null)
{
$package = Package::load($project_path);
$package->assembly->version = Functions::convertToSemVer($version);
$package->assembly->setVersion(Functions::convertToSemVer($version));
$package->save($project_path);
}
@ -169,7 +169,7 @@
/** @var ProjectConfiguration\ExecutionPolicy $policy */
foreach($configuration->execution_policies as $policy)
{
Console::outVerbose(sprintf('Compiling Execution Policy %s', $policy->name));
Console::outVerbose(sprintf('Compiling Execution Policy %s', $policy->getName()));
/** @noinspection DisconnectedForeachInstructionInspection */
if($total_items > 5)
@ -177,7 +177,7 @@
Console::inlineProgressBar($processed_items, $total_items);
}
$unit_path = Functions::correctDirectorySeparator($path . $policy->execute->target);
$unit_path = Functions::correctDirectorySeparator($path . $policy->getExecute()->getTarget());
$execution_units[] = Functions::compileRunner($unit_path, $policy);
}
@ -207,15 +207,15 @@
// Write the package to disk
$FileSystem = new Filesystem();
$BuildConfiguration = $configuration->build->getBuildConfiguration($build_configuration);
if(!$FileSystem->exists($path . $BuildConfiguration->output_path))
if(!$FileSystem->exists($path . $BuildConfiguration->getOutputPath()))
{
Console::outDebug(sprintf('creating output directory %s', $path . $BuildConfiguration->output_path));
$FileSystem->mkdir($path . $BuildConfiguration->output_path);
Console::outDebug(sprintf('creating output directory %s', $path . $BuildConfiguration->getOutputPath()));
$FileSystem->mkdir($path . $BuildConfiguration->getOutputPath());
}
// Finally write the package to the disk
$FileSystem->mkdir($path . $BuildConfiguration->output_path);
$output_file = $path . $BuildConfiguration->output_path . DIRECTORY_SEPARATOR . $package->assembly->package . '.ncc';
$FileSystem->mkdir($path . $BuildConfiguration->getOutputPath());
$output_file = $path . $BuildConfiguration->getOutputPath() . DIRECTORY_SEPARATOR . $package->assembly->getPackage() . '.ncc';
if($FileSystem->exists($output_file))
{
Console::outDebug(sprintf('removing existing package %s', $output_file));
@ -263,7 +263,7 @@
$units = [];
foreach($package->execution_units as $executionUnit)
{
Console::outDebug(sprintf('compiling execution unit constant %s (%s)', $executionUnit->execution_policy->name, implode(', ', array_keys($refs))));
Console::outDebug(sprintf('compiling execution unit constant %s (%s)', $executionUnit->execution_policy->getName(), implode(', ', array_keys($refs))));
$units[] = self::compileExecutionUnitConstants($executionUnit, $refs);
}
$package->execution_units = $units;
@ -314,46 +314,47 @@
*/
public static function compileExecutionUnitConstants(Package\ExecutionUnit $unit, array $refs): Package\ExecutionUnit
{
$unit->execution_policy->message = self::compileConstants($unit->execution_policy->message, $refs);
$unit->execution_policy->setMessage(self::compileConstants($unit->execution_policy->getMessage(), $refs));
if($unit->execution_policy->exit_handlers !== null)
if($unit->execution_policy->getExitHandlers() !== null)
{
if($unit->execution_policy->exit_handlers->success !== null)
if($unit->execution_policy->getExitHandlers()->getSuccess()?->getMessage() !== null)
{
$unit->execution_policy->exit_handlers->success->message = self::compileConstants($unit->execution_policy->exit_handlers->success->message, $refs);
$unit->execution_policy->getExitHandlers()->getSuccess()?->setMessage(
self::compileConstants($unit->execution_policy->getExitHandlers()->getSuccess()->getMessage(), $refs)
);
}
if($unit->execution_policy->exit_handlers->error !== null)
if($unit->execution_policy->getExitHandlers()->getError()?->getMessage() !== null)
{
$unit->execution_policy->exit_handlers->error->message = self::compileConstants($unit->execution_policy->exit_handlers->error->message, $refs);
$unit->execution_policy->getExitHandlers()->getError()?->setMessage(
self::compileConstants($unit->execution_policy->getExitHandlers()->getError()->getMessage(), $refs)
);
}
if($unit->execution_policy->exit_handlers->warning !== null)
if($unit->execution_policy->getExitHandlers()->getWarning()?->getMessage() !== null)
{
$unit->execution_policy->exit_handlers->warning->message = self::compileConstants($unit->execution_policy->exit_handlers->warning->message, $refs);
$unit->execution_policy->getExitHandlers()->getWarning()?->setMessage(
self::compileConstants($unit->execution_policy->getExitHandlers()->getWarning()->getMessage(), $refs)
);
}
}
if($unit->execution_policy->execute !== null)
if($unit->execution_policy->getExecute() !== null)
{
if($unit->execution_policy->execute->target !== null)
{
$unit->execution_policy->execute->target = self::compileConstants($unit->execution_policy->execute->target, $refs);
}
$unit->execution_policy->getExecute()->setTarget(self::compileConstants($unit->execution_policy->getExecute()->getTarget(), $refs));
$unit->execution_policy->getExecute()->setWorkingDirectory(self::compileConstants($unit->execution_policy->getExecute()->getWorkingDirectory(), $refs));
if($unit->execution_policy->execute->working_directory !== null)
{
$unit->execution_policy->execute->working_directory = self::compileConstants($unit->execution_policy->execute->working_directory, $refs);
}
if($unit->execution_policy->execute->options !== null && count($unit->execution_policy->execute->options) > 0)
if(count($unit->execution_policy->getExecute()->getOptions()) > 0)
{
$options = [];
foreach($unit->execution_policy->execute->options as $key=> $value)
foreach($unit->execution_policy->getExecute()->getOptions() as $key=> $value)
{
$options[self::compileConstants($key, $refs)] = self::compileConstants($value, $refs);
}
$unit->execution_policy->execute->options = $options;
$unit->execution_policy->getExecute()->setOptions($options);
}
}

View file

@ -56,7 +56,7 @@
$ExecutionPointerManager = new ExecutionPointerManager();
$ExecutionPointerManager->addUnit($package, $version, $unit, true);
$ExecutionPointerManager->executeUnit($package, $version, $unit->execution_policy->name);
$ExecutionPointerManager->executeUnit($package, $version, $unit->execution_policy->getName());
$ExecutionPointerManager->cleanTemporaryUnits();
}
}

View file

@ -43,7 +43,6 @@
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
{
$execution_unit = new ExecutionUnit();
$policy->execute->target = null;
if(!file_exists($path) && !is_file($path))
{

View file

@ -35,6 +35,7 @@
use ncc\Exceptions\BuildException;
use ncc\Exceptions\ConfigurationException;
use ncc\Exceptions\IOException;
use ncc\Exceptions\NotSupportedException;
use ncc\Exceptions\OperationException;
use ncc\Exceptions\PackageException;
use ncc\Exceptions\PathNotFoundException;
@ -42,6 +43,7 @@
use ncc\Managers\PackageLockManager;
use ncc\Objects\Package;
use ncc\Objects\ProjectConfiguration;
use ncc\Objects\ProjectConfiguration\Dependency;
use ncc\ThirdParty\nikic\PhpParser\ParserFactory;
use ncc\ThirdParty\Symfony\Filesystem\Filesystem;
use ncc\ThirdParty\theseer\DirectoryScanner\DirectoryScanner;
@ -106,8 +108,8 @@
// Create the package object
$this->package = new Package();
$this->package->assembly = $this->project->assembly;
$this->package->dependencies = $this->project->build->dependencies;
$this->package->main_execution_policy = $this->project->build->main;
$this->package->dependencies = $this->project->build->getDependencies();
$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)
@ -119,8 +121,8 @@
// Global constants are overridden
$this->package->header->RuntimeConstants = [];
$this->package->header->RuntimeConstants = array_merge(
($selected_build_configuration->define_constants ?? []),
($this->project->build->define_constants ?? []),
$selected_build_configuration->getDefineConstants(),
($this->project->build->getDefineConstants()),
($this->package->header->RuntimeConstants ?? [])
);
@ -137,11 +139,11 @@
Console::outDebug('theseer\DirectoryScanner - Copyright (c) 2009-2014 Arne Blankerts <arne@blankerts.de> All rights reserved.');
// First scan the project files and create a file struct.
$DirectoryScanner = new DirectoryScanner();
$directory_scanner = new DirectoryScanner();
try
{
$DirectoryScanner->unsetFlag(FilesystemIterator::FOLLOW_SYMLINKS);
$directory_scanner->unsetFlag(FilesystemIterator::FOLLOW_SYMLINKS);
}
catch (Exception $e)
{
@ -149,14 +151,14 @@
}
// Include file components that can be compiled
$DirectoryScanner->setIncludes(ComponentFileExtensions::PHP);
$directory_scanner->setIncludes(ComponentFileExtensions::PHP);
if($selected_build_configuration->exclude_files !== null && count($selected_build_configuration->exclude_files) > 0)
if(count($selected_build_configuration->getExcludeFiles()) > 0)
{
$DirectoryScanner->setExcludes($selected_build_configuration->exclude_files);
$directory_scanner->setExcludes($selected_build_configuration->getExcludeFiles());
}
$source_path = $this->path . $this->project->build->source_path;
$source_path = $this->path . $this->project->build->getSourcePath();
// TODO: Re-implement the scanning process outside the compiler, as this is will be redundant
// Scan for components first.
@ -165,7 +167,7 @@
Console::outVerbose('Scanning for components... ');
/** @var SplFileInfo $item */
/** @noinspection PhpRedundantOptionalArgumentInspection */
foreach($DirectoryScanner($source_path, True) as $item)
foreach($directory_scanner($source_path, True) as $item)
{
// Ignore directories, they're not important. :-)
if(is_dir($item->getPathName()))
@ -173,11 +175,11 @@
continue;
}
$Component = new Package\Component();
$Component->name = Functions::removeBasename($item->getPathname(), $this->path);
$this->package->components[] = $Component;
$component = new Package\Component();
$component->name = Functions::removeBasename($item->getPathname(), $this->path);
$this->package->components[] = $component;
Console::outVerbose(sprintf('Found component %s', $Component->name));
Console::outVerbose(sprintf('Found component %s', $component->name));
}
if(count($this->package->components) > 0)
@ -190,22 +192,22 @@
}
// Clear previously excludes and includes
$DirectoryScanner->setExcludes();
$DirectoryScanner->setIncludes();
$directory_scanner->setExcludes();
$directory_scanner->setIncludes();
// Ignore component files
if($selected_build_configuration->exclude_files !== null && count($selected_build_configuration->exclude_files) > 0)
if(count($selected_build_configuration->getExcludeFiles()) > 0)
{
$DirectoryScanner->setExcludes(array_merge($selected_build_configuration->exclude_files, ComponentFileExtensions::PHP));
$directory_scanner->setExcludes(array_merge($selected_build_configuration->getExcludeFiles(), ComponentFileExtensions::PHP));
}
else
{
$DirectoryScanner->setExcludes(ComponentFileExtensions::PHP);
$directory_scanner->setExcludes(ComponentFileExtensions::PHP);
}
Console::outVerbose('Scanning for resources... ');
/** @var SplFileInfo $item */
foreach($DirectoryScanner($source_path) as $item)
foreach($directory_scanner($source_path) as $item)
{
// Ignore directories, they're not important. :-)
if(is_dir($item->getPathName()))
@ -213,11 +215,11 @@
continue;
}
$Resource = new Package\Resource();
$Resource->Name = Functions::removeBasename($item->getPathname(), $this->path);
$this->package->resources[] = $Resource;
$resource = new Package\Resource();
$resource->Name = Functions::removeBasename($item->getPathname(), $this->path);
$this->package->resources[] = $resource;
Console::outVerbose(sprintf('found resource %s', $Resource->Name));
Console::outVerbose(sprintf('found resource %s', $resource->Name));
}
if(count($this->package->resources) > 0)
@ -236,14 +238,14 @@
$selected_dependencies = [];
if($this->project->build->dependencies !== null && count($this->project->build->dependencies) > 0)
if(count($this->project->build->getDependencies()) > 0)
{
$selected_dependencies = array_merge($selected_dependencies, $this->project->build->dependencies);
$selected_dependencies = array_merge($selected_dependencies, $this->project->build->getDependencies());
}
if($selected_build_configuration->dependencies !== null && count($selected_build_configuration->dependencies) > 0)
if(count($selected_build_configuration->getDependencies()) > 0)
{
$selected_dependencies = array_merge($selected_dependencies, $selected_build_configuration->dependencies);
$selected_dependencies = array_merge($selected_dependencies, $selected_build_configuration->getDependencies());
}
// Process the dependencies
@ -252,14 +254,14 @@
$package_lock_manager = new PackageLockManager();
$filesystem = new Filesystem();
$lib_path = $selected_build_configuration->output_path . DIRECTORY_SEPARATOR . 'libs';
$lib_path = $selected_build_configuration->getOutputPath() . DIRECTORY_SEPARATOR . 'libs';
if($filesystem->exists($lib_path))
{
$filesystem->remove($lib_path);
}
Console::outVerbose('Scanning for dependencies... ');
/** @var \ncc\Objects\ProjectConfiguration\Dependency $dependency */
/** @var Dependency $dependency */
foreach($selected_dependencies as $dependency)
{
Console::outVerbose(sprintf('processing dependency %s', $dependency->getName()));
@ -325,10 +327,10 @@
* Executes the compile process in the correct order and returns the finalized Package object
*
* @return Package|null
* @throws \ncc\Exceptions\BuildException
* @throws \ncc\Exceptions\IOException
* @throws \ncc\Exceptions\NotSupportedException
* @throws \ncc\Exceptions\PathNotFoundException
* @throws BuildException
* @throws IOException
* @throws NotSupportedException
* @throws PathNotFoundException
*/
public function build(): ?Package
{
@ -386,7 +388,7 @@
// Get the data and
$resource->Data = IO::fread(Functions::correctDirectorySeparator($this->path . $resource->Name));
$resource->Data = Base64::encode($resource->Data);
$resource->Name = str_replace($this->project->build->source_path, (string)null, $resource->Name);
$resource->Name = str_replace($this->project->build->getSourcePath(), (string)null, $resource->Name);
$resource->updateChecksum();
$resources[] = $resource;
@ -454,7 +456,7 @@
unset($parser);
$component->name = str_replace($this->project->build->source_path, (string)null, $component->name);
$component->name = str_replace($this->project->build->getSourcePath(), (string)null, $component->name);
$component->updateChecksum();
$components[] = $component;
++$processed_items;
@ -468,9 +470,9 @@
/**
* @return void
* @throws \ncc\Exceptions\IOException
* @throws \ncc\Exceptions\NotSupportedException
* @throws \ncc\Exceptions\PathNotFoundException
* @throws IOException
* @throws NotSupportedException
* @throws PathNotFoundException
*/
public function compileExecutionPolicies(): void
{

View file

@ -46,8 +46,6 @@
throw new PathNotFoundException($path);
}
$policy->execute->target = null;
$execution_unit->execution_policy = $policy;
$execution_unit->Data = IO::fread($path);

View file

@ -84,7 +84,7 @@
try
{
Constants::register($assembly->package, $name, $value, true);
Constants::register($assembly->getPackage(), $name, $value, true);
}
catch (IntegrityException $e)
{

View file

@ -49,7 +49,6 @@
throw new PathNotFoundException($path);
}
$policy->execute->target = null;
$execution_unit->execution_policy = $policy;
$execution_unit->Data = IO::fread($path);

View file

@ -49,7 +49,6 @@
throw new PathNotFoundException($path);
}
$policy->execute->target = null;
$execution_unit->execution_policy = $policy;
$execution_unit->Data = IO::fread($path);

View file

@ -49,7 +49,6 @@
throw new PathNotFoundException($path);
}
$policy->execute->target = null;
$execution_unit->execution_policy = $policy;
$execution_unit->Data = IO::fread($path);

View file

@ -22,10 +22,11 @@
namespace ncc\Exceptions;
use Exception;
use ncc\Enums\ExceptionCodes;
use Throwable;
class IntegrityException extends \Exception
class IntegrityException extends Exception
{
public function __construct(string $message = "", ?Throwable $previous = null)
{

View file

@ -28,8 +28,30 @@
class PathNotFoundException extends Exception
{
/**
* @var string
*/
private string $path;
/**
* PathNotFoundException constructor.
*
* @param string $path
* @param Throwable|null $previous
*/
public function __construct(string $path, ?Throwable $previous = null)
{
parent::__construct(sprintf('Path "%s" not found', $path), ExceptionCodes::PATH_NOT_FOUND, $previous);
$this->path = $path;
}
/**
* Returns the path that was not found
*
* @return string
*/
public function getPath(): string
{
return $this->path;
}
}

View file

@ -44,5 +44,4 @@
* @return string
*/
public static function getFileExtension(): string;
}

View file

@ -82,6 +82,7 @@
* Saves the configuration file to disk
*
* @return void
* @throws AuthenticationException
* @throws IOException
*/
public function save(): void
@ -142,6 +143,7 @@
* @param $value
* @return bool
* @throws IOException
* @throws AuthenticationException
*/
public function updateProperty(string $property, $value): bool
{

View file

@ -29,6 +29,7 @@
use ncc\Enums\Versions;
use ncc\Exceptions\AuthenticationException;
use ncc\Exceptions\IOException;
use ncc\Exceptions\PathNotFoundException;
use ncc\Exceptions\RuntimeException;
use ncc\Objects\Vault;
use ncc\Utilities\Console;
@ -76,6 +77,7 @@
* Constructs the store file if it doesn't exist on the system (First initialization)
*
* @return void
* @throws AuthenticationException
* @throws IOException
*/
public function constructStore(): void
@ -105,6 +107,7 @@
*
* @return void
* @throws IOException
* @throws PathNotFoundException
* @throws RuntimeException
*/
private function loadVault(): void
@ -137,6 +140,7 @@
* Saves the vault to the disk
*
* @return void
* @throws AuthenticationException
* @throws IOException
*/
public function saveVault(): void

View file

@ -174,15 +174,15 @@
{
if(Resolver::resolveScope() !== Scopes::SYSTEM)
{
throw new AuthenticationException('Cannot add new ExecutionUnit \'' . $unit->execution_policy->name .'\' for ' . $package . ', insufficient permissions');
throw new AuthenticationException('Cannot add new ExecutionUnit \'' . $unit->execution_policy->getName() .'\' for ' . $package . ', insufficient permissions');
}
Console::outVerbose(sprintf('Adding new ExecutionUnit \'%s\' for %s', $unit->execution_policy->name, $package));
Console::outVerbose(sprintf('Adding new ExecutionUnit \'%s\' for %s', $unit->execution_policy->getName(), $package));
$package_id = $this->getPackageId($package, $version);
$package_config_path = $this->runner_path . DIRECTORY_SEPARATOR . $package_id . '.inx';
$package_bin_path = $this->runner_path . DIRECTORY_SEPARATOR . $package_id;
$entry_point_path = $package_bin_path . DIRECTORY_SEPARATOR . hash('haval128,4', $unit->execution_policy->name) . '.entrypoint';
$entry_point_path = $package_bin_path . DIRECTORY_SEPARATOR . hash('haval128,4', $unit->execution_policy->getName()) . '.entrypoint';
Console::outDebug(sprintf('package_id=%s', $package_id));
Console::outDebug(sprintf('package_config_path=%s', $package_config_path));
@ -201,8 +201,8 @@
$execution_pointers = ExecutionPointers::fromArray(ZiProto::decode(IO::fread($package_config_path)));
}
$bin_file = $package_bin_path . DIRECTORY_SEPARATOR . hash('haval128,4', $unit->execution_policy->name);
$bin_file .= match ($unit->execution_policy->runner)
$bin_file = $package_bin_path . DIRECTORY_SEPARATOR . hash('haval128,4', $unit->execution_policy->getName());
$bin_file .= match ($unit->execution_policy->getRunner())
{
Runners::BASH => BashRunner::getFileExtension(),
Runners::PHP => PhpRunner::getFileExtension(),
@ -211,7 +211,7 @@
Runners::PYTHON_2 => Python2Runner::getFileExtension(),
Runners::PYTHON_3 => Python3Runner::getFileExtension(),
Runners::LUA => LuaRunner::getFileExtension(),
default => throw new NotSupportedException('The runner \'' . $unit->execution_policy->runner . '\' is not supported'),
default => throw new NotSupportedException('The runner \'' . $unit->execution_policy->getRunner() . '\' is not supported'),
};
Console::outDebug(sprintf('bin_file=%s', $bin_file));
@ -237,7 +237,7 @@
$entry_point = sprintf("#!%s\nncc exec --package=\"%s\" --exec-version=\"%s\" --exec-unit=\"%s\" --exec-args \"$@\"",
'/bin/bash',
$package, $version, $unit->execution_policy->name
$package, $version, $unit->execution_policy->getName()
);
if(file_exists($entry_point_path))
@ -250,11 +250,11 @@
if($temporary)
{
Console::outVerbose(sprintf('Adding temporary ExecutionUnit \'%s\' for %s', $unit->execution_policy->name, $package));
Console::outVerbose(sprintf('Adding temporary ExecutionUnit \'%s\' for %s', $unit->execution_policy->getName(), $package));
$this->temporary_units[] = [
'package' => $package,
'version' => $version,
'unit' => $unit->execution_policy->name
'unit' => $unit->execution_policy->getName()
];
}
}
@ -351,8 +351,8 @@
$results = [];
foreach($execution_pointers->getPointers() as $pointer)
{
Console::outDebug(sprintf('unit %s', $pointer->execution_policy->name));
$results[] = $pointer->execution_policy->name;
Console::outDebug(sprintf('unit %s', $pointer->execution_policy->getName()));
$results[] = $pointer->execution_policy->getName();
}
return $results;
@ -390,34 +390,32 @@
throw new OperationException('The execution unit \'' . $name . '\' was not found for \'' . $package . '=' .$version .'\'');
}
Console::outDebug(sprintf('unit=%s', $unit->execution_policy->name));
Console::outDebug(sprintf('runner=%s', $unit->execution_policy->runner));
Console::outDebug(sprintf('unit=%s', $unit->execution_policy->getName()));
Console::outDebug(sprintf('runner=%s', $unit->execution_policy->getRunner()));
Console::outDebug(sprintf('file=%s', $unit->file_pointer));
Console::outDebug(sprintf('pass_thru_args=%s', implode(' ', $args)));
// Handle the arguments
if($unit->execution_policy->execute->options !== null && count($unit->execution_policy->execute->options) > 0)
if(count($unit->execution_policy->getExecute()->getOptions()) > 0)
{
$args = array_merge($args, $unit->execution_policy->execute->options);
$args = array_merge($args, $unit->execution_policy->getExecute()->getOptions());
foreach($unit->execution_policy->execute->options as $option)
foreach($unit->execution_policy->getExecute()->getOptions() as $option)
{
$args[] = ConstantCompiler::compileRuntimeConstants($option);
}
}
$process = new Process(array_merge(
[PathFinder::findRunner(strtolower($unit->execution_policy->runner)), $unit->file_pointer], $args)
[PathFinder::findRunner(strtolower($unit->execution_policy->getRunner())), $unit->file_pointer], $args)
);
if($unit->execution_policy->execute->working_directory !== null)
{
$process->setWorkingDirectory(ConstantCompiler::compileRuntimeConstants($unit->execution_policy->execute->working_directory));
}
$process->setWorkingDirectory(ConstantCompiler::compileRuntimeConstants($unit->execution_policy->getExecute()->getWorkingDirectory()));
if($unit->execution_policy->execute->timeout !== null)
if(is_null($unit->execution_policy->getExecute()->getTimeout()))
{
$process->setTimeout((float)$unit->execution_policy->execute->timeout);
$process->setTimeout((float)$unit->execution_policy->getExecute()->getTimeout());
}
else
{
@ -427,12 +425,12 @@
try
{
if($unit->execution_policy->execute->silent)
if($unit->execution_policy->getExecute()->isSilent())
{
$process->disableOutput();
$process->setTty(false);
}
elseif($unit->execution_policy->execute->tty)
elseif($unit->execution_policy->getExecute()->isTty())
{
$process->enableOutput();
$process->setTty(true);
@ -459,16 +457,16 @@
Console::outDebug(sprintf('working_directory=%s', $process->getWorkingDirectory()));
Console::outDebug(sprintf('timeout=%s', (int)$process->getTimeout()));
Console::outDebug(sprintf('silent=%s', ($unit->execution_policy->execute->silent ? 'true' : 'false')));
Console::outDebug(sprintf('tty=%s', ($unit->execution_policy->execute->tty ? 'true' : 'false')));
Console::outDebug(sprintf('silent=%s', ($unit->execution_policy->getExecute()->isSilent() ? 'true' : 'false')));
Console::outDebug(sprintf('tty=%s', ($unit->execution_policy->getExecute()->isTty() ? 'true' : 'false')));
Console::outDebug(sprintf('options=%s', implode(' ', $args)));
Console::outDebug(sprintf('cmd=%s', $process->getCommandLine()));
try
{
if($unit->execution_policy->message !== null)
if($unit->execution_policy->getMessage() !== null)
{
Console::out($unit->execution_policy->message);
Console::out($unit->execution_policy->getMessage());
}
$process->run(function ($type, $buffer)
@ -480,33 +478,33 @@
}
catch(Exception $e)
{
if($unit->execution_policy->exit_handlers !== null && $unit->execution_policy->exit_handlers->error !== null)
if($unit->execution_policy->getExitHandlers() !== null && $unit->execution_policy->getExitHandlers()->getError() !== null)
{
$this->handleExit($package, $version, $unit->execution_policy->exit_handlers->error);
$this->handleExit($package, $version, $unit->execution_policy->getExitHandlers()->getError());
}
Console::outException(sprintf('An error occurred while executing the unit \'%s\' for \'%s\' (exit code %s)', $unit->execution_policy->name, $package, $process->getExitCode()), $e);
Console::outException(sprintf('An error occurred while executing the unit \'%s\' for \'%s\' (exit code %s)', $unit->execution_policy->getName(), $package, $process->getExitCode()), $e);
}
finally
{
Console::outDebug(sprintf('exit_code=%s', $process->getExitCode()));
}
if($unit->execution_policy->exit_handlers !== null)
if($unit->execution_policy->getExitHandlers() !== null)
{
if($unit->execution_policy->exit_handlers->success !== null && $process->isSuccessful())
if($unit->execution_policy->getExitHandlers()->getSuccess() !== null && $process->isSuccessful())
{
$this->handleExit($package, $version, $unit->execution_policy->exit_handlers->success);
$this->handleExit($package, $version, $unit->execution_policy->getExitHandlers()->getSuccess());
}
elseif($unit->execution_policy->exit_handlers->error !== null && $process->isSuccessful())
elseif($unit->execution_policy->getExitHandlers()->getError() !== null && $process->isSuccessful())
{
$this->handleExit($package, $version, $unit->execution_policy->exit_handlers->error);
$this->handleExit($package, $version, $unit->execution_policy->getExitHandlers()->getError());
}
else
{
$this->handleExit($package, $version, $unit->execution_policy->exit_handlers->success, $process);
$this->handleExit($package, $version, $unit->execution_policy->exit_handlers->warning, $process);
$this->handleExit($package, $version, $unit->execution_policy->exit_handlers->error, $process);
$this->handleExit($package, $version, $unit->execution_policy->getExitHandlers()->getSuccess(), $process);
$this->handleExit($package, $version, $unit->execution_policy->getExitHandlers()->getWarning(), $process);
$this->handleExit($package, $version, $unit->execution_policy->getExitHandlers()->getError(), $process);
}
}
@ -532,26 +530,26 @@
if($unit === null)
{
throw new OperationException(sprintf('No execution unit named \'%s\' is available for package \'%s\'', $unit_name, $package->assembly->package));
throw new OperationException(sprintf('No execution unit named \'%s\' is available for package \'%s\'', $unit_name, $package->assembly->getPackage()));
}
// Get the required units
$required_units = [];
if($unit->execution_policy->exit_handlers !== null)
if($unit->execution_policy->getExitHandlers() !== null)
{
$required_unit = $unit->execution_policy?->exit_handlers?->success?->run;
$required_unit = $unit->execution_policy?->getExitHandlers()?->getSuccess()?->getRun();
if($required_unit !== null)
{
$required_units[] = $required_unit;
}
$required_unit = $unit->execution_policy?->exit_handlers?->warning?->run;
$required_unit = $unit->execution_policy?->getExitHandlers()?->getWarning()?->getRun();
if($required_unit !== null)
{
$required_units[] = $required_unit;
}
$required_unit = $unit->execution_policy?->exit_handlers?->error?->run;
$required_unit = $unit->execution_policy?->getExitHandlers()?->getError()?->getRun();
if($required_unit !== null)
{
$required_units = $required_unit;
@ -559,13 +557,13 @@
}
// Install the units temporarily
$this->addUnit($package->assembly->package, $package->assembly->version, $unit, true);
$this->addUnit($package->assembly->getPackage(), $package->assembly->getVersion(), $unit, true);
foreach($required_units as $r_unit)
{
$this->addUnit($package->assembly->package, $package->assembly->version, $r_unit, true);
$this->addUnit($package->assembly->getPackage(), $package->assembly->getVersion(), $r_unit, true);
}
$this->executeUnit($package->assembly->package, $package->assembly->version, $unit_name);
$this->executeUnit($package->assembly->getPackage(), $package->assembly->getVersion(), $unit_name);
$this->cleanTemporaryUnits();
}
@ -586,28 +584,28 @@
*/
public function handleExit(string $package, string $version, ExitHandle $exit_handler, ?Process $process=null): bool
{
if($exit_handler->message !== null)
if($exit_handler->getMessage() !== null)
{
Console::out($exit_handler->message);
Console::out($exit_handler->getMessage());
}
if($process !== null && !$exit_handler->end_process)
if($process !== null && !$exit_handler->getEndProcess())
{
if($exit_handler->exit_code !== $process->getExitCode())
if($exit_handler->getExitCode() !== $process->getExitCode())
{
return false;
}
}
elseif($exit_handler->end_process)
elseif($exit_handler->getEndProcess())
{
Console::outDebug(sprintf('exit_code=%s', $process->getExitCode()));
exit($exit_handler->exit_code);
exit($exit_handler->getExitCode());
}
if($exit_handler->run !== null)
if($exit_handler->getRun() !== null)
{
Console::outVerbose('Running unit \'' . $exit_handler->run . '\'');
$this->executeUnit($package, $version, $exit_handler->run);
Console::outVerbose('Running unit \'' . $exit_handler->getRun() . '\'');
$this->executeUnit($package, $version, $exit_handler->getRun());
}
return true;

View file

@ -39,6 +39,7 @@
use ncc\Classes\PhpExtension\PhpInstaller;
use ncc\CLI\Main;
use ncc\Exceptions\AuthenticationException;
use ncc\Exceptions\ConfigurationException;
use ncc\Exceptions\IOException;
use ncc\Exceptions\NotSupportedException;
use ncc\Exceptions\OperationException;
@ -101,6 +102,7 @@
* @throws OperationException
* @throws PackageException
* @throws PathNotFoundException
* @throws ConfigurationException
*/
public function install(string $package_path, ?Entry $entry=null, array $options=[]): string
{
@ -116,14 +118,14 @@
$package = Package::load($package_path);
if(RuntimeCache::get(sprintf('installed.%s=%s', $package->assembly->package, $package->assembly->version)))
if(RuntimeCache::get(sprintf('installed.%s=%s', $package->assembly->getPackage(), $package->assembly->getVersion())))
{
Console::outDebug(sprintf('skipping installation of %s=%s, already processed', $package->assembly->package, $package->assembly->version));
return $package->assembly->package;
Console::outDebug(sprintf('skipping installation of %s=%s, already processed', $package->assembly->getPackage(), $package->assembly->getVersion()));
return $package->assembly->getPackage();
}
$extension = $package->header->CompilerExtension->extension;
$installation_paths = new InstallationPaths($this->packages_path . DIRECTORY_SEPARATOR . $package->assembly->package . '=' . $package->assembly->version);
$extension = $package->header->CompilerExtension->getExtension();
$installation_paths = new InstallationPaths($this->packages_path . DIRECTORY_SEPARATOR . $package->assembly->getPackage() . '=' . $package->assembly->getVersion());
$installer = match ($extension)
{
@ -131,20 +133,20 @@
default => throw new NotSupportedException(sprintf('Compiler extension %s is not supported with ncc', $extension))
};
if($this->getPackageVersion($package->assembly->package, $package->assembly->version) !== null)
if($this->getPackageVersion($package->assembly->getPackage(), $package->assembly->getVersion()) !== null)
{
if(in_array(InstallPackageOptions::REINSTALL, $options, true))
{
if($this->getPackageLockManager()?->getPackageLock()?->packageExists($package->assembly->package, $package->assembly->version))
if($this->getPackageLockManager()?->getPackageLock()?->packageExists($package->assembly->getPackage(), $package->assembly->getVersion()))
{
$this->getPackageLockManager()?->getPackageLock()?->removePackageVersion(
$package->assembly->package, $package->assembly->version
$package->assembly->getPackage(), $package->assembly->getVersion()
);
}
}
else
{
throw new PackageException('The package ' . $package->assembly->package . '=' . $package->assembly->version . ' is already installed');
throw new PackageException('The package ' . $package->assembly->getPackage() . '=' . $package->assembly->getVersion() . ' is already installed');
}
}
@ -195,7 +197,7 @@
}
}
Console::out('Installing ' . $package->assembly->package);
Console::out('Installing ' . $package->assembly->getPackage());
// Four For Directory Creation, preInstall, postInstall & initData methods
$steps = (4 + count($package->components) + count ($package->resources) + count ($package->execution_units));
@ -345,8 +347,8 @@
/** @var Package\ExecutionUnit $executionUnit */
foreach($package->execution_units as $executionUnit)
{
Console::outDebug(sprintf('processing execution unit %s', $executionUnit->execution_policy->name));
$execution_pointer_manager->addUnit($package->assembly->package, $package->assembly->version, $executionUnit);
Console::outDebug(sprintf('processing execution unit %s', $executionUnit->execution_policy->getName()));
$execution_pointer_manager->addUnit($package->assembly->getPackage(), $package->assembly->getVersion(), $executionUnit);
++$current_steps;
Console::inlineProgressBar($current_steps, $steps);
}
@ -366,10 +368,10 @@
throw new OperationException('Cannot create symlink, no main execution policy is defined');
}
Console::outDebug(sprintf('creating symlink to %s', $package->assembly->package));
Console::outDebug(sprintf('creating symlink to %s', $package->assembly->getPackage()));
$SymlinkManager = new SymlinkManager();
$SymlinkManager->add($package->assembly->package, $package->main_execution_policy);
$SymlinkManager->add($package->assembly->getPackage(), $package->main_execution_policy);
}
// Execute the post-installation stage after the installation is complete
@ -416,15 +418,15 @@
if($package->header->UpdateSource !== null && $package->header->UpdateSource->repository !== null)
{
$sources_manager = new RemoteSourcesManager();
if($sources_manager->getRemoteSource($package->header->UpdateSource->repository->name) === null)
if($sources_manager->getRemoteSource($package->header->UpdateSource->repository->getName()) === null)
{
Console::outVerbose('Adding remote source ' . $package->header->UpdateSource->repository->name);
Console::outVerbose('Adding remote source ' . $package->header->UpdateSource->repository->getName());
$defined_remote_source = new DefinedRemoteSource();
$defined_remote_source->name = $package->header->UpdateSource->repository->name;
$defined_remote_source->host = $package->header->UpdateSource->repository->host;
$defined_remote_source->type = $package->header->UpdateSource->repository->type;
$defined_remote_source->ssl = $package->header->UpdateSource->repository->ssl;
$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();
$sources_manager->addRemoteSource($defined_remote_source);
}
@ -433,9 +435,9 @@
$this->getPackageLockManager()?->getPackageLock()?->addPackage($package, $installation_paths->getInstallationPath());
$this->getPackageLockManager()?->save();
RuntimeCache::set(sprintf('installed.%s=%s', $package->assembly->package, $package->assembly->version), true);
RuntimeCache::set(sprintf('installed.%s=%s', $package->assembly->getPackage(), $package->assembly->getVersion()), true);
return $package->assembly->package;
return $package->assembly->getPackage();
}
/**
@ -639,6 +641,7 @@
* @throws OperationException
* @throws PackageException
* @throws PathNotFoundException
* @throws ConfigurationException
*/
private function processDependency(Dependency $dependency, Package $package, string $package_path, ?Entry $entry=null, array $options=[]): void
{
@ -671,7 +674,7 @@
if ($dependency->getSourceType() !== null && !$dependency_met)
{
Console::outVerbose(sprintf('Installing dependency %s=%s for %s=%s', $dependency->getName(), $dependency->getVersion(), $package->assembly->package, $package->assembly->version));
Console::outVerbose(sprintf('Installing dependency %s=%s for %s=%s', $dependency->getName(), $dependency->getVersion(), $package->assembly->getPackage(), $package->assembly->getVersion()));
switch ($dependency->getSourceType())
{
case DependencySourceType::LOCAL:
@ -925,9 +928,9 @@
$execution_pointer_manager = new ExecutionPointerManager();
foreach($version_entry->ExecutionUnits as $executionUnit)
{
if(!$execution_pointer_manager->removeUnit($package, $version, $executionUnit->execution_policy->name))
if(!$execution_pointer_manager->removeUnit($package, $version, $executionUnit->execution_policy->getName()))
{
Console::outDebug(sprintf('warning: removing execution unit %s failed', $executionUnit->execution_policy->name));
Console::outDebug(sprintf('warning: removing execution unit %s failed', $executionUnit->execution_policy->getName()));
}
}
}
@ -986,7 +989,7 @@
*/
private static function initData(Package $package, InstallationPaths $paths): void
{
Console::outVerbose(sprintf('Initializing data for %s', $package->assembly->name));
Console::outVerbose(sprintf('Initializing data for %s', $package->assembly->getName()));
// Create data files
$dependencies = [];

View file

@ -128,38 +128,38 @@
$this->project_configuration->project->compiler = $compiler;
// Set the assembly information
$this->project_configuration->assembly->name = $name;
$this->project_configuration->assembly->package = $package;
$this->project_configuration->assembly->version = '1.0.0';
$this->project_configuration->assembly->uuid = Uuid::v1()->toRfc4122();
$this->project_configuration->assembly->setName($name);
$this->project_configuration->assembly->setPackage($package);
$this->project_configuration->assembly->setVersion('1.0.0');
$this->project_configuration->assembly->setUuid(Uuid::v1()->toRfc4122());
// Set the build information
$this->project_configuration->build->source_path = $src;
$this->project_configuration->build->setSourcePath($src);
if($this->project_configuration->build->source_path === null)
if($this->project_configuration->build->getSourcePath() === null)
{
$this->project_configuration->build->source_path = $this->project_path;
$this->project_configuration->build->setSourcePath($this->project_path);
}
$this->project_configuration->build->default_configuration = 'debug';
$this->project_configuration->build->setDefaultConfiguration('debug');
// Assembly constants if the program wishes to check for this
$this->project_configuration->build->define_constants['ASSEMBLY_NAME'] = '%ASSEMBLY.NAME%';
$this->project_configuration->build->define_constants['ASSEMBLY_PACKAGE'] = '%ASSEMBLY.PACKAGE%';
$this->project_configuration->build->define_constants['ASSEMBLY_VERSION'] = '%ASSEMBLY.VERSION%';
$this->project_configuration->build->define_constants['ASSEMBLY_UID'] = '%ASSEMBLY.UID%';
$this->project_configuration->build->addDefineConstant('ASSEMBLY_PACKAGE', '%ASSEMBLY.PACKAGE%');
$this->project_configuration->build->addDefineConstant('ASSEMBLY_VERSION', '%ASSEMBLY.VERSION%');
$this->project_configuration->build->addDefineConstant('ASSEMBLY_UID', '%ASSEMBLY.UID%');
// Generate configurations
$DebugConfiguration = new ProjectConfiguration\Build\BuildConfiguration();
$DebugConfiguration->name = 'debug';
$DebugConfiguration->output_path = 'build/debug';
$DebugConfiguration->define_constants["DEBUG"] = '1'; // Debugging constant if the program wishes to check for this
$this->project_configuration->build->build_configurations[] = $DebugConfiguration;
$ReleaseConfiguration = new ProjectConfiguration\Build\BuildConfiguration();
$ReleaseConfiguration->name = 'release';
$ReleaseConfiguration->output_path = 'build/release';
$ReleaseConfiguration->define_constants["DEBUG"] = '0'; // Debugging constant if the program wishes to check for this
$this->project_configuration->build->build_configurations[] = $ReleaseConfiguration;
$debug_configuration = new ProjectConfiguration\Build\BuildConfiguration();
$debug_configuration->setName('debug');
$debug_configuration->setOutputPath('build/debug');
$debug_configuration->setDefinedConstant('DEBUG', '1'); // Debugging constant if the program wishes to check for this
$this->project_configuration->build->addBuildConfiguration($debug_configuration);
$release_configuration = new ProjectConfiguration\Build\BuildConfiguration();
$release_configuration->setName('release');
$release_configuration->setOutputPath('build/release');
$release_configuration->setDefinedConstant('DEBUG', '0'); // Debugging constant if the program wishes to check for this
$this->project_configuration->build->addBuildConfiguration($release_configuration);
// Finally, create project.json
$this->project_configuration->toFile($this->project_path . DIRECTORY_SEPARATOR . 'project.json');
@ -184,8 +184,8 @@
{
if (
$option === InitializeProjectOptions::CREATE_SOURCE_DIRECTORY &&
!file_exists($this->project_configuration->build->source_path) &&
!mkdir($concurrentDirectory = $this->project_configuration->build->source_path) &&
!file_exists($this->project_configuration->build->getSourcePath()) &&
!mkdir($concurrentDirectory = $this->project_configuration->build->getSourcePath()) &&
!is_dir($concurrentDirectory)
)
{
@ -226,6 +226,7 @@
* Saves the project configuration
*
* @return void
* @throws IOException
*/
public function save(): void
{

View file

@ -85,6 +85,7 @@
*
* @return void
* @throws AuthenticationException
* @throws IOException
*/
public function load(): void
{
@ -279,6 +280,7 @@
* @param string $package
* @return void
* @throws AuthenticationException
* @throws IOException
*/
private function setAsRegistered(string $package): void
{
@ -299,6 +301,7 @@
*
* @return void
* @throws AuthenticationException
* @throws IOException
*/
public function sync(): void
{

View file

@ -86,18 +86,24 @@
*/
public static function fromArray(array $data): CliHelpSection
{
$Object = new CliHelpSection();
$object = new CliHelpSection();
if(isset($data['parameters']))
$Object->Parameters = $data['parameters'];
{
$object->Parameters = $data['parameters'];
}
if(isset($data['description']))
$Object->Description = $data['description'];
{
$object->Description = $data['description'];
}
if(isset($data['default']))
$Object->Default = $data['default'];
{
$object->Default = $data['default'];
}
return $Object;
return $object;
}
/**
@ -125,16 +131,13 @@
$out[] .= $result;
}
elseif($basic)
{
$out[] .= implode(' ', $this->Parameters);
}
else
{
if($basic)
{
$out[] .= implode(' ', $this->Parameters);
}
else
{
$out[] .= Console::formatColor(implode(' ', $this->Parameters), ConsoleColors::GREEN);
}
$out[] .= Console::formatColor(implode(' ', $this->Parameters), ConsoleColors::GREEN);
}
}

View file

@ -40,7 +40,7 @@
*
* @var string
*/
public $Name;
public $name;
/**
* A short description of the package. Usually
@ -48,7 +48,7 @@
*
* @var string
*/
public $Description;
public $description;
/**
* The version of the package, in most cases this is not
@ -60,14 +60,14 @@
*
* @var string|null
*/
public $Version;
public $version;
/**
* The type of package, it defaults to library
*
* @var string
*/
public $Type;
public $type;
/**
* An array of keywords that the package is related to.
@ -82,21 +82,21 @@
*
* @var string[]
*/
public $Keywords;
public $keywords;
/**
* A URL to the website of the project
*
* @var string|null
*/
public $Homepage;
public $homepage;
/**
* A relative path to the readme document
*
* @var string|null
*/
public $Readme;
public $readme;
/**
* Release date of the version
@ -105,7 +105,7 @@
*
* @var string|null
*/
public $Time;
public $time;
/**
* The license of the package. This can either be a string or
@ -113,17 +113,17 @@
*
* @var string|string[]|null
*/
public $License;
public $license;
/**
* @var Author[]|null
*/
public $Authors;
public $authors;
/**
* @var Support|null
*/
public $Support;
public $support;
/**
* Map of packages required by this package. The package
@ -131,7 +131,7 @@
*
* @var PackageLink[]|null
*/
public $Require;
public $require;
/**
* Map of packages required for developing this package, or running tests,
@ -141,7 +141,7 @@
*
* @var PackageLink[]|null
*/
public $RequireDev;
public $require_dev;
/**
* Map of packages that conflict with this version of this package. They will
@ -149,7 +149,7 @@
*
* @var PackageLink[]|null
*/
public $Conflict;
public $conflict;
/**
* Map of packages that are replaced by this package. This allows you to fork a
@ -159,7 +159,7 @@
*
* @var PackageLink[]|null
*/
public $Replace;
public $replace;
/**
* Map of packages that are provided by this package. This is mostly useful for
@ -169,7 +169,7 @@
*
* @var PackageLink[]|null
*/
public $Provide;
public $provide;
/**
* Suggested packages that can enhance or work well with this package. These are
@ -179,35 +179,35 @@
*
* @var Suggestion[]|null
*/
public $Suggest;
public $suggest;
/**
* Autoload mapping for a PHP autoloader.
*
* @var Autoloader|null
*/
public $Autoload;
public $autoload;
/**
* This section allows defining autoload rules for development purposes.
*
* @var Autoloader|null
*/
public $AutoloadDev;
public $autoload_dev;
/**
* A list of paths which should get appended to PHP's include_path.
*
* @var string[]|null
*/
public $IncludePath;
public $include_path;
/**
* Defines the installation target.
*
* @var string|null
*/
public $TargetDirectory;
public $target_directory;
/**
* This defines the default behavior for filtering packages by
@ -222,31 +222,21 @@
*
* @var ComposerPackageTypes|null
*/
public $MinimumStability;
/**
* When this is enabled, Composer will prefer more stable packages over
* unstable ones when finding compatible stable packages is possible.
* If you require a dev version or only alphas are available for a package,
* those will still be selected granted that the minimum-stability allows for it.
*
* @var bool
*/
public $PreferStable;
public $minimum_stability;
/**
* Custom package repositories to use.
*
* @var array|null
*/
public $Repositories;
public $repositories;
/**
* A set of configuration options. It is only used for projects.
*
* @var array|null
*/
public $Configuration;
public $configuration;
/**
* Composer allows you to hook into various parts of the installation
@ -254,14 +244,14 @@
*
* @var array|null
*/
public $Scripts;
public $scripts;
/**
* Arbitrary extra data for consumption by scripts.
*
* @var array|null
*/
public $Extra;
public $extra;
/**
* A set of files that should be treated as binaries and made available into the bin-dir (from config).
@ -275,14 +265,14 @@
*
* @var array|null
*/
public $Archive;
public $archive;
/**
* Indicates whether this package has been abandoned.
*
* @var bool
*/
public $Abandoned;
public $abandoned;
/**
* A list of regex patterns of branch names that are
@ -292,14 +282,14 @@
*
* @var array|null
*/
public $NonFeatureBranches;
public $non_feature_branches;
public function __construct()
{
$this->Type = ComposerPackageTypes::LIBRARY;
$this->MinimumStability = ComposerStabilityTypes::STABLE;
$this->type = ComposerPackageTypes::LIBRARY;
$this->minimum_stability = ComposerStabilityTypes::STABLE;
$this->PreferStable = false;
$this->Abandoned = false;
$this->abandoned = false;
}
/**
@ -310,106 +300,106 @@
public function toArray(): array
{
$_authors = null;
if($this->Authors !== null && count($this->Authors) > 0)
if($this->authors !== null && count($this->authors) > 0)
{
$_authors = [];
foreach($this->Authors as $author)
foreach($this->authors as $author)
{
$_authors[] = $author->toArray();
}
}
$_require = null;
if($this->Require !== null && count($this->Require) > 0)
if($this->require !== null && count($this->require) > 0)
{
$_require = [];
foreach($this->Require as $require)
foreach($this->require as $require)
{
$_require[$require->PackageName] = $require->Version;
$_require[$require->package_name] = $require->version;
}
}
$_require_dev = null;
if($this->RequireDev !== null && count($this->RequireDev) > 0)
if($this->require_dev !== null && count($this->require_dev) > 0)
{
$_require_dev = [];
foreach($this->RequireDev as $require)
foreach($this->require_dev as $require)
{
$_require_dev[$require->PackageName] = $require->Version;
$_require_dev[$require->package_name] = $require->version;
}
}
$_conflict = null;
if($this->Conflict !== null && count($this->Conflict) > 0)
if($this->conflict !== null && count($this->conflict) > 0)
{
$_conflict = [];
foreach($this->Conflict as $require)
foreach($this->conflict as $require)
{
$_conflict[$require->PackageName] = $require->Version;
$_conflict[$require->package_name] = $require->version;
}
}
$_replace = null;
if($this->Replace !== null && count($this->Replace) > 0)
if($this->replace !== null && count($this->replace) > 0)
{
$_replace = [];
foreach($this->Replace as $require)
foreach($this->replace as $require)
{
$_replace[$require->PackageName] = $require->Version;
$_replace[$require->package_name] = $require->version;
}
}
$_provide = null;
if($this->Provide !== null && count($this->Provide) > 0)
if($this->provide !== null && count($this->provide) > 0)
{
$_provide = [];
foreach($this->Provide as $require)
foreach($this->provide as $require)
{
$_provide[$require->PackageName] = $require->Version;
$_provide[$require->package_name] = $require->version;
}
}
$_suggest = null;
if($this->Suggest !== null && count($this->Suggest) > 0)
if($this->suggest !== null && count($this->suggest) > 0)
{
$_suggest = [];
foreach($this->Suggest as $suggestion)
foreach($this->suggest as $suggestion)
{
$_suggest[$suggestion->PackageName] = $suggestion->Comment;
$_suggest[$suggestion->package_name] = $suggestion->comment;
}
}
return [
'name' => $this->Name,
'description' => $this->Description,
'version' => $this->Version,
'type' => $this->Type,
'keywords' => $this->Keywords,
'homepage' => $this->Homepage,
'readme' => $this->Readme,
'time' => $this->Time,
'license' => $this->License,
'name' => $this->name,
'description' => $this->description,
'version' => $this->version,
'type' => $this->type,
'keywords' => $this->keywords,
'homepage' => $this->homepage,
'readme' => $this->readme,
'time' => $this->time,
'license' => $this->license,
'authors' => $_authors,
'support' => $this->Support?->toArray(),
'support' => $this->support?->toArray(),
'require' => $_require,
'require_dev' => $_require_dev,
'conflict' => $_conflict,
'replace' => $_replace,
'provide' => $_provide,
'suggest' => $_suggest,
'autoload' => $this->Autoload?->toArray(),
'autoload-dev' => $this->AutoloadDev?->toArray(),
'include-path' => $this->IncludePath,
'target-dir' => $this->TargetDirectory,
'minimum-stability' => $this->MinimumStability,
'repositories' => $this->Repositories,
'config' => $this->Configuration,
'scripts' => $this->Scripts,
'extra' => $this->Extra,
'autoload' => $this->autoload?->toArray(),
'autoload-dev' => $this->autoload_dev?->toArray(),
'include-path' => $this->include_path,
'target-dir' => $this->target_directory,
'minimum-stability' => $this->minimum_stability,
'repositories' => $this->repositories,
'config' => $this->configuration,
'scripts' => $this->scripts,
'extra' => $this->extra,
'bin' => $this->Bin,
'archive' => $this->Archive,
'abandoned' => $this->Abandoned,
'non-feature-branches' => $this->NonFeatureBranches
'archive' => $this->archive,
'abandoned' => $this->abandoned,
'non-feature-branches' => $this->non_feature_branches
];
}
@ -418,136 +408,182 @@
$object = new self();
if(isset($data['name']))
$object->Name = $data['name'];
{
$object->name = $data['name'];
}
if(isset($data['description']))
$object->Description = $data['description'];
{
$object->description = $data['description'];
}
if(isset($data['version']))
$object->Version = $data['version'];
{
$object->version = $data['version'];
}
if(isset($data['type']))
$object->Type = $data['type'];
{
$object->type = $data['type'];
}
if(isset($data['keywords']))
$object->Keywords = $data['keywords'];
{
$object->keywords = $data['keywords'];
}
if(isset($data['homepage']))
$object->Homepage = $data['homepage'];
{
$object->homepage = $data['homepage'];
}
if(isset($data['readme']))
$object->Readme = $data['readme'];
{
$object->readme = $data['readme'];
}
if(isset($data['time']))
$object->Time = $data['time'];
{
$object->time = $data['time'];
}
if(isset($data['license']))
$object->License = $data['license'];
{
$object->license = $data['license'];
}
if(isset($data['authors']))
{
$object->Authors = [];
$object->authors = [];
foreach($data['authors'] as $author)
{
$object->Authors[] = Author::fromArray($author);
$object->authors[] = Author::fromArray($author);
}
}
if(isset($data['support']))
$object->Support = Support::fromArray($data['support']);
{
$object->support = Support::fromArray($data['support']);
}
if(isset($data['require']))
{
$object->Require = [];
$object->require = [];
foreach($data['require'] as $package => $version)
{
$object->Require[] = new PackageLink($package, $version);
$object->require[] = new PackageLink($package, $version);
}
}
if(isset($data['require_dev']))
{
$object->RequireDev = [];
$object->require_dev = [];
foreach($data['require_dev'] as $package => $version)
{
$object->RequireDev[] = new PackageLink($package, $version);
$object->require_dev[] = new PackageLink($package, $version);
}
}
if(isset($data['conflict']))
{
$object->Conflict = [];
$object->conflict = [];
foreach($data['conflict'] as $package => $version)
{
$object->Conflict[] = new PackageLink($package, $version);
$object->conflict[] = new PackageLink($package, $version);
}
}
if(isset($data['replace']))
{
$object->Replace = [];
$object->replace = [];
foreach($data['replace'] as $package => $version)
{
$object->Replace[] = new PackageLink($package, $version);
$object->replace[] = new PackageLink($package, $version);
}
}
if(isset($data['provide']))
{
$object->Provide = [];
$object->provide = [];
foreach($data['provide'] as $package => $version)
{
$object->Provide[] = new PackageLink($package, $version);
$object->provide[] = new PackageLink($package, $version);
}
}
if(isset($data['suggest']))
{
$object->Suggest = [];
$object->suggest = [];
foreach($data['suggest'] as $package => $comment)
{
$object->Suggest[] = new Suggestion($package, $comment);
$object->suggest[] = new Suggestion($package, $comment);
}
}
if(isset($data['autoload']))
$object->Autoload = Autoloader::fromArray($data['autoload']);
{
$object->autoload = Autoloader::fromArray($data['autoload']);
}
if(isset($data['autoload-dev']))
$object->AutoloadDev = Autoloader::fromArray($data['autoload-dev']);
{
$object->autoload_dev = Autoloader::fromArray($data['autoload-dev']);
}
if(isset($data['include-path']))
$object->IncludePath = $data['include-path'];
{
$object->include_path = $data['include-path'];
}
if(isset($data['target-dir']))
$object->TargetDirectory = $data['target-dir'];
{
$object->target_directory = $data['target-dir'];
}
if(isset($data['minimum-stability']))
$object->MinimumStability = $data['minimum-stability'];
{
$object->minimum_stability = $data['minimum-stability'];
}
if(isset($data['repositories']))
$object->Repositories = $data['repositories'];
{
$object->repositories = $data['repositories'];
}
if(isset($data['config']))
$object->Configuration = $data['config'];
{
$object->configuration = $data['config'];
}
if(isset($data['scripts']))
$object->Scripts = $data['scripts'];
{
$object->scripts = $data['scripts'];
}
if(isset($data['extra']))
$object->Extra = $data['extra'];
{
$object->extra = $data['extra'];
}
if(isset($data['bin']))
{
$object->Bin = $data['bin'];
}
if(isset($data['archive']))
$object->Archive = $data['archive'];
{
$object->archive = $data['archive'];
}
if(isset($data['abandoned']))
$object->Abandoned = $data['abandoned'];
{
$object->abandoned = $data['abandoned'];
}
if(isset($data['non-feature-branches']))
$object->NonFeatureBranches = $data['non-feature-branches'];
{
$object->non_feature_branches = $data['non-feature-branches'];
}
return $object;
}

View file

@ -30,32 +30,33 @@
/**
* @var NamespacePointer[]|null
*/
public $Psr4;
public $psr_4;
/**
* @var NamespacePointer[]|null
*/
public $Psr0;
public $psr_0;
/**
* @var string[]|null
*/
public $Classmap;
public $class_map;
/**
* @var string[]|null
*/
public $Files;
public $files;
/**
* @var string[]|null
*/
public $ExcludeFromClassMap;
public $exclude_from_class_map;
/**
* @param array $psr
* @param mixed $pointer
* @return array
* @noinspection PhpUnusedPrivateMethodInspection
*/
private static function psrRestructure(array $psr, NamespacePointer $pointer): array
{
@ -70,7 +71,7 @@
$psr[(string)$pointer->Namespace] = $r;
}
elseif (!in_array($pointer->Path, $psr[(string)$pointer->Namespace]))
elseif (!in_array($pointer->Path, $psr[(string)$pointer->Namespace], true))
{
$psr[(string)$pointer->Namespace][] = $pointer->Path;
}
@ -90,27 +91,27 @@
public function toArray(): array
{
$_psr4 = null;
if($this->Psr4 !== null && count($this->Psr4) > 0)
if($this->psr_4 !== null && count($this->psr_4) > 0)
{
$_psr4 = [];
foreach($this->Psr4 as $_psr)
$_psr4 = self::psrRestructure($_psr4, $_psr);
$_psr4 = array_map(static function(NamespacePointer $pointer) {
return $pointer->toArray();
}, $this->psr_4);
}
$_psr0 = null;
if($this->Psr0 !== null && count($this->Psr0) > 0)
if($this->psr_0 !== null && count($this->psr_0) > 0)
{
$_psr0 = [];
foreach($this->Psr0 as $_psr)
$_psr4 = self::psrRestructure($_psr0, $_psr);
$_psr0 = array_map(static function(NamespacePointer $pointer) {
return $pointer->toArray();
}, $this->psr_0);
}
return [
'psr-4' => $_psr4,
'psr-0' => $_psr0,
'classmap' => $this->Classmap,
'files' => $this->Files,
'exclude-from-classmap' => $this->ExcludeFromClassMap,
'classmap' => $this->class_map,
'files' => $this->files,
'exclude-from-classmap' => $this->exclude_from_class_map,
];
}
@ -124,50 +125,56 @@
if(isset($data['psr-4']))
{
$object->Psr4 = [];
$object->psr_4 = [];
foreach($data['psr-4'] as $namespace => $path)
{
if(is_array($path))
{
foreach($path as $datum)
{
$object->Psr4[] = new NamespacePointer($namespace, $datum);
$object->psr_4[] = new NamespacePointer($namespace, $datum);
}
}
else
{
$object->Psr4[] = new NamespacePointer($namespace, $path);
$object->psr_4[] = new NamespacePointer($namespace, $path);
}
}
}
if(isset($data['psr-0']))
{
$object->Psr0 = [];
$object->psr_0 = [];
foreach($data['psr-0'] as $namespace => $path)
{
if(is_array($path))
{
foreach($path as $datum)
{
$object->Psr0[] = new NamespacePointer($namespace, $datum);
$object->psr_0[] = new NamespacePointer($namespace, $datum);
}
}
else
{
$object->Psr0[] = new NamespacePointer($namespace, $path);
$object->psr_0[] = new NamespacePointer($namespace, $path);
}
}
}
if(isset($data['classmap']))
$object->Classmap = $data['classmap'];
{
$object->class_map = $data['classmap'];
}
if(isset($data['files']))
$object->Files = $data['files'];
{
$object->files = $data['files'];
}
if(isset($data['exclude-from-classmap']))
$object->ExcludeFromClassMap = $data['exclude-from-classmap'];
{
$object->exclude_from_class_map = $data['exclude-from-classmap'];
}
return $object;
}

View file

@ -1,26 +1,29 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Objects\ComposerJson;
/** @noinspection PhpMissingFieldTypeInspection */
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Objects\ComposerJson;
class PackageLink
{
@ -29,23 +32,23 @@ namespace ncc\Objects\ComposerJson;
*
* @var string|null
*/
public $PackageName;
public $package_name;
/**
* The version of the package that is required
*
* @var string|null
*/
public $Version;
public $version;
/**
* @param string|null $packageName
* @param string|null $package_name
* @param string|null $version
*/
public function __construct(?string $packageName=null, ?string $version=null)
public function __construct(?string $package_name=null, ?string $version=null)
{
$this->PackageName = $packageName;
$this->Version = $version;
$this->package_name = $package_name;
$this->version = $version;
}
/**
@ -56,13 +59,13 @@ namespace ncc\Objects\ComposerJson;
public function toArray(): array
{
return [
'package_name' => $this->PackageName,
'version' => $this->Version
'package_name' => $this->package_name,
'version' => $this->version
];
}
/**
* Constructs object from an array representation
* Constructs an object from an array representation
*
* @param array $data
* @return PackageLink
@ -72,10 +75,14 @@ namespace ncc\Objects\ComposerJson;
$object = new self();
if(isset($data['package_name']))
$object->PackageName = $data['package_name'];
{
$object->package_name = $data['package_name'];
}
if(isset($data['version']))
$object->Version = $data['version'];
{
$object->version = $data['version'];
}
return $object;
}

View file

@ -29,14 +29,14 @@ namespace ncc\Objects\ComposerJson;
*
* @var string
*/
public $PackageName;
public $package_name;
/**
* The comment for the suggestion
*
* @var string
*/
public $Comment;
public $comment;
/**
* @param string|null $packageName
@ -44,8 +44,8 @@ namespace ncc\Objects\ComposerJson;
*/
public function __construct(?string $packageName=null, ?string $comment=null)
{
$this->PackageName = $packageName;
$this->Comment = $comment;
$this->package_name = $packageName;
$this->comment = $comment;
}
/**
@ -56,8 +56,8 @@ namespace ncc\Objects\ComposerJson;
public function toArray(): array
{
return [
'package_name' => $this->PackageName,
'comment' => $this->Comment,
'package_name' => $this->package_name,
'comment' => $this->comment,
];
}
@ -72,10 +72,10 @@ namespace ncc\Objects\ComposerJson;
$object = new self();
if(isset($data['package_name']))
$object->PackageName = $data['package_name'];
$object->package_name = $data['package_name'];
if(isset($data['comment']))
$object->Comment = $data['comment'];
$object->comment = $data['comment'];
return $object;
}

View file

@ -1,26 +1,29 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Objects\ComposerJson;
/** @noinspection PhpMissingFieldTypeInspection */
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
namespace ncc\Objects\ComposerJson;
class Support
{
@ -29,63 +32,63 @@ namespace ncc\Objects\ComposerJson;
*
* @var string|null
*/
public $Email;
public $email;
/**
* URL to the issue tracker
*
* @var string|null
*/
public $Issues;
public $issues;
/**
* URL to the forum
*
* @var string|null
*/
public $Forum;
public $forum;
/**
* URL to the Wiki
*
* @var string|null
*/
public $Wiki;
public $wiki;
/**
* The IRC channel for support, as irc://server/channel
*
* @var string|null
*/
public $IRC;
public $irc;
/**
* URL to browse or download the sources
*
* @var string|null
*/
public $Source;
public $source;
/**
* URL to the documentation
*
* @var string|null
*/
public $Docs;
public $docs;
/**
* URL to the RSS feed
*
* @var string|null
*/
public $RSS;
public $rss;
/**
* URL to the chat channel
*
* @var string|null
*/
public $Chat;
public $chat;
/**
* Returns an array representation of the object
@ -95,15 +98,15 @@ namespace ncc\Objects\ComposerJson;
public function toArray(): array
{
return [
'email' => $this->Email,
'issues' => $this->Issues,
'forum' => $this->Forum,
'wiki' => $this->Wiki,
'irc' => $this->IRC,
'source' => $this->Source,
'docs' => $this->Docs,
'rss' => $this->RSS,
'chat' => $this->Chat
'email' => $this->email,
'issues' => $this->issues,
'forum' => $this->forum,
'wiki' => $this->wiki,
'irc' => $this->irc,
'source' => $this->source,
'docs' => $this->docs,
'rss' => $this->rss,
'chat' => $this->chat
];
}
@ -118,31 +121,49 @@ namespace ncc\Objects\ComposerJson;
$object = new self();
if(isset($data['email']))
$object->Email = $data['email'];
{
$object->email = $data['email'];
}
if(isset($data['issues']))
$object->Issues = $data['issues'];
{
$object->issues = $data['issues'];
}
if(isset($data['forum']))
$object->Forum = $data['forum'];
{
$object->forum = $data['forum'];
}
if(isset($data['wiki']))
$object->Wiki = $data['wiki'];
{
$object->wiki = $data['wiki'];
}
if(isset($data['irc']))
$object->IRC = $data['irc'];
{
$object->irc = $data['irc'];
}
if(isset($data['source']))
$object->Source = $data['source'];
{
$object->source = $data['source'];
}
if(isset($data['docs']))
$object->Docs = $data['docs'];
{
$object->docs = $data['docs'];
}
if(isset($data['rss']))
$object->RSS = $data['rss'];
{
$object->rss = $data['rss'];
}
if(isset($data['chat']))
$object->Chat = $data['chat'];
{
$object->chat = $data['chat'];
}
return $object;
}

View file

@ -96,7 +96,7 @@
{
foreach($this->Packages as $package)
{
if($package->Name == $name)
if($package->name === $name)
{
return $package;
}
@ -113,10 +113,12 @@
public function toArray(): array
{
$_packages = [];
if($this->Packages != null)
if($this->Packages !== null)
{
foreach($this->Packages as $package)
{
$_packages[] = $package->toArray();
}
}
return [
'_readme' => $this->Readme,
@ -140,26 +142,30 @@
* @param array $data
* @return static
*/
public static function fromArray(array $data): self
public static function fromArray(array $data): ComposerLock
{
$obj = new self();
$obj->Readme = $data['_readme'];
$obj->ContentHash = $data['content-hash'];
$obj->Packages = [];
if($data['packages'] != null)
$object = new self();
$object->Readme = $data['_readme'];
$object->ContentHash = $data['content-hash'];
$object->Packages = [];
if($data['packages'] !== null)
{
foreach($data['packages'] as $package)
$obj->Packages[] = ComposerJson::fromArray($package);
{
$object->Packages[] = ComposerJson::fromArray($package);
}
}
$obj->PackagesDev = $data['packages-dev'];
$obj->Aliases = $data['aliases'];
$obj->MinimumStability = $data['minimum-stability'];
$obj->StabilityFlags = $data['stability-flags'];
$obj->PreferStable = $data['prefer-stable'];
$obj->PreferLowest = $data['prefer-lowest'];
$obj->Platform = $data['platform'];
$obj->PlatformDev = $data['platform-dev'];
$obj->PluginApiVersion = $data['plugin-api-version'];
return $obj;
$object->PackagesDev = $data['packages-dev'];
$object->Aliases = $data['aliases'];
$object->MinimumStability = $data['minimum-stability'];
$object->StabilityFlags = $data['stability-flags'];
$object->PreferStable = $data['prefer-stable'];
$object->PreferLowest = $data['prefer-lowest'];
$object->Platform = $data['platform'];
$object->PlatformDev = $data['platform-dev'];
$object->PluginApiVersion = $data['plugin-api-version'];
return $object;
}
}

View file

@ -82,9 +82,9 @@
if($overwrite)
{
$this->deleteUnit($unit->execution_policy->name);
$this->deleteUnit($unit->execution_policy->getName());
}
elseif($this->getUnit($unit->execution_policy->name) !== null)
elseif($this->getUnit($unit->execution_policy->getName()) !== null)
{
return false;
}
@ -111,7 +111,7 @@
$new_pointers = [];
foreach($this->pointers as $pointer)
{
if($pointer->execution_policy->name !== $name)
if($pointer->execution_policy->getName() !== $name)
{
$new_pointers[] = $pointer;
}
@ -132,7 +132,7 @@
/** @var ExecutionPointer $pointer */
foreach($this->pointers as $pointer)
{
if($pointer->execution_policy->name === $name)
if($pointer->execution_policy->getName() === $name)
{
return $pointer;
}

View file

@ -214,7 +214,7 @@
{
foreach($this->execution_units as $unit)
{
if($unit->execution_policy->name === $name)
if($unit->execution_policy->getName() === $name)
{
return $unit;
}

View file

@ -87,7 +87,10 @@
public function getId(): string
{
if($this->id == null)
$this->id = hash('sha1', $this->execution_policy->name);
{
$this->id = hash('sha1', $this->execution_policy->getName());
}
return $this->id;
}

View file

@ -25,6 +25,7 @@
namespace ncc\Objects;
use ncc\Enums\Versions;
use ncc\Exceptions\ConfigurationException;
use ncc\Exceptions\IOException;
use ncc\Objects\PackageLock\PackageEntry;
use ncc\Utilities\Console;
@ -77,27 +78,28 @@
* @param Package $package
* @param string $install_path
* @return void
* @throws ConfigurationException
*/
public function addPackage(Package $package, string $install_path): void
{
Console::outVerbose("Adding package {$package->assembly->package} to package lock file");
Console::outVerbose("Adding package {$package->assembly->getPackage()} to package lock file");
if(!isset($this->Packages[$package->assembly->package]))
if(!isset($this->Packages[$package->assembly->getPackage()]))
{
$package_entry = new PackageEntry();
$package_entry->addVersion($package, $install_path, true);
$package_entry->Name = $package->assembly->package;
$package_entry->Name = $package->assembly->getPackage();
$package_entry->UpdateSource = $package->header->UpdateSource;
$package_entry->getDataPath();
$this->Packages[$package->assembly->package] = $package_entry;
$this->Packages[$package->assembly->getPackage()] = $package_entry;
$this->update();
return;
}
$this->Packages[$package->assembly->package]->UpdateSource = $package->header->UpdateSource;
$this->Packages[$package->assembly->package]->addVersion($package, $install_path, true);
$this->Packages[$package->assembly->package]->getDataPath();
$this->Packages[$package->assembly->getPackage()]->UpdateSource = $package->header->UpdateSource;
$this->Packages[$package->assembly->getPackage()]->addVersion($package, $install_path, true);
$this->Packages[$package->assembly->getPackage()]->getDataPath();
$this->update();
}

View file

@ -153,14 +153,14 @@
{
try
{
if ($this->getVersion($package->assembly->version) !== null)
if ($this->getVersion($package->assembly->getVersion()) !== null)
{
if(!$overwrite)
{
return false;
}
$this->removeVersion($package->assembly->version);
$this->removeVersion($package->assembly->getVersion());
}
}
catch (IOException $e)
@ -169,7 +169,7 @@
}
$version = new VersionEntry();
$version->Version = $package->assembly->version;
$version->Version = $package->assembly->getVersion();
$version->Compiler = $package->header->CompilerExtension;
$version->ExecutionUnits = $package->execution_units;
$version->MainExecutionPolicy = $package->main_execution_policy;

View file

@ -131,13 +131,13 @@
return false;
}
if($this->build->main !== null)
if($this->build->getMain() !== null)
{
if($this->execution_policies === null || count($this->execution_policies) === 0)
{
if($throw_exception)
{
throw new ConfigurationException(sprintf('Build configuration build.main uses an execution policy "%s" but no policies are defined', $this->build->main));
throw new ConfigurationException(sprintf('Build configuration build.main uses an execution policy "%s" but no policies are defined', $this->build->getMain()));
}
return false;
@ -147,7 +147,7 @@
$found = false;
foreach($this->execution_policies as $policy)
{
if($policy->name === $this->build->main)
if($policy->getName() === $this->build->getMain())
{
$found = true;
break;
@ -158,12 +158,12 @@
{
if($throw_exception)
{
throw new ConfigurationException(sprintf('Build configuration build.main points to a undefined execution policy "%s"', $this->build->main));
throw new ConfigurationException(sprintf('Build configuration build.main points to a undefined execution policy "%s"', $this->build->getMain()));
}
return false;
}
if($this->build->main === BuildConfigurationValues::ALL)
if($this->build->getMain() === BuildConfigurationValues::ALL)
{
if($throw_exception)
{
@ -185,7 +185,7 @@
{
foreach($this->execution_policies as $executionPolicy)
{
if($executionPolicy->name === $name)
if($executionPolicy->getName() === $name)
{
return $executionPolicy;
}
@ -214,7 +214,7 @@
/** @var ExecutionPolicy $execution_policy */
foreach($this->execution_policies as $execution_policy)
{
$defined_polices[] = $execution_policy->name;
$defined_polices[] = $execution_policy->getName();
//$execution_policy->validate();
}
@ -245,9 +245,9 @@
}
}
if($this->build->pre_build !== null && count($this->build->post_build) > 0)
if(count($this->build->getPostBuild()) > 0)
{
foreach($this->build->post_build as $unit)
foreach($this->build->getPostBuild() as $unit)
{
if(!in_array($unit, $defined_polices, true))
{
@ -261,9 +261,9 @@
}
}
if($this->build->post_build !== null && count($this->build->post_build) > 0)
if(count($this->build->getPreBuild()) > 0)
{
foreach($this->build->post_build as $unit)
foreach($this->build->getPreBuild() as $unit)
{
if(!in_array($unit, $defined_polices, true))
{
@ -282,7 +282,7 @@
{
case BuildConfigurationValues::ALL:
/** @var BuildConfiguration $configuration */
foreach($this->build->build_configurations as $configuration)
foreach($this->build->getBuildConfigurations() as $configuration)
{
foreach($this->processBuildPolicies($configuration, $defined_polices) as $policy)
{
@ -309,47 +309,44 @@
foreach($required_policies as $policy)
{
$execution_policy = $this->getExecutionPolicy($policy);
if($execution_policy?->exit_handlers !== null)
if($execution_policy?->getExitHandlers() !== null)
{
if(
$execution_policy?->exit_handlers->success !== null &&
$execution_policy?->exit_handlers->success->run !== null
)
if($execution_policy?->getExitHandlers()->getSuccess()?->getRun() !== null)
{
if(!in_array($execution_policy?->exit_handlers->success->run, $defined_polices, true))
if(!in_array($execution_policy?->getExitHandlers()->getSuccess()?->getRun(), $defined_polices, true))
{
throw new ConfigurationException('The execution policy \'' . $execution_policy?->name . '\' Success exit handler points to a undefined execution policy \'' . $execution_policy?->exit_handlers->success->run . '\'');
throw new ConfigurationException('The execution policy \'' . $execution_policy?->getName() . '\' Success exit handler points to a undefined execution policy \'' . $execution_policy?->getExitHandlers()->getSuccess()?->getRun() . '\'');
}
if(!in_array($execution_policy?->exit_handlers->success->run, $required_policies, true))
if(!in_array($execution_policy?->getExitHandlers()->getSuccess()?->getRun(), $required_policies, true))
{
$required_policies[] = $execution_policy?->exit_handlers->success->run;
$required_policies[] = $execution_policy?->getExitHandlers()->getSuccess()?->getRun();
}
}
if($execution_policy?->exit_handlers->warning !== null && $execution_policy?->exit_handlers->warning->run !== null)
if($execution_policy?->getExitHandlers()->getWarning()?->getRun() !== null)
{
if(!in_array($execution_policy?->exit_handlers->warning->run, $defined_polices, true))
if(!in_array($execution_policy?->getExitHandlers()->getWarning()?->getRun(), $defined_polices, true))
{
throw new ConfigurationException('The execution policy \'' . $execution_policy?->name . '\' Warning exit handler points to a undefined execution policy \'' . $execution_policy?->exit_handlers->warning->run . '\'');
throw new ConfigurationException('The execution policy \'' . $execution_policy?->getName() . '\' Warning exit handler points to a undefined execution policy \'' . $execution_policy?->getExitHandlers()->getWarning()?->getRun() . '\'');
}
if(!in_array($execution_policy?->exit_handlers->warning->run, $required_policies, true))
if(!in_array($execution_policy?->getExitHandlers()->getWarning()?->getRun(), $required_policies, true))
{
$required_policies[] = $execution_policy?->exit_handlers->warning->run;
$required_policies[] = $execution_policy?->getExitHandlers()->getWarning()?->getRun();
}
}
if($execution_policy?->exit_handlers->error !== null && $execution_policy?->exit_handlers->error->run !== null)
if($execution_policy?->getExitHandlers()->getError()?->getRun() !== null)
{
if(!in_array($execution_policy?->exit_handlers->error->run, $defined_polices, true))
if(!in_array($execution_policy?->getExitHandlers()->getError()?->getRun(), $defined_polices, true))
{
throw new ConfigurationException('The execution policy \'' . $execution_policy?->name . '\' Error exit handler points to a undefined execution policy \'' . $execution_policy?->exit_handlers->error->run . '\'');
throw new ConfigurationException('The execution policy \'' . $execution_policy?->getName() . '\' Error exit handler points to a undefined execution policy \'' . $execution_policy?->getExitHandlers()->getError()?->getRun() . '\'');
}
if(!in_array($execution_policy?->exit_handlers->error->run, $required_policies, true))
if(!in_array($execution_policy?->getExitHandlers()->getError()?->getRun(), $required_policies, true))
{
$required_policies[] = $execution_policy?->exit_handlers->error->run;
$required_policies[] = $execution_policy?->getExitHandlers()->getError()?->getRun();
}
}
}
@ -401,26 +398,26 @@
{
$required_policies = [];
if ($configuration->pre_build !== null && count($configuration->pre_build) > 0)
if (count($configuration->getPreBuild()) > 0)
{
foreach ($configuration->pre_build as $unit)
foreach ($configuration->getPreBuild() as $unit)
{
if (!in_array($unit, $defined_polices, true))
{
throw new ConfigurationException(sprintf("The property 'pre_build' in the build configuration '%s' calls for an undefined execution policy '%s'", $configuration->name, $unit));
throw new ConfigurationException(sprintf("The property 'pre_build' in the build configuration '%s' calls for an undefined execution policy '%s'", $configuration->getName(), $unit));
}
$required_policies[] = $unit;
}
}
if ($configuration->post_build !== null && count($configuration->post_build) > 0)
if (count($configuration->getPostBuild()) > 0)
{
foreach ($configuration->post_build as $unit)
foreach ($configuration->getPostBuild() as $unit)
{
if (!in_array($unit, $defined_polices, true))
{
throw new ConfigurationException(sprintf("The property 'post_build' in the build configuration '%s' calls for an undefined execution policy '%s'", $configuration->name, $unit));
throw new ConfigurationException(sprintf("The property 'post_build' in the build configuration '%s' calls for an undefined execution policy '%s'", $configuration->getName(), $unit));
}
$required_policies[] = $unit;
@ -441,7 +438,7 @@
$execution_policies = [];
foreach($this->execution_policies as $executionPolicy)
{
$execution_policies[$executionPolicy->name] = $executionPolicy->toArray($bytecode);
$execution_policies[$executionPolicy->getName()] = $executionPolicy->toArray($bytecode);
}
}

View file

@ -41,61 +41,205 @@
*
* @var string
*/
public $name;
private $name;
/**
* The package name used to identify the package
*
* @var string
*/
public $package;
private $package;
/**
* The software description
*
* @var string|null
*/
public $description;
private $description;
/**
* @var string|null
*/
public $company;
private $company;
/**
* The product name
*
* @var string|null
*/
public $product;
private $product;
/**
* The copyright header for the product
*
* @var string|null
*/
public $copyright;
private $copyright;
/**
* Product trademark
*
* @var string|null
*/
public $trademark;
private $trademark;
/**
* Software version
*
* @var string
*/
public $version;
private $version;
/**
* Universally Unique Identifier
*
* @var string
*/
public $uuid;
private $uuid;
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
/**
* @return string
*/
public function getPackage(): string
{
return $this->package;
}
/**
* @param string $package
*/
public function setPackage(string $package): void
{
$this->package = $package;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @param string|null $description
*/
public function setDescription(?string $description): void
{
$this->description = $description;
}
/**
* @return string|null
*/
public function getCompany(): ?string
{
return $this->company;
}
/**
* @param string|null $company
*/
public function setCompany(?string $company): void
{
$this->company = $company;
}
/**
* @return string|null
*/
public function getProduct(): ?string
{
return $this->product;
}
/**
* @param string|null $product
*/
public function setProduct(?string $product): void
{
$this->product = $product;
}
/**
* @return string|null
*/
public function getCopyright(): ?string
{
return $this->copyright;
}
/**
* @param string|null $copyright
*/
public function setCopyright(?string $copyright): void
{
$this->copyright = $copyright;
}
/**
* @return string|null
*/
public function getTrademark(): ?string
{
return $this->trademark;
}
/**
* @param string|null $trademark
*/
public function setTrademark(?string $trademark): void
{
$this->trademark = $trademark;
}
/**
* @return string
*/
public function getVersion(): string
{
return $this->version;
}
/**
* @param string $version
*/
public function setVersion(string $version): void
{
$this->version = $version;
}
/**
* @return string
*/
public function getUuid(): string
{
return $this->uuid;
}
/**
* @param string $uuid
*/
public function setUuid(string $uuid): void
{
$this->uuid = $uuid;
}
/**
* Validates the object information to detect possible errors

View file

@ -42,77 +42,70 @@
*
* @var string
*/
public $source_path;
private $source_path;
/**
* The default configuration to use when building
*
* @var string
*/
public $default_configuration;
private $default_configuration;
/**
* An array of files to exclude from processing/bundling into the build output
*
* @var string[]
*/
public $exclude_files;
private $exclude_files;
/**
* Build options to pass on to the compiler
*
* @var array
*/
public $options;
/**
* The installation scope for the package (System/User/Shared)
*
* @var [type]
*/
public $scope;
private $options;
/**
* The execution policy to use as the main execution point
*
* @var string|null
*/
public $main;
private $main;
/**
* An array of constants to define by default
*
* @var string[]
*/
public $define_constants;
private $define_constants;
/**
* An array of execution policies to execute pre build
*
* @var string[]
*/
public $pre_build;
private $pre_build;
/**
* An array of execution policies to execute post build
*
* @var string[]
*/
public $post_build;
private $post_build;
/**
* An array of dependencies that are required by default
*
* @var Dependency[]
*/
public $dependencies;
private $dependencies;
/**
* An array of build configurations
*
* @var BuildConfiguration[]
*/
public $build_configurations;
private $build_configurations;
/**
* Public Constructor
@ -126,6 +119,138 @@
$this->build_configurations = [];
}
/**
* @return string
*/
public function getSourcePath(): string
{
return $this->source_path;
}
/**
* @param string $source_path
*/
public function setSourcePath(string $source_path): void
{
$this->source_path = $source_path;
}
/**
* @return string
*/
public function getDefaultConfiguration(): string
{
return $this->default_configuration;
}
/**
* @param string $default_configuration
*/
public function setDefaultConfiguration(string $default_configuration): void
{
$this->default_configuration = $default_configuration;
}
/**
* @return array|string[]
*/
public function getExcludeFiles(): array
{
return $this->exclude_files;
}
/**
* @param array|string[] $exclude_files
*/
public function setExcludeFiles(array $exclude_files): void
{
$this->exclude_files = $exclude_files;
}
/**
* @param string $file
* @return void
*/
public function excludeFile(string $file): void
{
$this->exclude_files[] = $file;
}
/**
* @param string $file
* @return void
*/
public function removeExcludedFile(string $file): void
{
foreach($this->exclude_files as $key => $exclude_file)
{
if($exclude_file === $file)
{
unset($this->exclude_files[$key]);
return;
}
}
}
/**
* @return array
*/
public function getOptions(): array
{
return $this->options;
}
/**
* @param array $options
*/
public function setOptions(array $options): void
{
$this->options = $options;
}
/**
* @param string $name
* @param string $value
* @return void
*/
public function setOption(string $name, string $value): void
{
$this->options[$name] = $value;
}
/**
* @param string $name
* @return void
*/
public function removeOption(string $name): void
{
foreach($this->options as $key => $option)
{
if($option === $name)
{
unset($this->options[$key]);
return;
}
}
}
/**
* @return string|null
*/
public function getMain(): ?string
{
return $this->main;
}
/**
* @param string|null $main
* @return void
*/
public function setMain(?string $main): void
{
$this->main = $main;
}
/**
* Adds a new dependency to the build if it doesn't already exist
*
@ -164,6 +289,212 @@
}
}
/**
* @return Dependency[]
*/
public function getDependencies(): array
{
return $this->dependencies;
}
/**
* @param Dependency[] $dependencies
* @return void
*/
public function setDependencies(array $dependencies): void
{
$this->dependencies = $dependencies;
}
/**
* @return array|string[]
*/
public function getDefineConstants(): array
{
return $this->define_constants;
}
/**
* @param array|string[] $define_constants
*/
public function setDefineConstants(array $define_constants): void
{
$this->define_constants = $define_constants;
}
/**
* @param string $name
* @param string $value
* @return void
*/
public function addDefineConstant(string $name, string $value): void
{
$this->define_constants[$name] = $value;
}
/**
* @param string $name
* @return void
*/
public function removeDefineConstant(string $name): void
{
foreach($this->define_constants as $key => $define_constant)
{
if($define_constant === $name)
{
unset($this->define_constants[$key]);
return;
}
}
}
/**
* @return string[]
*/
public function getPreBuild(): array
{
return $this->pre_build;
}
/**
* @param string[] $pre_build
*/
public function setPreBuild(array $pre_build): void
{
$this->pre_build = $pre_build;
}
/**
* Adds a new pre build policy to the build
*
* @param string $policy
* @return void
*/
public function addPreBuildPolicy(string $policy): void
{
$this->pre_build[] = $policy;
}
/**
* @param string $policy
* @return void
*/
public function removePreBuildPolicy(string $policy): void
{
foreach($this->pre_build as $key => $pre_build)
{
if($pre_build === $policy)
{
unset($this->pre_build[$key]);
return;
}
}
}
/**
* @return string[]
*/
public function getPostBuild(): array
{
return $this->post_build;
}
/**
* @param string[] $post_build
*/
public function setPostBuild(array $post_build): void
{
$this->post_build = $post_build;
}
/**
* @param string $policy
* @return void
*/
public function addPostBuildPolicy(string $policy): void
{
$this->post_build[] = $policy;
}
/**
* @param string $policy
* @return void
*/
public function removePostBuildPolicy(string $policy): void
{
foreach($this->post_build as $key => $post_build)
{
if($post_build === $policy)
{
unset($this->post_build[$key]);
return;
}
}
}
/**
* Returns an array of all the build configurations defined in the project configuration
*
* @return array
* @noinspection PhpUnused
*/
public function getBuildConfigurations(): array
{
$build_configurations = [];
foreach($this->build_configurations as $configuration)
{
$build_configurations[] = $configuration->getName();
}
return $build_configurations;
}
/**
* Returns the build configurations defined in the project configuration, throw an
* exception if there is no such configuration defined in the project configuration
*
* @param string $name
* @return BuildConfiguration
* @throws ConfigurationException
*/
public function getBuildConfiguration(string $name): BuildConfiguration
{
if($name === BuildConfigurationValues::DEFAULT)
{
$name = $this->default_configuration;
}
foreach($this->build_configurations as $configuration)
{
if($configuration->getName() === $name)
{
return $configuration;
}
}
throw new ConfigurationException(sprintf('The build configuration "%s" does not exist', $name));
}
/**
* @param array $build_configurations
* @return void
*/
public function setBuildConfigurations(array $build_configurations): void
{
$this->build_configurations = $build_configurations;
}
/**
* @param BuildConfiguration $configuration
* @return void
*/
public function addBuildConfiguration(BuildConfiguration $configuration): void
{
$this->build_configurations[] = $configuration;
}
/**
* Validates the build configuration object
*
@ -186,11 +517,11 @@
$build_configurations = [];
foreach($this->build_configurations as $configuration)
{
if(in_array($configuration->name, $build_configurations, true))
if(in_array($configuration->getName(), $build_configurations, true))
{
if($throw_exception)
{
throw new ConfigurationException(sprintf('Invalid build configuration name "%s"', $configuration->name));
throw new ConfigurationException(sprintf('Invalid build configuration name "%s"', $configuration->getName()));
}
return false;
@ -230,50 +561,6 @@
return true;
}
/**
* Returns an array of all the build configurations defined in the project configuration
*
* @return array
* @noinspection PhpUnused
*/
public function getBuildConfigurations(): array
{
$build_configurations = [];
foreach($this->build_configurations as $configuration)
{
$build_configurations[] = $configuration->name;
}
return $build_configurations;
}
/**
* Returns the build configurations defined in the project configuration, throw an
* exception if there is no such configuration defined in the project configuration
*
* @param string $name
* @return BuildConfiguration
* @throws ConfigurationException
*/
public function getBuildConfiguration(string $name): BuildConfiguration
{
if($name === BuildConfigurationValues::DEFAULT)
{
$name = $this->default_configuration;
}
foreach($this->build_configurations as $configuration)
{
if($configuration->name === $name)
{
return $configuration;
}
}
throw new ConfigurationException(sprintf('The build configuration "%s" does not exist', $name));
}
/**
* Returns an array representation of the object
*
@ -301,11 +588,6 @@
$results[($bytecode ? Functions::cbc('options') : 'options')] = $this->options;
}
if($this->scope !== null)
{
$results[($bytecode ? Functions::cbc('scope') : 'scope')] = $this->scope;
}
if($this->main !== null)
{
$results[($bytecode ? Functions::cbc('main') : 'main')] = $this->main;
@ -363,7 +645,6 @@
$object->default_configuration = Functions::array_bc($data, 'default_configuration');
$object->exclude_files = (Functions::array_bc($data, 'exclude_files') ?? []);
$object->options = (Functions::array_bc($data, 'options') ?? []);
$object->scope = Functions::array_bc($data, 'scope');
$object->main = Functions::array_bc($data, 'main');
$object->define_constants = (Functions::array_bc($data, 'define_constants') ?? []);
$object->pre_build = (Functions::array_bc($data, 'pre_build') ?? []);

View file

@ -41,49 +41,49 @@
*
* @var string
*/
public $name;
private $name;
/**
* Options to pass onto the extension compiler
*
* @var array
*/
public $options;
private $options;
/**
* The build output path for the build configuration, eg; build/%BUILD.NAME%
*
* @var string
*/
public $output_path;
private $output_path;
/**
* An array of constants to define for the build when importing or executing.
*
* @var string[]
*/
public $define_constants;
private $define_constants;
/**
* An array of files to exclude in this build configuration
*
* @var string[]
*/
public $exclude_files;
private $exclude_files;
/**
* An array of policies to execute pre-building the package
*
* @var string[]|string
* @var string[]
*/
public $pre_build;
private $pre_build;
/**
* An array of policies to execute post-building the package
*
* @var string
* @var string[]
*/
public $post_build;
private $post_build;
/**
* Dependencies required for the build configuration, cannot conflict with the
@ -91,7 +91,7 @@
*
* @var Dependency[]
*/
public $dependencies;
private $dependencies;
/**
* Public Constructor
@ -210,6 +210,207 @@
return True;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
/**
* @return array
*/
public function getOptions(): array
{
return $this->options;
}
/**
* @param array $options
*/
public function setOptions(array $options): void
{
$this->options = $options;
}
/**
* @return string
*/
public function getOutputPath(): string
{
return $this->output_path;
}
/**
* @param string $output_path
*/
public function setOutputPath(string $output_path): void
{
$this->output_path = $output_path;
}
/**
* @return array|string[]
*/
public function getDefineConstants(): array
{
return $this->define_constants;
}
/**
* Sets a defined constant for the build configuration
*
* @param string $name
* @param string $value
*/
public function setDefinedConstant(string $name, string $value): void
{
$this->define_constants[$name] = $value;
}
/**
* Removes a defined constant from the build configuration
*
* @param string $name
* @return void
*/
public function removeDefinedConstant(string $name): void
{
unset($this->define_constants[$name]);
}
/**
* Returns excluded files
*
* @return array|string[]
*/
public function getExcludeFiles(): array
{
return $this->exclude_files;
}
/**
* Adds a file to the excluded files list
*
* @param string $file
*/
public function addExcludedFile(string $file): void
{
$this->exclude_files[] = $file;
}
/**
* Removes a file from the excluded files list
*
* @param string $file
* @return void
*/
public function removeExcludedFile(string $file): void
{
$this->exclude_files = array_filter($this->exclude_files, static function($item) use ($file)
{
return $item !== $file;
});
}
/**
* @return array|string[]
*/
public function getPreBuild(): array
{
return $this->pre_build;
}
/**
* @param string $pre_build
*/
public function addPreBuild(string $pre_build): void
{
$this->pre_build[] = $pre_build;
}
/**
* Removes a pre-build policy
*
* @param string $pre_build
* @return void
*/
public function removePreBuild(string $pre_build): void
{
$this->pre_build = array_filter($this->pre_build, static function($item) use ($pre_build)
{
return $item !== $pre_build;
});
}
/**
* @return array
*/
public function getPostBuild(): array
{
return $this->post_build;
}
/**
* Adds a post-build policy
*
* @param string $post_build
*/
public function addPostBuild(string $post_build): void
{
$this->post_build[] = $post_build;
}
/**
* @return Dependency[]
*/
public function getDependencies(): array
{
return $this->dependencies;
}
/**
* @param Dependency[] $dependencies
*/
public function setDependencies(array $dependencies): void
{
$this->dependencies = $dependencies;
}
/**
* Adds a dependency to the build configuration
*
* @param Dependency $dependency
* @return void
*/
public function addDependency(Dependency $dependency): void
{
$this->dependencies[] = $dependency;
}
/**
* Removes a dependency from the build configuration
*
* @param Dependency $dependency
* @return void
*/
public function removeDependency(Dependency $dependency): void
{
$this->dependencies = array_filter($this->dependencies, static function($item) use ($dependency)
{
return $item !== $dependency;
});
}
/**
* @inheritDoc
*/
@ -268,12 +469,12 @@
$object = new BuildConfiguration();
$object->name = Functions::array_bc($data, 'name');
$object->options = Functions::array_bc($data, 'options');
$object->options = Functions::array_bc($data, 'options') ?? [];
$object->output_path = Functions::array_bc($data, 'output_path');
$object->define_constants = Functions::array_bc($data, 'define_constants');
$object->exclude_files = Functions::array_bc($data, 'exclude_files');
$object->pre_build = Functions::array_bc($data, 'pre_build');
$object->post_build = Functions::array_bc($data, 'post_build');
$object->define_constants = Functions::array_bc($data, 'define_constants') ?? [];
$object->exclude_files = Functions::array_bc($data, 'exclude_files') ?? [];
$object->pre_build = Functions::array_bc($data, 'pre_build') ?? [];
$object->post_build = Functions::array_bc($data, 'post_build') ?? [];
if(Functions::array_bc($data, 'dependencies') !== null)
{

View file

@ -44,21 +44,69 @@
*
* @var string
*/
public $extension;
private $extension;
/**
* The minimum version that is supported
*
* @var string
*/
public $minimum_version;
private $minimum_version;
/**
* The maximum version that is supported
*
* @var string
*/
public $maximum_version;
private $maximum_version;
/**
* @return string
*/
public function getExtension(): string
{
return $this->extension;
}
/**
* @param string $extension
*/
public function setExtension(string $extension): void
{
$this->extension = $extension;
}
/**
* @return string
*/
public function getMinimumVersion(): string
{
return $this->minimum_version;
}
/**
* @param string $minimum_version
*/
public function setMinimumVersion(string $minimum_version): void
{
$this->minimum_version = $minimum_version;
}
/**
* @return string
*/
public function getMaximumVersion(): string
{
return $this->maximum_version;
}
/**
* @param string $maximum_version
*/
public function setMaximumVersion(string $maximum_version): void
{
$this->maximum_version = $maximum_version;
}
/**
* Validates the compiler object

View file

@ -36,35 +36,115 @@
*
* @var string
*/
public $name;
private $name;
/**
* The name of a supported runner instance
*
* @var string
*/
public $runner;
private $runner;
/**
* The message to display when the policy is invoked
*
* @var string|null
*/
public $message;
private $message;
/**
* The execution process of the policy
*
* @var Execute
*/
public $execute;
private $execute;
/**
* The configuration for exit handling
*
* @var ExitHandlers
*/
public $exit_handlers;
private $exit_handlers;
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
/**
* @return string
*/
public function getRunner(): string
{
return $this->runner;
}
/**
* @param string $runner
*/
public function setRunner(string $runner): void
{
$this->runner = $runner;
}
/**
* @return string|null
*/
public function getMessage(): ?string
{
return $this->message;
}
/**
* @param string|null $message
*/
public function setMessage(?string $message): void
{
$this->message = $message;
}
/**
* @return Execute
*/
public function getExecute(): Execute
{
return $this->execute;
}
/**
* @param Execute $execute
*/
public function setExecute(Execute $execute): void
{
$this->execute = $execute;
}
/**
* @return ExitHandlers
*/
public function getExitHandlers(): ExitHandlers
{
return $this->exit_handlers;
}
/**
* @param ExitHandlers $exit_handlers
*/
public function setExitHandlers(ExitHandlers $exit_handlers): void
{
$this->exit_handlers = $exit_handlers;
}
/**
* @return bool

View file

@ -24,6 +24,7 @@
namespace ncc\Objects\ProjectConfiguration\ExecutionPolicy;
use ncc\Enums\SpecialConstants\RuntimeConstants;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Utilities\Functions;
@ -34,7 +35,7 @@
*
* @var string
*/
public $target;
private $target;
/**
* The working directory to execute the policy in, if not specified the
@ -42,35 +43,35 @@
*
* @var string|null
*/
public $working_directory;
private $working_directory;
/**
* Options to pass to the process
*
* @var array
*/
public $options;
private $options;
/**
* An array of environment variables to pass on to the process
*
* @var array|null
* @var array
*/
public $environment_variables;
private $environment_variables;
/**
* Indicates if the output should be displayed or suppressed
*
* @var bool|null
* @var bool
*/
public $silent;
private $silent;
/**
* Indicates if the process should run in Tty mode (Overrides Silent & Pty mode)
*
* @var bool|null
* @var bool
*/
public $tty;
private $tty;
/**
* The number of seconds to wait before giving up on the process, will automatically execute the error handler
@ -78,12 +79,12 @@
*
* @var int|null
*/
public $timeout;
private $timeout;
/**
* @var int|null
*/
public $idle_timeout;
private $idle_timeout;
/**
* Public Constructor
@ -92,11 +93,149 @@
{
$this->tty = false;
$this->silent = false;
$this->timeout = null;
$this->idle_timeout = null;
$this->working_directory = "%CWD%";
}
/**
* Gets the target file to execute
*
* @return string
*/
public function getTarget(): string
{
return $this->target;
}
/**
* Sets the target file to execute
*
* @param string $target
*/
public function setTarget(string $target): void
{
$this->target = $target;
}
/**
* Returns the working directory to execute the policy in, if not specified the value "%CWD%" will be used as
* the default
*
* @return string
*/
public function getWorkingDirectory(): string
{
return $this->working_directory ?? RuntimeConstants::CWD;
}
/**
* Sets the working directory to execute the policy in, if not specified, the value "%CWD%" will be used as
* the default
*
* @param string|null $working_directory
*/
public function setWorkingDirectory(?string $working_directory): void
{
$this->working_directory = $working_directory;
}
/**
* @return array
*/
public function getOptions(): array
{
return $this->options;
}
/**
* @param array $options
*/
public function setOptions(array $options): void
{
$this->options = $options;
}
/**
* @return array
*/
public function getEnvironmentVariables(): array
{
return $this->environment_variables;
}
/**
* @param array $environment_variables
*/
public function setEnvironmentVariables(array $environment_variables): void
{
$this->environment_variables = $environment_variables;
}
/**
* @return bool
*/
public function isSilent(): bool
{
return $this->silent ?? false;
}
/**
* @param bool $silent
*/
public function setSilent(bool $silent): void
{
$this->silent = $silent;
}
/**
* @return bool
*/
public function isTty(): bool
{
return $this->tty ?? true;
}
/**
* @param bool $tty
*/
public function setTty(bool $tty): void
{
$this->tty = $tty;
}
/**
* @return int|null
*/
public function getTimeout(): ?int
{
return $this->timeout;
}
/**
* @param int|null $timeout
*/
public function setTimeout(?int $timeout): void
{
$this->timeout = $timeout;
}
/**
* @return int|null
*/
public function getIdleTimeout(): ?int
{
return $this->idle_timeout;
}
/**
* @param int|null $idle_timeout
*/
public function setIdleTimeout(?int $idle_timeout): void
{
$this->idle_timeout = $idle_timeout;
}
/**
* @inheritDoc
*/
@ -156,10 +295,10 @@
$object->target = Functions::array_bc($data, 'target');
$object->working_directory = Functions::array_bc($data, 'working_directory');
$object->options = Functions::array_bc($data, 'options');
$object->environment_variables = Functions::array_bc($data, 'environment_variables');
$object->silent = Functions::array_bc($data, 'silent');
$object->tty = Functions::array_bc($data, 'tty');
$object->options = Functions::array_bc($data, 'options') ?? [];
$object->environment_variables = Functions::array_bc($data, 'environment_variables') ?? [];
$object->silent = Functions::array_bc($data, 'silent') ?? false;
$object->tty = Functions::array_bc($data, 'tty') ?? true;
$object->timeout = Functions::array_bc($data, 'timeout');
$object->idle_timeout = Functions::array_bc($data, 'idle_timeout');

View file

@ -34,7 +34,7 @@
*
* @var string|null
*/
public $message;
private $message;
/**
* Indicates if the process should exit if the handle is triggered,
@ -43,23 +43,93 @@
* property will be set to true, otherwise for "success" and "warning"
* the property will be false.
*
* @var bool|null
* @var bool
*/
public $end_process;
private $end_process;
/**
* The name of another execution policy to execute (optionally) when this exit handle is triggered
*
* @var string|null
*/
public $run;
private $run;
/**
* The exit code that needs to be returned from the process to trigger this handle
*
* @var int
*/
public $exit_code;
private $exit_code;
public function __construct()
{
$this->end_process = false;
$this->exit_code = 0;
}
/**
* @return string|null
*/
public function getMessage(): ?string
{
return $this->message;
}
/**
* @param string|null $message
*/
public function setMessage(?string $message): void
{
$this->message = $message;
}
/**
* @return bool
*/
public function getEndProcess(): bool
{
return $this->end_process;
}
/**
* @param bool $end_process
*/
public function setEndProcess(bool $end_process): void
{
$this->end_process = $end_process;
}
/**
* @return string|null
*/
public function getRun(): ?string
{
return $this->run;
}
/**
* @param string|null $run
*/
public function setRun(?string $run): void
{
$this->run = $run;
}
/**
* @return int
*/
public function getExitCode(): int
{
return $this->exit_code;
}
/**
* @param int $exit_code
*/
public function setExitCode(int $exit_code): void
{
$this->exit_code = $exit_code;
}
/**
* @inheritDoc
@ -97,9 +167,9 @@
$object = new self();
$object->message = Functions::array_bc($data, 'message');
$object->end_process = Functions::array_bc($data, 'end_process');
$object->end_process = Functions::array_bc($data, 'end_process') ?? false;
$object->run = Functions::array_bc($data, 'run');
$object->exit_code = Functions::array_bc($data, 'exit_code');
$object->exit_code = Functions::array_bc($data, 'exit_code') ?? 0;
return $object;
}

View file

@ -34,21 +34,69 @@
*
* @var ExitHandle|null
*/
public $success;
private $success;
/**
* The handle to execute when the process exits with a warning exit code
*
* @var ExitHandle|null
*/
public $warning;
private $warning;
/**
* The handle to execute when the process exits with a error exit code
*
* @var ExitHandle|null
*/
public $error;
private $error;
/**
* @return ExitHandle|null
*/
public function getSuccess(): ?ExitHandle
{
return $this->success;
}
/**
* @param ExitHandle|null $success
*/
public function setSuccess(?ExitHandle $success): void
{
$this->success = $success;
}
/**
* @return ExitHandle|null
*/
public function getWarning(): ?ExitHandle
{
return $this->warning;
}
/**
* @param ExitHandle|null $warning
*/
public function setWarning(?ExitHandle $warning): void
{
$this->warning = $warning;
}
/**
* @return ExitHandle|null
*/
public function getError(): ?ExitHandle
{
return $this->error;
}
/**
* @param ExitHandle|null $error
*/
public function setError(?ExitHandle $error): void
{
$this->error = $error;
}
/**
* @inheritDoc
@ -65,26 +113,26 @@
/**
* @inheritDoc
*/
public static function fromArray(array $data): self
public static function fromArray(array $data): ExitHandlers
{
$object = new self();
$object->success = Functions::array_bc($data, 'success');
if($object->success !== null)
$object->setSuccess(Functions::array_bc($data, 'success'));
if($object->getSuccess() !== null)
{
$object->success = ExitHandle::fromArray($object->success);
$object->setSuccess(ExitHandle::fromArray((array)$object->getSuccess()));
}
$object->warning = Functions::array_bc($data, 'warning');
if($object->warning !== null)
$object->setWarning(Functions::array_bc($data, 'warning'));
if($object->getWarning() !== null)
{
$object->warning = ExitHandle::fromArray($object->warning);
$object->setWarning(ExitHandle::fromArray((array)$object->getWarning()));
}
$object->error = Functions::array_bc($data, 'error');
if($object->error !== null)
$object->setError(Functions::array_bc($data, 'error'));
if($object->getError() !== null)
{
$object->error = ExitHandle::fromArray($object->error);
$object->setError(ExitHandle::fromArray((array)$object->getError()));
}
return $object;

View file

@ -34,42 +34,42 @@
*
* @var string[]|null
*/
public $pre_install;
private $pre_install;
/**
* An array of execution policies to execute post-installation
*
* @var string[]|null
*/
public $post_install;
private $post_install;
/**
* An array of execution policies to execute pre-uninstallation
*
* @var string[]|null
*/
public $pre_uninstall;
private $pre_uninstall;
/**
* An array of execution policies to execute post-uninstallation
*
* @var string[]|null
*/
public $post_uninstall;
private $post_uninstall;
/**
* An array of execution policies to execute pre-update
*
* @var string[]|null
*/
public $pre_update;
private $pre_update;
/**
* An array of execution policies to execute post-update
*
* @var string[]|null
*/
public $post_update;
private $post_update;
/**
* @inheritDoc

View file

@ -24,6 +24,7 @@
namespace ncc\Objects\ProjectConfiguration\UpdateSource;
use ncc\Enums\RemoteSourceType;
use ncc\Interfaces\BytecodeObjectInterface;
use ncc\Utilities\Functions;
@ -34,28 +35,92 @@
*
* @var string
*/
public $name;
private $name;
/**
* The type of client that is used to connect to the remote source
*
* @var string|null
*/
public $type;
private $type;
/**
* The host of the remote source
*
* @var string
*/
public $host;
private $host;
/**
* If SSL should be used
*
* @var bool
*/
public $ssl;
private $ssl;
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name): void
{
$this->name = $name;
}
/**
* @return string|null
*/
public function getType(): ?string
{
return $this->type;
}
/**
* @param string|null $type
*/
public function setType(?string $type): void
{
$this->type = $type;
}
/**
* @return string
*/
public function getHost(): string
{
return $this->host;
}
/**
* @param string $host
*/
public function setHost(string $host): void
{
$this->host = $host;
}
/**
* @return bool
*/
public function isSsl(): bool
{
return $this->ssl;
}
/**
* @param bool $ssl
*/
public function setSsl(bool $ssl): void
{
$this->ssl = $ssl;
}
/**
* @inheritDoc
@ -78,9 +143,9 @@
$object = new self();
$object->name = Functions::array_bc($data, 'name');
$object->type = Functions::array_bc($data, 'type');
$object->type = Functions::array_bc($data, 'type') ?? RemoteSourceType::UNKNOWN;
$object->host = Functions::array_bc($data, 'host');
$object->ssl = Functions::array_bc($data, 'ssl');
$object->ssl = Functions::array_bc($data, 'ssl') ?? false;
return $object;
}

View file

@ -148,8 +148,6 @@
* @param string $name
* @param string $password
* @return bool
* @throws RuntimeException
* @noinspection PhpUnused
*/
public function authenticate(string $name, string $password): bool
{

View file

@ -110,7 +110,7 @@
if($version === Versions::LATEST)
{
$version = $package_entry?->getLatestVersion();
$version = $package_entry->getLatestVersion();
}
try
@ -152,14 +152,14 @@
try
{
switch($version_entry->Compiler->extension)
switch($version_entry->Compiler->getExtension())
{
case CompilerExtensions::PHP:
PhpRuntime::import($version_entry, $options);
break;
default:
throw new ImportException(sprintf('Compiler extension %s is not supported in this runtime', $version_entry->Compiler->extension));
throw new ImportException(sprintf('Compiler extension %s is not supported in this runtime', $version_entry->Compiler->getExtension()));
}
}
catch(Exception $e)

View file

@ -39,7 +39,9 @@ namespace ncc\Utilities;
{
// Builtin function is faster than raw implementation
if(function_exists('base64_encode'))
{
return base64_encode($string);
}
$base64 = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');
$bit_pattern = '';
@ -79,7 +81,9 @@ namespace ncc\Utilities;
public static function decode(string $string): string
{
if(function_exists('base64_decode'))
{
return base64_decode($string);
}
$base64 = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/');
$bit_pattern = '';
@ -88,7 +92,7 @@ namespace ncc\Utilities;
foreach (str_split($string) as $b64_encoded)
{
$bit_pattern .= sprintf('%06s', decbin(array_search($b64_encoded, $base64)));
$bit_pattern .= sprintf('%06s', decbin(array_search($b64_encoded, $base64, true)));
}
$bit_pattern = str_split($bit_pattern, 8);

View file

@ -1,24 +1,24 @@
<?php
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*
* Copyright (c) Nosial 2022-2023, all rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
* associated documentation files (the "Software"), to deal in the Software without restriction, including without
* limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
* Software, and to permit persons to whom the Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions
* of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/** @noinspection PhpMissingFieldTypeInspection */
@ -51,76 +51,51 @@
* @param int $size
* @param array $options
* @return void
*@copyright Copyright (c) 2010, dealnews.com, Inc. All rights reserved.
* @copyright Copyright (c) 2010, dealnews.com, Inc. All rights reserved.
* @copyright Copyright (c) 2023, Nosial. All rights reserved
*/
public static function inlineProgressBar(int $value, int $total, int $size=38, array $options=[]): void
public static function inlineProgressBar(int $value, int $total, int $size = 10, array $options = []): void
{
if(!ncc::cliMode())
return;
if(Main::getLogLevel() !== null)
{
switch(Main::getLogLevel())
{
case LogLevel::VERBOSE:
case LogLevel::DEBUG:
case LogLevel::SILENT:
return;
default:
break;
}
}
static $start_time;
// if we go over our bound, just ignore it
if($value > $total)
return;
if(empty($start_time)) $start_time=time();
$now = time();
$perc=(double)($value/$total);
$bar=floor($perc*$size);
$status_bar="\r[ ";
$status_bar.=str_repeat("=", $bar);
if($bar<$size){
$status_bar.=">";
$status_bar.=str_repeat(" ", $size-$bar);
} else {
$status_bar.="=";
}
/** @noinspection PhpRedundantOptionalArgumentInspection */
$disp=number_format($perc*100, 0);
$status_bar.=" ] $disp% $value/$total";
if($value == 0)
return;
$rate = ($now-$start_time)/$value;
$left = $total - $value;
$eta = round($rate * $left, 2);
$elapsed = $now - $start_time;
$remaining_text = 'remaining: ';
if(isset($options['remaining_text']))
// Start time initialization
if (!$start_time)
{
$remaining_text = $options['remaining_text'];
$start_time = time();
}
$status_bar.= " $remaining_text ".number_format($eta)." sec. elapsed: ".number_format($elapsed)." sec.";
// If the value is out of bounds or zero, return early
if ($value > $total || $value === 0)
{
return;
}
echo "$status_bar ";
// Build status bar
$percentage = $value / $total;
$barLength = floor($percentage * $size);
$statusBar = "\r[ "
. str_repeat("=", $barLength)
. ($barLength < $size ? ">" : "=")
. str_repeat(" ", $size - $barLength)
. " ] "
. number_format($percentage * 100) . " % $value/$total";
// ETA and elapsed time calculation
$rate = (time() - $start_time) / $value;
$eta = round($rate * ($total - $value), 2);
$elapsed = time() - $start_time;
$remaining_text = $options['remaining_text'] ?? 'remaining: ';
$statusBar .= " $remaining_text " . number_format($eta) . " sec. elapsed: " . number_format($elapsed) . " sec.";
print("$statusBar ");
flush();
// when done, send a newline
if($value == $total)
Console::out((string)null);
// Reset variables once the progress is complete
if ($value === $total)
{
print("\n");
$start_time = null; // This resets the start time for the next progress bar
}
}
/**
@ -162,11 +137,11 @@
if ($timeDiff > 1.0)
{
$fmt_tick = Console::formatColor($tick_time, ConsoleColors::LIGHT_RED);
$fmt_tick = self::formatColor($tick_time, ConsoleColors::LIGHT_RED);
}
elseif ($timeDiff > 0.5)
{
$fmt_tick = Console::formatColor($tick_time, ConsoleColors::LIGHT_YELLOW);
$fmt_tick = self::formatColor($tick_time, ConsoleColors::LIGHT_YELLOW);
}
}
@ -185,13 +160,19 @@
public static function out(string $message, bool $newline=true, bool $no_prefix=false): void
{
if(!ncc::cliMode())
{
return;
}
if(Main::getLogLevel() !== null && !Resolver::checkLogLevel(LogLevel::INFO, Main::getLogLevel()))
{
return;
}
if(Main::getLogLevel() !== null && Resolver::checkLogLevel(LogLevel::VERBOSE, Main::getLogLevel()) && !$no_prefix)
if(!$no_prefix && Main::getLogLevel() !== null && Resolver::checkLogLevel(LogLevel::VERBOSE, Main::getLogLevel()))
{
$message = self::setPrefix(LogLevel::INFO, $message);
}
if($newline)
{
@ -212,34 +193,30 @@
public static function outDebug(string $message, bool $newline=true): void
{
if(!ncc::cliMode())
{
return;
}
if(Main::getLogLevel() !== null && !Resolver::checkLogLevel(LogLevel::DEBUG, Main::getLogLevel()))
{
return;
}
$backtrace = null;
if(function_exists('debug_backtrace'))
{
$backtrace = debug_backtrace();
}
$trace_msg = null;
if($backtrace !== null && isset($backtrace[1]))
{
$trace_msg = Console::formatColor($backtrace[1]['class'], ConsoleColors::LIGHT_GREY);
$trace_msg = self::formatColor($backtrace[1]['class'], ConsoleColors::LIGHT_GREY);
$trace_msg .= $backtrace[1]['type'];
$trace_msg .= Console::formatColor($backtrace[1]['function'] . '()', ConsoleColors::LIGHT_GREEN);
$trace_msg .= self::formatColor($backtrace[1]['function'] . '()', ConsoleColors::LIGHT_GREEN);
$trace_msg .= ' > ';
}
/** Apply syntax highlighting using regular expressions */
// Hyperlinks
$message = preg_replace('/(https?:\/\/[^\s]+)/', Console::formatColor('$1', ConsoleColors::LIGHT_BLUE), $message);
// File Paths
$message = preg_replace('/(\/[^\s]+)/', Console::formatColor('$1', ConsoleColors::LIGHT_CYAN), $message);
/** @noinspection PhpUnnecessaryStringCastInspection */
$message = self::setPrefix(LogLevel::DEBUG, (string)$trace_msg . $message);
$message = self::setPrefix(LogLevel::DEBUG, $trace_msg . $message);
self::out($message, $newline, true);
}
@ -253,10 +230,14 @@
public static function outVerbose(string $message, bool $newline=true): void
{
if(!ncc::cliMode())
{
return;
}
if(Main::getLogLevel() !== null && !Resolver::checkLogLevel(LogLevel::VERBOSE, Main::getLogLevel()))
{
return;
}
self::out(self::setPrefix(LogLevel::VERBOSE, $message), $newline, true);
}
@ -295,10 +276,14 @@
public static function outWarning(string $message, bool $newline=true): void
{
if(!ncc::cliMode())
{
return;
}
if(Main::getLogLevel() !== null && !Resolver::checkLogLevel(LogLevel::WARNING, Main::getLogLevel()))
{
return;
}
if(Main::getLogLevel() !== null && Resolver::checkLogLevel(LogLevel::VERBOSE, Main::getLogLevel()))
{
@ -320,10 +305,14 @@
public static function outError(string $message, bool $newline=true, ?int $exit_code=null): void
{
if(!ncc::cliMode())
{
return;
}
if(Main::getLogLevel() !== null && !Resolver::checkLogLevel(LogLevel::ERROR, Main::getLogLevel()))
{
return;
}
if(Main::getLogLevel() !== null && Resolver::checkLogLevel(LogLevel::VERBOSE, Main::getLogLevel()))
{
@ -351,14 +340,16 @@
public static function outException(string $message, Exception $e, ?int $exit_code=null): void
{
if(!ncc::cliMode())
{
return;
}
if(strlen($message) > 0 && Resolver::checkLogLevel(LogLevel::ERROR, Main::getLogLevel()))
if($message !== '' && Resolver::checkLogLevel(LogLevel::ERROR, Main::getLogLevel()))
{
self::out(PHP_EOL . self::formatColor('Error: ', ConsoleColors::RED) . $message);
}
Console::out(PHP_EOL . '===== Exception Details =====');
self::out(PHP_EOL . '===== Exception Details =====');
self::outExceptionDetails($e);
if($exit_code !== null)
@ -377,10 +368,11 @@
private static function outExceptionDetails(Throwable $e, bool $sub=false): void
{
if(!ncc::cliMode())
{
return;
}
// Exception name without namespace
$trace_header = self::formatColor($e->getFile() . ':' . $e->getLine(), ConsoleColors::MAGENTA);
$trace_error = self::formatColor( 'Error: ', ConsoleColors::RED);
self::out($trace_header . ' ' . $trace_error . $e->getMessage());
@ -396,16 +388,13 @@
}
}
if($e->getPrevious() !== null)
// Check if previous is the same as the current
if(($e->getPrevious() !== null) && $e->getPrevious()->getMessage() !== $e->getMessage())
{
// Check if previous is the same as the current
if($e->getPrevious()->getMessage() !== $e->getMessage())
{
self::outExceptionDetails($e->getPrevious(), true);
}
self::outExceptionDetails($e->getPrevious(), true);
}
if(Main::getArgs() !== null && !$sub)
if(!$sub && Main::getArgs() !== null)
{
if(isset(Main::getArgs()['dbg-ex']))
{
@ -415,7 +404,8 @@
'constants' => ncc::getConstants(),
'exception' => Functions::exceptionToArray($e)
];
IO::fwrite(getcwd() . DIRECTORY_SEPARATOR . time() . '.json', json_encode($dump, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), 0777);
IO::fwrite(getcwd() . DIRECTORY_SEPARATOR . time() . '.json', json_encode($dump, JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), 0777);
}
catch (Exception $e)
{
@ -451,12 +441,7 @@
*/
public static function getOptionInput(array $args, string $option, string $prompt): string
{
if(isset($args[$option]))
{
return $args[$option];
}
return self::getInput($prompt);
return $args[$option] ?? self::getInput($prompt);
}
/**
@ -479,7 +464,7 @@
$r = self::getInput($prompt);
}
if(strlen($r) > 0)
if($r !== '')
{
switch(strtoupper($r))
{
@ -506,7 +491,9 @@
public static function passwordInput(string $prompt): ?string
{
if(!ncc::cliMode())
{
return null;
}
// passwordInput() is not properly implemented yet, defaulting to prompt
return self::getInput($prompt);
@ -537,12 +524,16 @@
public static function outHelpSections(array $sections): void
{
if(!ncc::cliMode())
{
return;
}
$padding = Functions::detectParametersPadding($sections);
foreach($sections as $section)
Console::out(' ' . $section->toString($padding));
{
self::out(' ' . $section->toString($padding));
}
}
}

View file

@ -294,7 +294,7 @@
*/
public static function compileRunner(string $path, ExecutionPolicy $policy): ExecutionUnit
{
return match (strtolower($policy->runner))
return match (strtolower($policy->getRunner()))
{
Runners::BASH => BashRunner::processUnit($path, $policy),
Runners::PHP => PhpRunner::processUnit($path, $policy),
@ -303,7 +303,7 @@
Runners::PYTHON_2 => Python2Runner::processUnit($path, $policy),
Runners::PYTHON_3 => Python3Runner::processUnit($path, $policy),
Runners::LUA => LuaRunner::processUnit($path, $policy),
default => throw new NotSupportedException('The runner \'' . $policy->runner . '\' is not supported'),
default => throw new NotSupportedException('The runner \'' . $policy->getRunner() . '\' is not supported'),
};
}
@ -371,7 +371,7 @@
if(!$filesystem->exists(PathFinder::getCachePath(Scopes::SYSTEM)))
{
Console::outDebug(sprintf('Initializing %s', PathFinder::getCachePath(Scopes::SYSTEM)));
$filesystem->mkdir(PathFinder::getCachePath(Scopes::SYSTEM), 0777);
$filesystem->mkdir(PathFinder::getCachePath(Scopes::SYSTEM));
}
if(!$filesystem->exists(PathFinder::getRunnerPath(Scopes::SYSTEM)))

View file

@ -46,7 +46,7 @@
private static $version_information;
/**
* Returns the version information object about the current build of NCC
* Returns the version information object about the current build of ncc
*
* @param boolean $reload Indicates if the cached version is to be ignored and the version file to be reloaded and validated
* @return NccVersionInformation
@ -87,10 +87,9 @@
}
/**
* Initializes the NCC environment
* Initializes the ncc environment
*
* @return bool
* @throws IOException
* @throws PathNotFoundException
*/
public static function initialize(): bool
@ -102,7 +101,7 @@
// Set debugging/troubleshooting constants
define('NCC_EXEC_LOCATION', __DIR__); // The directory of where ncc.php is located
define('NCC_EXEC_IWD', getcwd()); // The initial working directory when NCC was first invoked
define('NCC_EXEC_IWD', getcwd()); // The initial working directory when ncc was first invoked
// Set version information about the current build
$VersionInformation = self::getVersionInformation(true);
@ -116,7 +115,7 @@
}
/**
* Determines if NCC is currently in CLI mode or not
* Determines if ncc is currently in CLI mode or not
*
* @return bool
*/
@ -126,7 +125,7 @@
}
/**
* Returns the constants set by NCC
* Returns the constants set by ncc
*
* @return array
*/
@ -135,7 +134,7 @@
if(!defined('NCC_INIT'))
{
/** @noinspection ClassConstantCanBeUsedInspection */
throw new RuntimeException('NCC Must be initialized before executing ' . get_called_class() . '::getConstants()');
throw new RuntimeException('ncc Must be initialized before executing ' . get_called_class() . '::getConstants()');
}
return [