1.0.0 Alpha Release

This commit is contained in:
Zi Xing 2023-01-29 23:27:56 +00:00
parent 9fb26e9aa0
commit c2b7be0ea2
297 changed files with 13712 additions and 2517 deletions

View file

@ -19,12 +19,6 @@ ncc:
php:
# The main executable path for PHP that NCC should use
executable_path: "/usr/bin/php"
runtime:
# Whether to initialize NCC when running `require('ncc');`
initialize_on_require: true
# if NCC should handle fatal exceptions during execution
handle_exceptions: true
git:
# if git is enabled or not
@ -55,10 +49,10 @@ composer:
quiet: false
# Disable ANSI output
no_ansi: false
no_ansi: true
# Do not ask any interactive question
no_interaction: false
no_interaction: true
# Display timing and memory usage information
profile: false

View file

@ -0,0 +1,6 @@
[
"gitgud.json",
"github.json",
"gitlab.json",
"n64.json"
]

View file

@ -0,0 +1,6 @@
{
"name": "gitgud",
"type": "gitlab",
"host": "gitgud.io",
"ssl": true
}

View file

@ -0,0 +1,6 @@
{
"name": "github",
"type": "github",
"host": "api.github.com",
"ssl": true
}

View file

@ -0,0 +1,6 @@
{
"name": "gitlab",
"type": "gitlab",
"host": "gitlab.com",
"ssl": true
}

View file

@ -0,0 +1,6 @@
{
"name": "n64",
"type": "gitlab",
"host": "git.n64.cc",
"ssl": true
}

View file

@ -1,8 +1,19 @@
<?php
if(defined('NCC_INIT') == false)
use ncc\Abstracts\Versions;
use ncc\Exceptions\ConstantReadonlyException;
use ncc\Exceptions\ImportException;
use ncc\Exceptions\InvalidConstantNameException;
use ncc\Exceptions\InvalidPackageNameException;
use ncc\Exceptions\InvalidScopeException;
use ncc\Exceptions\PackageLockException;
use ncc\Exceptions\PackageNotFoundException;
use ncc\ncc;
use ncc\Runtime;
if(!defined('NCC_INIT'))
{
if(file_exists('%ncc_install' . DIRECTORY_SEPARATOR . 'autoload.php') == false)
if(!file_exists('%ncc_install' . DIRECTORY_SEPARATOR . 'autoload.php'))
{
throw new RuntimeException('Cannot locate file \'%ncc_install' . DIRECTORY_SEPARATOR . 'autoload.php\'');
}
@ -10,4 +21,150 @@
{
require('%ncc_install' . DIRECTORY_SEPARATOR . 'autoload.php');
}
if(!function_exists('import'))
{
/**
* Attempts to import a package into the current runtime
*
* @param string $package
* @param string $version
* @param array $options
* @return void
* @throws ImportException
*/
function import(string $package, string $version= Versions::Latest, array $options=[]): void
{
Runtime::import($package, $version, $options);
}
}
if(!function_exists('get_imported'))
{
/**
* Returns an array of all imported packages
*
* @return array
*/
function get_imported(): array
{
return Runtime::getImportedPackages();
}
}
if(!function_exists('ncc_constants'))
{
/**
* Returns an array of constants defined by NCC
*
* @return array
* @throws \ncc\Exceptions\RuntimeException
*/
function ncc_constants(): array
{
return ncc::getConstants();
}
}
if(!function_exists('consts_get'))
{
/**
* Returns the value of a constant defined in NCC's runtime environment
*
* @param string $package
* @param string $name
* @return string|null
*/
function consts_get(string $package, string $name): ?string
{
return Runtime\Constants::get($package, $name);
}
}
if(!function_exists('consts_set'))
{
/**
* Sets the value of a constant defined in NCC's runtime environment
*
* @param string $package
* @param string $name
* @param string $value
* @param bool $readonly
* @return void
* @throws ConstantReadonlyException
* @throws InvalidConstantNameException
*/
function consts_set(string $package, string $name, string $value, bool $readonly=false): void
{
Runtime\Constants::register($package, $name, $value, $readonly);
}
}
if(!function_exists('consts_delete'))
{
/**
* Deletes a constant defined in NCC's runtime environment
*
* @param string $package
* @param string $name
* @return void
* @throws ConstantReadonlyException
*/
function consts_delete(string $package, string $name): void
{
Runtime\Constants::delete($package, $name);
}
}
if(!function_exists('get_data_path'))
{
/**
* Returns the data path of the package
*
* @param string $package
* @return string
* @throws InvalidPackageNameException
* @throws InvalidScopeException
* @throws PackageLockException
* @throws PackageNotFoundException
*/
function get_data_path(string $package): string
{
return Runtime::getDataPath($package);
}
}
if(!function_exists('get_constant'))
{
/**
* Returns the value of a constant defined in NCC's runtime environment
*
* @param string $package
* @param string $name
* @return string|null
*/
function get_constant(string $package, string $name): ?string
{
return Runtime::getConstant($package, $name);
}
}
if(!function_exists('set_constant'))
{
/**
* Sets the value of a constant defined in NCC's runtime environment
*
* @param string $package
* @param string $name
* @param string $value
* @return void
* @throws ConstantReadonlyException
* @throws InvalidConstantNameException
*/
function set_constant(string $package, string $name, string $value): void
{
Runtime::setConstant($package, $name, $value);
}
}
}

View file

@ -14,8 +14,10 @@
use ncc\Abstracts\ConsoleColors;
use ncc\Exceptions\FileNotFoundException;
use ncc\Managers\RemoteSourcesManager;
use ncc\ncc;
use ncc\Objects\CliHelpSection;
use ncc\Objects\DefinedRemoteSource;
use ncc\ThirdParty\Symfony\Filesystem\Exception\IOException;
use ncc\ThirdParty\Symfony\Filesystem\Filesystem;
use ncc\ThirdParty\Symfony\Process\Exception\ProcessFailedException;
@ -712,7 +714,6 @@
$config_obj['composer']['enable_internal_composer'] = false;
if($config_obj['composer']['executable_path'] == null)
{
// TODO: Implement Configuration Tools
Console::outWarning('Cannot locate the executable path for \'composer\', run \'ncc config --composer.executable_path="composer.phar"\' as root to update the path');
}
}
@ -724,7 +725,7 @@
{
if ($NCC_FILESYSTEM->exists(PathFinder::getConfigurationFile()))
{
$config_backup = IO::fread(PathFinder::getConfigurationFile());
$config_backup = Yaml::parseFile(PathFinder::getConfigurationFile());
}
}
catch (Exception $e)
@ -736,33 +737,73 @@
// Create/Update configuration file
$config_obj = Yaml::parseFile(__DIR__ . DIRECTORY_SEPARATOR . 'default_config.yaml');
// Update the old configuration
if($config_backup !== null)
if(!function_exists('array_replace_recursive'))
{
$old_config_obj = Yaml::parse($config_backup);
foreach($old_config_obj as $section => $value)
/**
* @param $array
* @param $array1
* @return array|mixed
* @author <msahagian@dotink.org>
* @noinspection PhpMissingReturnTypeInspection
*/
function array_replace_recursive($array, $array1)
{
if(isset($config_obj[$section]))
// handle the arguments, merge one by one
$args = func_get_args();
$array = $args[0];
if (!is_array($array))
{
foreach($value as $section_item => $section_value)
return $array;
}
for ($i = 1; $i < count($args); $i++)
{
if (is_array($args[$i]))
{
if(!isset($config_obj[$section][$section_item]))
{
$config_obj[$section][$section_item] = $section_value;
}
$array = recurse($array, $args[$i]);
}
}
else
{
$config_obj[$section] = $value;
}
return $array;
}
}
if(!function_exists('recurse'))
{
/**
* @param $array
* @param $array1
* @return mixed
* @author <msahagian@dotink.org>
* @noinspection PhpMissingReturnTypeInspection
*/
function recurse($array, $array1)
{
foreach ($array1 as $key => $value)
{
// create new key in $array, if it is empty or not an array
/** @noinspection PhpConditionAlreadyCheckedInspection */
if (!isset($array[$key]) || (isset($array[$key]) && !is_array($array[$key])))
{
$array[$key] = array();
}
// overwrite the value in the base array
if (is_array($value))
{
$value = recurse($array[$key], $value);
}
$array[$key] = $value;
}
return $array;
}
}
if($config_backup !== null)
$config_obj = array_replace_recursive($config_obj, $config_backup);
if($config_backup == null)
{
Console::out('Generating ncc.yaml');
}
else
{
@ -779,6 +820,57 @@
return;
}
if($NCC_FILESYSTEM->exists(__DIR__ . DIRECTORY_SEPARATOR . 'repositories'))
{
if(!$NCC_FILESYSTEM->exists(__DIR__ . DIRECTORY_SEPARATOR . 'repositories' . DIRECTORY_SEPARATOR . 'custom_repositories.json'))
return;
try
{
$custom_repositories = Functions::loadJsonFile(__DIR__ . DIRECTORY_SEPARATOR . 'repositories' . DIRECTORY_SEPARATOR . 'custom_repositories.json', Functions::FORCE_ARRAY);
}
catch(Exception $e)
{
$custom_repositories = null;
Console::outWarning(sprintf('Failed to load custom repositories: %s', $e->getMessage()));
}
if($custom_repositories !== null)
{
$source_manager = new RemoteSourcesManager();
foreach($custom_repositories as $repository)
{
$repo_path = __DIR__ . DIRECTORY_SEPARATOR . 'repositories' . DIRECTORY_SEPARATOR . $repository;
if($NCC_FILESYSTEM->exists($repo_path))
{
try
{
$definedEntry = DefinedRemoteSource::fromArray(Functions::loadJsonFile($repo_path, Functions::FORCE_ARRAY));
if(!$source_manager->getRemoteSource($definedEntry->Name))
$source_manager->addRemoteSource($definedEntry);
}
catch(Exception $e)
{
Console::outWarning(sprintf('Failed to load custom repository %s: %s', $repository, $e->getMessage()));
}
}
else
{
Console::outWarning(sprintf('Failed to load custom repository %s, file does not exist', $repository));
}
}
try
{
$source_manager->save();
}
catch (\ncc\Exceptions\IOException $e)
{
Console::outWarning(sprintf('Failed to save sources: %s', $e->getMessage()));
}
}
}
Console::out('NCC version: ' . NCC_VERSION_NUMBER . ' has been successfully installed');
Console::out('For licensing information see \'' . $NCC_INSTALL_PATH . DIRECTORY_SEPARATOR . 'LICENSE\' or run \'ncc help --license\'');

View file

@ -1,12 +0,0 @@
<?php
namespace ncc\Abstracts;
abstract class AuthenticationSource
{
const None = 'NONE';
const ServerProvided = 'SERVER_PROVIDED';
const UserProvided = 'USER_PROVIDED';
}

View file

@ -0,0 +1,36 @@
<?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\Abstracts;
abstract class AuthenticationType
{
/**
* A combination of a username and password is used for authentication
*/
const UsernamePassword = 1;
/**
* A single private access token is used for authentication
*/
const AccessToken = 2;
}

View file

@ -0,0 +1,37 @@
<?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\Abstracts;
class BuiltinRemoteSourceType
{
/**
* The remote source indicates the package is to be
* fetched using the composer utility.
*/
const Composer = 'composer';
const All = [
self::Composer
];
}

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class CompilerExtensionDefaultVersions
{
@ -9,5 +29,5 @@
// [1] = MaximumVersion
// ----------------------------------------------------------------
const PHP = ['8.0', '8.1'];
const PHP = ['8.0', '8.2'];
}

View file

@ -1,8 +1,28 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class CompilerExtensionSupportedVersions
{
const PHP = ['8.0', '8.1'];
const PHP = ['8.0', '8.1', '8.2'];
}

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class CompilerExtensions
{

View file

@ -1,8 +0,0 @@
<?php
namespace ncc\Abstracts;
abstract class CompilerOptions
{
}

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class ComponentDataType
{

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class ComponentFileExtensions
{

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class ComposerPackageTypes
{
@ -12,7 +32,7 @@
/**
* This denotes a project rather than a library. For example
* application shells like the Symfony standard edition, CMSs
* like the SilverStripe instlaler or full-fledged applications
* like the SilverStripe installer or full-fledged applications
* distributed as packages. This can for example be used by IDEs
* to provide listings of projects to initialize when creating
* a new workspace.

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class ComposerStabilityTypes
{

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class ConsoleColors
{

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class ConstantReferences
{
@ -11,4 +31,6 @@
const DateTime = 'date_time';
const Install = 'install';
const Runtime = 'runtime';
}

View file

@ -0,0 +1,53 @@
<?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\Abstracts;
abstract class DefinedRemoteSourceType
{
/**
* THe remote source is from gitlab or a custom gitlab instance
*
* Will use an API wrapper to interact with the gitlab instance
* to fetch the package and check for updates without having to
* pull the entire repository
*
* Will still use git to fetch the package from the gitlab instance
*/
const Gitlab = 'gitlab';
/**
* The remote source is from GitHub
*
* Will use an API wrapper to interact with the GitHub instance
* to fetch the package and check for updates without having to
* pull the entire repository
*
* Will still use git to fetch the package from the GitHub instance
*/
const Github = 'github';
const All = [
self::Gitlab,
self::Github
];
}

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class DependencySourceType
{

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class EncoderType
{

View file

@ -1,6 +1,28 @@
<?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\Abstracts;
namespace ncc\Abstracts;
use ncc\Exceptions\SymlinkException;
/**
* @author Zi Xing Narrakas
@ -268,6 +290,91 @@
*/
const MissingDependencyException = -1751;
/**
* @see HttpException
*/
const HttpException = -1752;
/**
* @see UnsupportedRemoteSourceTypeException
*/
const UnsupportedRemoteSourceTypeException = -1753;
/**
* @see GitCloneException
*/
const GitCloneException = -1754;
/**
* @see GitCheckoutException
*/
const GitCheckoutException = -1755;
/**
* @see GitlabServiceException
*/
const GitlabServiceException = -1756;
/**
* @see ImportException
*/
const ImportException = -1757;
/**
* @see GitTagsException
*/
const GitTagsException = -1758;
/**
* @see GithubServiceException
*/
const GithubServiceException = -1759;
/**
* @see AuthenticationException
*/
const AuthenticationException = -1760;
/**
* @see NotSupportedException
*/
const NotSupportedException = -1761;
/**
* @see UnsupportedProjectTypeException
*/
const UnsupportedProjectTypeException = -1762;
/**
* @see UnsupportedArchiveException
*/
const UnsupportedArchiveException = -1763;
/**
* @see ArchiveException
*/
const ArchiveException = -1764;
/**
* @see PackageFetchException
*/
const PackageFetchException = -1765;
/**
* @see InvalidBuildConfigurationException
*/
const InvalidBuildConfigurationException = -1766;
/**
* @see InvalidBuildConfigurationNameException
*/
const InvalidDependencyConfiguration = -1767;
/**
* @see SymlinkException
*/
const SymlinkException = -1768;
/**
* All the exception codes from NCC
*/
@ -322,6 +429,21 @@
self::ComposerNotAvailableException,
self::ComposerException,
self::UserAbortedOperationException,
self::MissingDependencyException
self::MissingDependencyException,
self::HttpException,
self::UnsupportedRemoteSourceTypeException,
self::GitCloneException,
self::GitCheckoutException,
self::GitlabServiceException,
self::GitTagsException,
self::AuthenticationException,
self::NotSupportedException,
self::UnsupportedProjectTypeException,
self::UnsupportedArchiveException,
self::ArchiveException,
self::PackageFetchException,
self::InvalidBuildConfigurationException,
self::InvalidDependencyConfiguration,
self::SymlinkException,
];
}

View file

@ -0,0 +1,31 @@
<?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\Abstracts;
abstract class HttpRequestType
{
const GET = 'GET';
const POST = 'POST';
const PUT = 'PUT';
const DELETE = 'DELETE';
}

View file

@ -0,0 +1,124 @@
<?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\Abstracts;
abstract class HttpStatusCodes
{
const OK = 200;
const CREATED = 201;
const ACCEPTED = 202;
const NO_CONTENT = 204;
const MOVED_PERMANENTLY = 301;
const FOUND = 302;
const SEE_OTHER = 303;
const NOT_MODIFIED = 304;
const TEMPORARY_REDIRECT = 307;
const PERMANENT_REDIRECT = 308;
const BAD_REQUEST = 400;
const UNAUTHORIZED = 401;
const FORBIDDEN = 403;
const NOT_FOUND = 404;
const METHOD_NOT_ALLOWED = 405;
const NOT_ACCEPTABLE = 406;
const REQUEST_TIMEOUT = 408;
const CONFLICT = 409;
const GONE = 410;
const LENGTH_REQUIRED = 411;
const PRECONDITION_FAILED = 412;
const PAYLOAD_TOO_LARGE = 413;
const URI_TOO_LONG = 414;
const UNSUPPORTED_MEDIA_TYPE = 415;
const RANGE_NOT_SATISFIABLE = 416;
const EXPECTATION_FAILED = 417;
const IM_A_TEAPOT = 418;
const MISDIRECTED_REQUEST = 421;
const UNPROCESSABLE_ENTITY = 422;
const LOCKED = 423;
const FAILED_DEPENDENCY = 424;
const UPGRADE_REQUIRED = 426;
const PRECONDITION_REQUIRED = 428;
const TOO_MANY_REQUESTS = 429;
const REQUEST_HEADER_FIELDS_TOO_LARGE = 431;
const UNAVAILABLE_FOR_LEGAL_REASONS = 451;
const INTERNAL_SERVER_ERROR = 500;
const NOT_IMPLEMENTED = 501;
const BAD_GATEWAY = 502;
const SERVICE_UNAVAILABLE = 503;
const GATEWAY_TIMEOUT = 504;
const HTTP_VERSION_NOT_SUPPORTED = 505;
const VARIANT_ALSO_NEGOTIATES = 506;
const INSUFFICIENT_STORAGE = 507;
const LOOP_DETECTED = 508;
const NOT_EXTENDED = 510;
const NETWORK_AUTHENTICATION_REQUIRED = 511;
const All = [
self::OK,
self::CREATED,
self::ACCEPTED,
self::NO_CONTENT,
self::MOVED_PERMANENTLY,
self::FOUND,
self::SEE_OTHER,
self::NOT_MODIFIED,
self::TEMPORARY_REDIRECT,
self::PERMANENT_REDIRECT,
self::BAD_REQUEST,
self::UNAUTHORIZED,
self::FORBIDDEN,
self::NOT_FOUND,
self::METHOD_NOT_ALLOWED,
self::NOT_ACCEPTABLE,
self::REQUEST_TIMEOUT,
self::CONFLICT,
self::GONE,
self::LENGTH_REQUIRED,
self::PRECONDITION_FAILED,
self::PAYLOAD_TOO_LARGE,
self::URI_TOO_LONG,
self::UNSUPPORTED_MEDIA_TYPE,
self::RANGE_NOT_SATISFIABLE,
self::EXPECTATION_FAILED,
self::IM_A_TEAPOT,
self::MISDIRECTED_REQUEST,
self::UNPROCESSABLE_ENTITY,
self::LOCKED,
self::FAILED_DEPENDENCY,
self::UPGRADE_REQUIRED,
self::PRECONDITION_REQUIRED,
self::TOO_MANY_REQUESTS,
self::REQUEST_HEADER_FIELDS_TOO_LARGE,
self::UNAVAILABLE_FOR_LEGAL_REASONS,
self::INTERNAL_SERVER_ERROR,
self::NOT_IMPLEMENTED,
self::BAD_GATEWAY,
self::SERVICE_UNAVAILABLE,
self::GATEWAY_TIMEOUT,
self::HTTP_VERSION_NOT_SUPPORTED,
self::VARIANT_ALSO_NEGOTIATES,
self::INSUFFICIENT_STORAGE,
self::LOOP_DETECTED,
self::NOT_EXTENDED,
self::NETWORK_AUTHENTICATION_REQUIRED
];
}

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class LogLevel
{

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class NccBuildFlags
{
@ -8,5 +28,5 @@
* Indicates if the build is currently unstable and some features may not work correctly
* and can cause errors
*/
const Unstable = 'UNSTABLE';
const Unstable = 'unstable';
}

View file

@ -1,6 +1,26 @@
<?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\Abstracts\Options;
namespace ncc\Abstracts\Options;
abstract class BuildConfigurationValues
{

View file

@ -1,6 +1,26 @@
<?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\Abstracts\Options;
namespace ncc\Abstracts\Options;
abstract class InitializeProjectOptions
{

View file

@ -0,0 +1,40 @@
<?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\Abstracts\Options;
abstract class InstallPackageOptions
{
/**
* Skips the installation of dependencies of the package
*
* @warning This will cause the package to fail to import of
* the dependencies are not met
*/
const SkipDependencies = 'skip_dependencies';
/**
* Reinstall all packages if they are already installed
* Including dependencies if they are being processed.
*/
const Reinstall = 'reinstall';
}

View file

@ -0,0 +1,38 @@
<?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\Abstracts\Options;
abstract class RuntimeImportOptions
{
/**
* Indicates if the import should require PHP's autoload.php file
* for the package (Only applies to PHP packages)
*/
const ImportAutoloader = 'import_autoloader';
/**
* Indicates if the import should require all static files
* for the package (Only applies to PHP packages)
*/
const ImportStaticFiles = 'import_static_files';
}

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class PackageStandardVersions
{

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class PackageStructureVersions
{

View file

@ -0,0 +1,32 @@
<?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\Abstracts;
abstract class ProjectType
{
const Composer = 'composer';
const Ncc = 'ncc';
const Unknown = 'unknown';
}

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
/**
* @author Zi Xing Narrakas

View file

@ -1,16 +0,0 @@
<?php
namespace ncc\Abstracts;
abstract class RemoteAuthenticationType
{
/**
* A combination of a username and password is used for authentication
*/
const UsernamePassword = 'USERNAME_PASSWORD';
/**
* A single private access token is used for authentication
*/
const PrivateAccessToken = 'PRIVATE_ACCESS_TOKEN';
}

View file

@ -1,16 +0,0 @@
<?php
namespace ncc\Abstracts;
abstract class RemoteSource
{
/**
* The remote source is from composer
*/
const Composer = 'composer';
/**
* The remote source is from a git repository
*/
const Git = 'git';
}

View file

@ -0,0 +1,50 @@
<?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\Abstracts;
abstract class RemoteSourceType
{
/**
* A builtin source type is not defined by the user but handled by
* an extension built into NCC
*/
const Builtin = 'builtin';
/**
* A defined source type is defined by the user in the remote sources file
* and handled by an extension designed by passing on the information of
* the source to the extension
*/
const Defined = 'defined';
/**
* Unsupported or invalid source type
*/
const Unknown = 'unknown';
const All = [
self::Builtin,
self::Defined,
self::Unknown
];
}

View file

@ -1,8 +1,51 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class Runners
{
const php = 'php';
const bash = 'bash';
const python = 'python';
const python3 = 'python3';
const python2 = 'python2';
const perl = 'perl';
const lua = 'lua';
const All = [
self::php,
self::bash,
self::python,
self::python3,
self::python2,
self::perl,
self::lua
];
}

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class Scopes
{

View file

@ -1,6 +1,26 @@
<?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\Abstracts\SpecialConstants;
namespace ncc\Abstracts\SpecialConstants;
abstract class AssemblyConstants
{

View file

@ -1,6 +1,26 @@
<?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\Abstracts\SpecialConstants;
namespace ncc\Abstracts\SpecialConstants;
abstract class BuildConstants
{

View file

@ -1,6 +1,26 @@
<?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\Abstracts\SpecialConstants;
namespace ncc\Abstracts\SpecialConstants;
abstract class DateTimeConstants
{

View file

@ -1,6 +1,26 @@
<?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\Abstracts\SpecialConstants;
namespace ncc\Abstracts\SpecialConstants;
abstract class InstallConstants
{

View file

@ -1,8 +1,33 @@
<?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\Abstracts\SpecialConstants;
namespace ncc\Abstracts\SpecialConstants;
abstract class RuntimeConstants
{
const CWD = '%CWD%';
const PID = '%PID%';
const UID = '%UID%';
const GID = '%GID%';
const User = '%USER%';
}

View file

@ -1,12 +0,0 @@
<?php
namespace ncc\Abstracts;
abstract class StringPaddingMethod
{
const LEFT = 'LEFT';
const RIGHT = 'RIGHT';
const BOTH = 'BOTH';
}

View file

@ -1,6 +1,26 @@
<?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\Abstracts;
namespace ncc\Abstracts;
abstract class Versions
{
@ -18,4 +38,9 @@
* The current version of the package lock structure file format
*/
const PackageLockVersion = '1.0.0';
/**
* Generic version of the package structure file format (latest)
*/
const Latest = 'latest';
}

View file

@ -1,14 +1,35 @@
<?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\CLI;
namespace ncc\CLI\Commands;
use Exception;
use ncc\Abstracts\Options\BuildConfigurationValues;
use ncc\Managers\ProjectManager;
use ncc\Objects\CliHelpSection;
use ncc\Utilities\Console;
use ncc\Utilities\Functions;
class BuildMenu
class BuildCommand
{
/**
* Displays the main help menu
@ -103,7 +124,7 @@
new CliHelpSection(['build', '--config'], 'Builds the current project with a specified build configuration')
];
$options_padding = \ncc\Utilities\Functions::detectParametersPadding($options) + 4;
$options_padding = Functions::detectParametersPadding($options) + 4;
Console::out('Usage: ncc build [options]');
Console::out('Options:' . PHP_EOL);

View file

@ -0,0 +1,144 @@
<?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\CLI\Commands;
use Exception;
use ncc\Managers\ExecutionPointerManager;
use ncc\Managers\PackageLockManager;
use ncc\Objects\CliHelpSection;
use ncc\Utilities\Console;
use ncc\Utilities\Functions;
class ExecCommand
{
/**
* Displays the main help menu
*
* @param $args
* @return void
*/
public static function start($args): void
{
$package = $args['package'] ?? null;
$version = $args['exec-version'] ?? 'latest';
$unit_name = $args['exec-unit'] ?? 'main';
$set_args = $args['exec-args'] ?? null;
if($package == null)
{
self::displayOptions();
exit(0);
}
$package_lock_manager = new PackageLockManager();
$execution_pointer_manager = new ExecutionPointerManager();
try
{
$package_entry = $package_lock_manager->getPackageLock()->getPackage($package);
}
catch(Exception $e)
{
Console::outException('Package ' . $package . ' is not installed', $e, 1);
return;
}
try
{
$version_entry = $package_entry->getVersion($version);
}
catch(Exception $e)
{
Console::outException('Version ' . $version . ' is not installed', $e, 1);
return;
}
try
{
$units = $execution_pointer_manager->getUnits($package_entry->Name, $version_entry->Version);
}
catch(Exception $e)
{
Console::outException(sprintf('Cannot load execution units for package \'%s\'', $package), $e, 1);
return;
}
if(!in_array($unit_name, $units))
{
Console::outError(sprintf('Unit \'%s\' is not configured for package \'%s\'', $unit_name, $package), true, 1);
return;
}
$options = [];
if($set_args != null)
{
global $argv;
$args_index = array_search('--exec-args', $argv);
$options = array_slice($argv, $args_index + 1);
}
try
{
exit($execution_pointer_manager->executeUnit($package_entry->Name, $version_entry->Version, $unit_name, $options));
}
catch(Exception $e)
{
Console::outException(sprintf('Cannot execute execution point \'%s\' in package \'%s\'', $unit_name, $package), $e, 1);
return;
}
}
/**
* Displays the main options section
*
* @return void
*/
private static function displayOptions(): void
{
$options = [
new CliHelpSection(['help'], 'Displays this help menu about the value command'),
new CliHelpSection(['exec', '--package'], '(Required) The package to execute'),
new CliHelpSection(['--exec-version'], '(default: latest) The version of the package to execute'),
new CliHelpSection(['--exec-unit'], '(default: main) The unit point of the package to execute'),
new CliHelpSection(['--exec-args'], '(optional) Anything past this point will be passed to the execution unit'),
];
$options_padding = Functions::detectParametersPadding($options) + 4;
Console::out('Usage: ncc exec --package <package> [options] [arguments]');
Console::out('Options:' . PHP_EOL);
foreach($options as $option)
{
Console::out(' ' . $option->toString($options_padding));
}
Console::out(PHP_EOL . 'Arguments:' . PHP_EOL);
Console::out(' <arguments> The arguments to pass to the program');
Console::out(PHP_EOL . 'Example Usage:' . PHP_EOL);
Console::out(' ncc exec --package com.example.program');
Console::out(' ncc exec --package com.example.program --exec-version 1.0.0');
Console::out(' ncc exec --package com.example.program --exec-version 1.0.0 --exec-unit setup');
Console::out(' ncc exec --package com.example.program --exec-args --foo --bar --extra=test');
}
}

View file

@ -1,72 +0,0 @@
<?php
namespace ncc\CLI;
use ncc\Abstracts\Scopes;
use ncc\Exceptions\AccessDeniedException;
use ncc\Objects\CliHelpSection;
use ncc\Utilities\Resolver;
class CredentialMenu
{
/**
* Displays the main help menu
*
* @param $args
* @return void
* @throws AccessDeniedException
*/
public static function start($args): void
{
if(isset($args['add']))
{
self::addCredential($args);
}
self::displayOptions();
exit(0);
}
/**
* @param $args
* @return void
* @throws AccessDeniedException
*/
public static function addCredential($args): void
{
$ResolvedScope = Resolver::resolveScope();
if($ResolvedScope !== Scopes::System)
{
throw new AccessDeniedException('Root permissions are required to manage the vault');
}
print('end' . PHP_EOL);
exit(0);
}
/**
* Displays the main options section
*
* @return void
*/
private static function displayOptions(): void
{
$options = [
new CliHelpSection(['help'], 'Displays this help menu about the value command'),
new CliHelpSection(['add'], 'Adds a new credential to the vault'),
new CliHelpSection(['remove'], 'Adds a new credential to the vault'),
];
$options_padding = \ncc\Utilities\Functions::detectParametersPadding($options) + 4;
print('Usage: ncc vault {command} [options]' . PHP_EOL);
print('Options:' . PHP_EOL);
foreach($options as $option)
{
print(' ' . $option->toString($options_padding) . PHP_EOL);
}
print(PHP_EOL);
}
}

View file

@ -1,9 +1,33 @@
<?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\CLI;
namespace ncc\CLI;
use ncc\Exceptions\AccessDeniedException;
use ncc\Exceptions\FileNotFoundException;
use ncc\Exceptions\IOException;
use ncc\Objects\CliHelpSection;
use ncc\Utilities\Console;
use ncc\Utilities\Functions;
class HelpMenu
{
@ -12,8 +36,11 @@
*
* @param $args
* @return void
* @throws AccessDeniedException
* @throws FileNotFoundException
* @throws IOException
*/
public static function start($args)
public static function start($args): void
{
$basic_ascii = false;
@ -23,7 +50,7 @@
}
// TODO: Make copyright not hard-coded.
print(\ncc\Utilities\Functions::getBanner(NCC_VERSION_BRANCH . ' ' . NCC_VERSION_NUMBER, 'Copyright (c) 2022-2022 Nosial', $basic_ascii) . PHP_EOL);
print(Functions::getBanner(NCC_VERSION_BRANCH . ' ' . NCC_VERSION_NUMBER, 'Copyright (c) 2022-2022 Nosial', $basic_ascii) . PHP_EOL);
Console::out('Usage: ncc COMMAND [options]');
Console::out('Alternative Usage: ncc.php --ncc-cli=COMMAND [options]' . PHP_EOL);
@ -32,7 +59,6 @@
self::displayMainOptions();
self::displayManagementCommands();
self::displayMainCommands();
self::displayExtensions();
}
/**
@ -42,22 +68,15 @@
*/
private static function displayMainOptions(): void
{
$options = [
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(['-D', '--debug'], 'Enables debug mode'),
new CliHelpSection(['-l', '--log-level={debug|info|warn|error|fatal}'], 'Set the logging level', 'info'),
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')
];
$options_padding = \ncc\Utilities\Functions::detectParametersPadding($options) + 4;
Console::out('Options:');
foreach($options as $option)
{
Console::out(' ' . $option->toString($options_padding));
}
]);
}
/**
@ -67,20 +86,14 @@
*/
private static function displayManagementCommands(): void
{
$commands = [
Console::out('Management Commands:');
Console::outHelpSections([
new CliHelpSection(['project'], 'Manages the current project'),
new CliHelpSection(['package'], 'Manages the package system'),
new CliHelpSection(['cache'], 'Manages the system cache'),
new CliHelpSection(['credential'], 'Manages credentials'),
new CliHelpSection(['cred'], 'Manages credentials'),
new CliHelpSection(['config'], 'Changes NCC configuration values'),
];
$commands_padding = \ncc\Utilities\Functions::detectParametersPadding($commands) + 2;
Console::out('Management Commands:');
foreach($commands as $command)
{
Console::out(' ' . $command->toString($commands_padding));
}
new CliHelpSection(['source'], 'Manages remote sources'),
]);
}
/**
@ -90,35 +103,10 @@
*/
private static function displayMainCommands(): void
{
$commands = [
new CliHelpSection(['build'], 'Builds the current project'),
new CliHelpSection(['main'], 'Executes the main entrypoint of a package')
];
$commands_padding = \ncc\Utilities\Functions::detectParametersPadding($commands) + 2;
Console::out('Commands:');
foreach($commands as $command)
{
Console::out(' ' . $command->toString($commands_padding));
}
}
/**
* Displays the main commands section
*
* @return void
*/
private static function displayExtensions(): void
{
$extensions = [
new CliHelpSection(['exphp'], 'The PHP compiler extension')
];
$extensions_padding = \ncc\Utilities\Functions::detectParametersPadding($extensions) + 2;
Console::out('Extensions:');
foreach($extensions as $command)
{
Console::out(' ' . $command->toString($extensions_padding));
}
Console::outHelpSections([
new CliHelpSection(['build'], 'Builds the current project'),
new CliHelpSection(['exec'], 'Executes the main entrypoint of a package')
]);
}
}

View file

@ -1,4 +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.
*
*/
/** @noinspection PhpMissingFieldTypeInspection */
@ -7,11 +27,22 @@
use Exception;
use ncc\Abstracts\LogLevel;
use ncc\Abstracts\NccBuildFlags;
use ncc\CLI\Commands\BuildCommand;
use ncc\CLI\Commands\ExecCommand;
use ncc\CLI\Management\ConfigMenu;
use ncc\CLI\Management\CredentialMenu;
use ncc\CLI\Management\PackageManagerMenu;
use ncc\CLI\Management\ProjectMenu;
use ncc\CLI\Management\SourcesMenu;
use ncc\Exceptions\AccessDeniedException;
use ncc\Exceptions\FileNotFoundException;
use ncc\Exceptions\IOException;
use ncc\Exceptions\RuntimeException;
use ncc\ncc;
use ncc\Utilities\Console;
use ncc\Utilities\Functions;
use ncc\Utilities\Resolver;
use ncc\Utilities\RuntimeCache;
class Main
{
@ -24,12 +55,15 @@
* @var string|null
*/
private static $log_level;
/**
* Executes the main CLI process
*
* @param $argv
* @return void
* @throws RuntimeException
* @throws AccessDeniedException
* @throws IOException
*/
public static function start($argv): void
{
@ -51,8 +85,8 @@
Console::outException('Cannot initialize NCC due to a runtime error.', $e, 1);
}
// Define CLI stuff
define('NCC_CLI_MODE', 1);
register_shutdown_function('ncc\CLI\Main::shutdown');
if(isset(self::$args['l']) || isset(self::$args['log-level']))
{
@ -82,13 +116,13 @@
if(Resolver::checkLogLevel(self::$log_level, LogLevel::Debug))
{
Console::outDebug('Debug logging enabled');
Console::outDebug(sprintf('consts: %s', json_encode(ncc::getConstants(), JSON_UNESCAPED_SLASHES)));
Console::outDebug(sprintf('const: %s', json_encode(ncc::getConstants(), JSON_UNESCAPED_SLASHES)));
Console::outDebug(sprintf('args: %s', json_encode(self::$args, JSON_UNESCAPED_SLASHES)));
}
if(in_array(NccBuildFlags::Unstable, NCC_VERSION_FLAGS))
{
//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');
}
try
@ -97,32 +131,44 @@
{
default:
Console::out('Unknown command ' . strtolower(self::$args['ncc-cli']));
exit(1);
break;
case 'project':
ProjectMenu::start(self::$args);
exit(0);
break;
case 'build':
BuildMenu::start(self::$args);
exit(0);
BuildCommand::start(self::$args);
break;
case 'credential':
case 'exec':
ExecCommand::start(self::$args);
break;
case 'cred':
CredentialMenu::start(self::$args);
exit(0);
break;
case 'package':
PackageManagerMenu::start(self::$args);
exit(0);
break;
case 'config':
ConfigMenu::start(self::$args);
exit(0);
break;
case 'source':
SourcesMenu::start(self::$args);
break;
case 'version':
Console::out(sprintf('NCC version %s (%s)', NCC_VERSION_NUMBER, NCC_VERSION_BRANCH));
break;
case '1':
case 'help':
HelpMenu::start(self::$args);
exit(0);
break;
}
}
catch(Exception $e)
@ -131,14 +177,27 @@
exit(1);
}
exit(0);
}
}
/**
* @return mixed
* @return array
*/
public static function getArgs()
public static function getArgs(): array
{
if (self::$args == null)
{
if(isset($argv))
{
self::$args = Resolver::parseArguments(implode(' ', $argv));
}
else
{
self::$args = [];
}
}
return self::$args;
}
@ -152,4 +211,20 @@
return self::$log_level;
}
/**
* @return void
*/
public static function shutdown(): void
{
try
{
RuntimeCache::clearCache();
Functions::finalizePermissions();
}
catch (Exception $e)
{
Console::outWarning('An error occurred while shutting down NCC, ' . $e->getMessage());
}
}
}

View file

@ -1,6 +1,26 @@
<?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\CLI;
namespace ncc\CLI\Management;
use ncc\Abstracts\Scopes;
use ncc\Exceptions\AccessDeniedException;
@ -83,7 +103,7 @@
{
if(Resolver::resolveScope() !== Scopes::System)
{
Console::outError('Insufficent permissions, cannot modify configuration values', true, 1);
Console::outError('Insufficient permissions, cannot modify configuration values', true, 1);
return;
}

View file

@ -0,0 +1,397 @@
<?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\CLI\Management;
use Exception;
use ncc\Abstracts\Scopes;
use ncc\Exceptions\RuntimeException;
use ncc\Managers\CredentialManager;
use ncc\Objects\CliHelpSection;
use ncc\Objects\Vault\Password\AccessToken;
use ncc\Objects\Vault\Password\UsernamePassword;
use ncc\Utilities\Console;
use ncc\Utilities\Functions;
use ncc\Utilities\Resolver;
class CredentialMenu
{
/**
* Displays the main help menu
*
* @param $args
* @return void
* @noinspection DuplicatedCode
*/
public static function start($args): void
{
if(isset($args['add']))
{
try
{
self::addEntry($args);
}
catch(Exception $e)
{
Console::outException('Error while adding entry.', $e, 1);
}
return;
}
if(isset($args['remove']))
{
try
{
self::removeEntry($args);
}
catch(Exception $e)
{
Console::outException('Cannot remove entry.', $e, 1);
}
return;
}
if(isset($args['list']))
{
try
{
self::listEntries();
}
catch(Exception $e)
{
Console::outException('Cannot list entries.', $e, 1);
}
return;
}
if(isset($args['test']))
{
try
{
self::testEntry($args);
}
catch(Exception $e)
{
Console::outException('Cannot test entry.', $e, 1);
}
return;
}
self::displayOptions();
}
/**
* Tests an entry authentication
*
* @param $args
* @return void
*/
public static function testEntry($args): void
{
$name = $args['name'] ?? $args['alias'] ?? null;
if($name === null)
{
Console::outError('Please specify a name or alias for the entry.', true, 1);
return;
}
$credential_manager = new CredentialManager();
$entry = $credential_manager->getVault()->getEntry($name);
if($entry === null)
{
Console::out('Entry not found.', true, 1);
return;
}
if($entry->isEncrypted())
{
$tries = 0;
while(true)
{
try
{
$password = Console::passwordInput('Password/Secret: ');
if (!$entry->unlock($password))
{
$tries++;
if ($tries >= 3)
{
Console::outError('Too many failed attempts.', true, 1);
return;
}
Console::outError('Invalid password.', true, 1);
}
else
{
Console::out('Authentication successful.');
return;
}
}
catch (RuntimeException $e)
{
Console::outException('Cannot unlock entry.', $e, 1);
return;
}
}
}
else
{
Console::out('Authentication always successful, entry is not encrypted.');
}
}
/**
* Prints the list of entries in the vault
*
* @return void
*/
public static function listEntries(): void
{
$credential_manager = new CredentialManager();
$entries = $credential_manager->getVault()->getEntries();
if(count($entries) === 0)
{
Console::out('No entries found.');
return;
}
Console::out('Entries:');
foreach($entries as $entry)
{
Console::out(sprintf(' - %s (%s)', $entry->getName(), $entry->isEncrypted() ? ' (encrypted)' : ''));
}
Console::out('Total: ' . count($entries));
}
/**
* @param $args
* @return void
*/
public static function addEntry($args): void
{
$ResolvedScope = Resolver::resolveScope();
if($ResolvedScope !== Scopes::System)
Console::outError('Insufficient permissions to add entries');
// Really dumb-proofing this
$name = $args['alias'] ?? $args['name'] ?? null;
$auth_type = $args['auth-type'] ?? $args['auth'] ?? null;
$username = $args['username'] ?? $args['usr'] ?? null;
$password = $args['password'] ?? $args['pwd'] ?? null;
$token = $args['token'] ?? $args['pat'] ?? $args['private-token'] ?? null;
$encrypt = !isset($args['no-encryption']);
if($name === null)
$name = Console::getInput('Enter a name for the entry: ');
if($auth_type === null)
$auth_type = Console::getInput('Enter the authentication type (login or pat): ');
if($auth_type === 'login')
{
if($username === null)
$username = Console::getInput('Username: ');
if($password === null)
$password = Console::passwordInput('Password: ');
}
elseif($auth_type === 'pat')
{
if($token === null)
$token = Console::passwordInput('Token: ');
}
else
{
Console::outError('Invalid authentication type');
}
if($name === null)
{
Console::outError('You must specify a name for the entry (alias, name)', true, 1);
return;
}
if($auth_type === null)
{
Console::outError('You must specify an authentication type for the entry (auth-type, auth)', true, 1);
return;
}
$encrypt = Functions::cbool($encrypt);
switch($auth_type)
{
case 'login':
if($username === null)
{
Console::outError('You must specify a username for the entry (username, usr)', true, 1);
return;
}
if($password === null)
{
Console::outError('You must specify a password for the entry (password, pwd)', true, 1);
return;
}
$pass_object = new UsernamePassword();
$pass_object->setUsername($username);
$pass_object->setPassword($password);
break;
case 'pat':
if($token === null)
{
Console::outError('You must specify a token for the entry (token, pat, private-token)', true, 1);
return;
}
$pass_object = new AccessToken();
$pass_object->setAccessToken($token);
break;
default:
Console::outError('Invalid authentication type specified', true, 1);
return;
}
$credential_manager = new CredentialManager();
if(!$credential_manager->getVault()->addEntry($name, $pass_object, $encrypt))
{
Console::outError('Failed to add entry, entry already exists.', true, 1);
return;
}
try
{
$credential_manager->saveVault();
}
catch(Exception $e)
{
Console::outException('Failed to save vault', $e, 1);
return;
}
Console::out('Successfully added entry', true, 0);
}
/**
* Removes an existing entry from the vault.
*
* @param $args
* @return void
*/
private static function removeEntry($args): void
{
$ResolvedScope = Resolver::resolveScope();
if($ResolvedScope !== Scopes::System)
Console::outError('Insufficient permissions to remove entries');
$name = $args['alias'] ?? $args['name'] ?? null;
if($name === null)
$name = Console::getInput('Enter the name of the entry to remove: ');
$credential_manager = new CredentialManager();
if(!$credential_manager->getVault()->deleteEntry($name))
{
Console::outError('Failed to remove entry, entry does not exist.', true, 1);
return;
}
try
{
$credential_manager->saveVault();
}
catch(Exception $e)
{
Console::outException('Failed to save vault', $e, 1);
return;
}
Console::out('Successfully removed entry', true, 0);
}
/**
* Displays the main options section
*
* @return void
*/
private static function displayOptions(): void
{
Console::out('Usage: ncc cred {command} [options]');
Console::out('Options:');
Console::outHelpSections([
new CliHelpSection(['help'], 'Displays this help menu about the value command'),
new CliHelpSection(['add'], 'Adds a new entry to the vault (See below)'),
new CliHelpSection(['remove', '--name'], 'Removes an entry from the vault'),
new CliHelpSection(['list'], 'Lists all entries in the vault'),
]);
Console::out((string)null);
Console::out('If you are adding a new entry, you can run the add command in interactive mode');
Console::out('or you can specify the options below' . PHP_EOL);
Console::out('Add Options:');
Console::outHelpSections([
new CliHelpSection(['--name'], 'The name of the entry'),
new CliHelpSection(['--auth-type', '--auth'], 'The type of authentication (login, pat)'),
new CliHelpSection(['--no-encryption'], 'Omit encryption to the entry (By default it\'s encrypted)', true),
]);
Console::out(' login authentication type options:');
Console::outHelpSections([
new CliHelpSection(['--username', '--usr'], 'The username for the entry'),
new CliHelpSection(['--password', '--pwd'], 'The password for the entry'),
]);
Console::out(' pat authentication type options:');
Console::outHelpSections([
new CliHelpSection(['--token', '--pat',], 'The private access token for the entry', true),
]);
Console::out('Authentication Types:');
Console::out(' login');
Console::out(' pat' . PHP_EOL);
Console::out('Examples:');
Console::out(' ncc cred add --alias "My Alias" --auth-type login --username "myusername" --password "mypassword"');
Console::out(' ncc cred add --alias "My Alias" --auth-type pat --token "mytoken" --no-encryption');
Console::out(' ncc cred remove --alias "My Alias"');
}
}

View file

@ -1,15 +1,36 @@
<?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\CLI;
namespace ncc\CLI\Management;
use Exception;
use ncc\Abstracts\ConsoleColors;
use ncc\Abstracts\RemoteSource;
use ncc\Abstracts\Options\InstallPackageOptions;
use ncc\Abstracts\Scopes;
use ncc\Classes\ComposerExtension\ComposerSource;
use ncc\Exceptions\FileNotFoundException;
use ncc\Exceptions\PackageLockException;
use ncc\Exceptions\RuntimeException;
use ncc\Exceptions\VersionNotFoundException;
use ncc\Managers\CredentialManager;
use ncc\Managers\PackageManager;
use ncc\Objects\CliHelpSection;
use ncc\Objects\Package;
@ -84,6 +105,20 @@
}
}
if(isset($args['sdc']))
{
try
{
self::semiDecompile($args);
return;
}
catch(Exception $e)
{
Console::outException('List Failed', $e, 1);
return;
}
}
self::displayOptions();
exit(0);
}
@ -116,6 +151,91 @@
}
}
/**
* Semi-Decompiles a package and prints it to the console
*
* @param $args
* @return void
* @throws FileNotFoundException
*/
private static function semiDecompile($args): void
{
$path = ($args['package'] ?? $args['p']);
if(!file_exists($path) || !is_file($path) || !is_readable($path))
throw new FileNotFoundException('The specified file \'' . $path .' \' does not exist or is not readable.');
try
{
$package = Package::load($path);
}
catch(Exception $e)
{
Console::outException('Error while loading package', $e, 1);
return;
}
Console::out('magic_bytes: ' . json_encode(($package->MagicBytes?->toArray() ?? []), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
Console::out('header: ' . json_encode(($package->Header?->toArray() ?? []), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
Console::out('assembly: ' . json_encode(($package->Assembly?->toArray() ?? []), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
Console::out('main: ' . ($package->MainExecutionPolicy ?? 'N/A'));
Console::out('installer: ' . ($package->Installer?->toArray() ?? 'N/A'));
if($package->Dependencies !== null && count($package->Dependencies) > 0)
{
Console::out('dependencies:');
foreach($package->Dependencies as $dependency)
{
Console::out(' - ' . json_encode($dependency->toArray(), JSON_UNESCAPED_SLASHES));
}
}
else
{
Console::out('dependencies: N/A');
}
if($package->ExecutionUnits !== null && count($package->ExecutionUnits) > 0)
{
Console::out('execution_units:');
foreach($package->ExecutionUnits as $unit)
{
Console::out(' - ' . json_encode($unit->toArray(), JSON_UNESCAPED_SLASHES));
}
}
else
{
Console::out('execution_units: N/A');
}
if($package->Resources !== null && count($package->Resources) > 0)
{
Console::out('resources:');
foreach($package->Resources as $resource)
{
Console::out(' - ' . sprintf('%s - (%s)', $resource->Name, Functions::b2u(strlen($resource->Data))));
}
}
else
{
Console::out('resources: N/A');
}
if($package->Components !== null && count($package->Components) > 0)
{
Console::out('components:');
foreach($package->Components as $component)
{
Console::out(' - ' . sprintf('#%s %s - %s', $component->DataType, $component->Name, json_encode(($component->Flags ?? []), JSON_UNESCAPED_SLASHES)));
}
}
else
{
Console::out('components: N/A');
}
exit(0);
}
/**
* Displays all installed packages
*
@ -156,6 +276,7 @@
$package_version = $package_manager->getPackageVersion($package, $version);
if($package_version == null)
continue;
Console::out(sprintf('%s=%s (%s)',
Console::formatColor($package, ConsoleColors::LightGreen),
Console::formatColor($version, ConsoleColors::LightMagenta),
@ -165,9 +286,10 @@
catch(Exception $e)
{
unset($e);
Console::out(sprintf('%s=%s',
Console::out(sprintf('%s=%s (%s)',
Console::formatColor($package, ConsoleColors::LightGreen),
Console::formatColor($version, ConsoleColors::LightMagenta)
Console::formatColor($version, ConsoleColors::LightMagenta),
Console::formatColor('N/A', ConsoleColors::LightRed)
));
}
}
@ -191,33 +313,66 @@
return;
}
$path = $package;
$parsed_source = new RemotePackageInput($path);
if($parsed_source->Vendor !== null && $parsed_source->Package !== null)
// check if authentication is provided
$entry_arg = ($args['auth'] ?? null);
$credential_manager = new CredentialManager();
if($entry_arg !== null)
{
if($parsed_source->Source == null)
$credential = $credential_manager->getVault()->getEntry($entry_arg);
if($credential == null)
{
Console::outError('No source specified', true, 1);
Console::outError(sprintf('Unknown credential entry \'%s\'', $entry_arg), true, 1);
return;
}
}
else
{
$credential = null;
}
switch($parsed_source->Source)
if($credential !== null && !$credential->isCurrentlyDecrypted())
{
// Try 3 times
for($i = 0; $i < 3; $i++)
{
case RemoteSource::Composer:
try
{
$path = ComposerSource::fetch($parsed_source);
break;
}
catch(Exception $e)
{
Console::outException(sprintf('Failed to fetch package %s', $package), $e, 1);
return;
}
default:
Console::outError('Cannot install package from source: ' . $parsed_source->Source, true, 1);
try
{
$credential->unlock(Console::passwordInput(sprintf('Enter Password for %s: ', $credential->getName())));
}
catch (RuntimeException $e)
{
Console::outException(sprintf('Failed to unlock credential %s', $credential->getName()), $e, 1);
return;
}
if($credential->isCurrentlyDecrypted())
break;
Console::outWarning(sprintf('Invalid password, %d attempts remaining', 2 - $i));
}
if(!$credential->isCurrentlyDecrypted())
{
Console::outError('Failed to unlock credential', true, 1);
return;
}
}
$path = $package;
$parsed_source = new RemotePackageInput($path);
if($parsed_source->Vendor !== null && $parsed_source->Package !== null && $parsed_source->Source !== null)
{
try
{
$path = $package_manager->fetchFromSource($parsed_source->toString(), $credential);
}
catch (Exception $e)
{
Console::outException('Failed to fetch package from source', $e, 1);
return;
}
}
@ -230,6 +385,18 @@
$user_confirmation = (bool)($args['y'] ?? $args['Y']);
}
$installer_options = [];
if((Functions::cbool($args['skip-dependencies'] ?? false)))
{
$installer_options[] = InstallPackageOptions::SkipDependencies;
}
if(Functions::cbool($args['reinstall'] ?? false))
{
$installer_options[] = InstallPackageOptions::Reinstall;
}
try
{
$package = Package::load($path);
@ -261,38 +428,39 @@
Console::out(' Trademark: ' . Console::formatColor($package->Assembly->Trademark, ConsoleColors::LightGreen));
Console::out((string)null);
if(count($package->Dependencies) > 0)
if(count($package->Dependencies) > 0 && !in_array(InstallPackageOptions::Reinstall, $installer_options))
{
$dependencies = [];
foreach($package->Dependencies as $dependency)
{
$require_dependency = true;
$require_dependency = false;
try
{
$dependency_package = $package_manager->getPackage($dependency->Name);
}
catch (PackageLockException $e)
{
unset($e);
$dependency_package = null;
}
if($dependency_package !== null)
if(!in_array(InstallPackageOptions::SkipDependencies, $installer_options))
{
try
{
$dependency_version = $dependency_package->getVersion($dependency->Version);
$dependency_package = $package_manager->getPackage($dependency->Name);
}
catch (VersionNotFoundException $e)
catch (PackageLockException $e)
{
unset($e);
$dependency_version = null;
$dependency_package = null;
}
if($dependency_version !== null)
if($dependency_package !== null)
{
$require_dependency = false;
try
{
$dependency_version = $dependency_package->getVersion($dependency->Version);
}
catch (VersionNotFoundException $e)
{
unset($e);
$dependency_version = null;
}
if($dependency_version == null)
$require_dependency = true;
}
}
@ -305,8 +473,11 @@
}
}
Console::out('The following dependencies will be installed:');
Console::out(sprintf('%s', implode(PHP_EOL, $dependencies)));
if($dependencies !== null && count($dependencies) > 0)
{
Console::out('The package requires the following dependencies:');
Console::out(sprintf('%s', implode(PHP_EOL, $dependencies)));
}
}
Console::out(sprintf('Extension: %s',
@ -326,11 +497,13 @@
if(!$user_confirmation)
$user_confirmation = Console::getBooleanInput(sprintf('Do you want to install %s', $package->Assembly->Package));
if($user_confirmation)
{
try
{
$package_manager->install($path);
$package_manager->install($path, $credential, $installer_options);
Console::out(sprintf('Package %s installed successfully', $package->Assembly->Package));
}
catch(Exception $e)
@ -382,7 +555,6 @@
$version_entry = null;
if($version_entry !== null && $package_entry !== null)
/** @noinspection PhpUnhandledExceptionInspection */
/** @noinspection PhpRedundantOptionalArgumentInspection */
$version_entry = $package_entry->getVersion($version_entry, false);
@ -490,9 +662,12 @@
new CliHelpSection(['list'], 'Lists all installed packages on the system'),
new CliHelpSection(['install', '--package', '-p'], 'Installs a specified NCC package'),
new CliHelpSection(['install', '--package', '-p', '--version', '-v'], 'Installs a specified NCC package version'),
new CliHelpSection(['install', '-p', '--skip-dependencies'], 'Installs a specified NCC package but skips the installation of dependencies'),
new CliHelpSection(['install', '-p', '--reinstall'], 'Installs a specified NCC package, reinstall if already installed'),
new CliHelpSection(['uninstall', '--package', '-p'], 'Uninstalls a specified NCC package'),
new CliHelpSection(['uninstall', '--package', '-p', '--version', '-v'], 'Uninstalls a specified NCC package version'),
new CliHelpSection(['uninstall-all'], 'Uninstalls all packages'),
new CliHelpSection(['sdc', '--package', '-p'], '(Debug) Semi-decompiles a specified NCC package and prints the result to the console'),
];
$options_padding = Functions::detectParametersPadding($options) + 4;

View file

@ -1,18 +1,45 @@
<?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\CLI;
namespace ncc\CLI\Management;
use Exception;
use ncc\Abstracts\CompilerExtensionDefaultVersions;
use ncc\Abstracts\CompilerExtensions;
use ncc\Abstracts\CompilerExtensionSupportedVersions;
use ncc\Exceptions\AccessDeniedException;
use ncc\Exceptions\DirectoryNotFoundException;
use ncc\Exceptions\FileNotFoundException;
use ncc\Exceptions\InvalidPackageNameException;
use ncc\Exceptions\InvalidProjectNameException;
use ncc\Exceptions\IOException;
use ncc\Exceptions\MalformedJsonException;
use ncc\Exceptions\ProjectAlreadyExistsException;
use ncc\Exceptions\ProjectConfigurationNotFoundException;
use ncc\Managers\ProjectManager;
use ncc\Objects\CliHelpSection;
use ncc\Objects\ProjectConfiguration\Compiler;
use ncc\Utilities\Console;
use ncc\Utilities\Functions;
class ProjectMenu
{
@ -21,6 +48,12 @@
*
* @param $args
* @return void
* @throws AccessDeniedException
* @throws DirectoryNotFoundException
* @throws FileNotFoundException
* @throws IOException
* @throws MalformedJsonException
* @throws ProjectConfigurationNotFoundException
*/
public static function start($args): void
{
@ -30,13 +63,17 @@
}
self::displayOptions();
exit(0);
}
/**
* @param $args
* @return void
* @throws AccessDeniedException
* @throws DirectoryNotFoundException
* @throws FileNotFoundException
* @throws IOException
* @throws MalformedJsonException
* @throws ProjectConfigurationNotFoundException
*/
public static function createProject($args): void
{
@ -64,6 +101,7 @@
else
{
Console::outError('The selected source directory \'' . $full_path . '\' was not found or is not a directory', true, 1);
return;
}
}
else
@ -72,7 +110,7 @@
}
// Remove basename from real_src
$real_src = \ncc\Utilities\Functions::removeBasename($real_src, $current_directory);
$real_src = Functions::removeBasename($real_src, $current_directory);
// Fetch the rest of the information needed for the project
//$compiler_extension = Console::getOptionInput($args, 'ce', 'Compiler Extension (php, java): ');
@ -221,7 +259,7 @@
new CliHelpSection(['create-makefile'], 'Generates a Makefile for the project'),
];
$options_padding = \ncc\Utilities\Functions::detectParametersPadding($options) + 4;
$options_padding = Functions::detectParametersPadding($options) + 4;
Console::out('Usage: ncc project {command} [options]');
Console::out('Options:' . PHP_EOL);

View file

@ -0,0 +1,240 @@
<?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\CLI\Management;
use Exception;
use ncc\Abstracts\Scopes;
use ncc\Exceptions\IOException;
use ncc\Managers\RemoteSourcesManager;
use ncc\Objects\CliHelpSection;
use ncc\Objects\DefinedRemoteSource;
use ncc\Utilities\Console;
use ncc\Utilities\Functions;
use ncc\Utilities\Resolver;
class SourcesMenu
{
/**
* Displays the main help menu
*
* @param $args
* @return void
*/
public static function start($args): void
{
if(isset($args['add']))
{
try
{
self::addEntry($args);
}
catch(Exception $e)
{
Console::outException('Error while adding entry.', $e, 1);
}
return;
}
if(isset($args['remove']))
{
try
{
self::removeEntry($args);
}
catch(Exception $e)
{
Console::outException('Cannot remove entry.', $e, 1);
}
return;
}
if(isset($args['list']))
{
try
{
self::listEntries();
}
catch(Exception $e)
{
Console::outException('Cannot list entries.', $e, 1);
}
return;
}
self::displayOptions();
}
/**
* @return void
*/
public static function listEntries(): void
{
$source_manager = new RemoteSourcesManager();
$sources = $source_manager->getSources();
if(count($sources) == 0)
{
Console::out('No remote sources defined.', 1);
return;
}
Console::out('Remote sources:', 1);
foreach($sources as $source)
{
Console::out(' - ' . $source->Name . ' (' . $source->Host . ')', 1);
}
Console::out('Total: ' . count($sources), 1);
}
/**
* @param $args
* @return void
*/
public static function addEntry($args): void
{
if(Resolver::resolveScope() !== Scopes::System)
{
Console::outError('Insufficient permissions to add entry.', true, 1);
return;
}
$name = $args['name'] ?? null;
$type = $args['type'] ?? null;
$host = $args['host'] ?? null;
$ssl = $args['ssl'] ?? null;
if($name == null)
{
Console::outError(sprintf('Missing required argument \'%s\'.', 'name'), true, 1);
return;
}
if($type == null)
{
Console::outError(sprintf('Missing required argument \'%s\'.', 'type'), true, 1);
return;
}
if($host == null)
{
Console::outError(sprintf('Missing required argument \'%s\'.', 'host'), true, 1);
return;
}
if($ssl !== null)
{
$ssl = Functions::cbool($ssl);
}
$source_manager = new RemoteSourcesManager();
$source = new DefinedRemoteSource();
$source->Name = $name;
$source->Type = $type;
$source->Host = $host;
$source->SSL = $ssl;
if(!$source_manager->addRemoteSource($source))
{
Console::outError(sprintf('Cannot add entry \'%s\', it already exists', $name), true, 1);
return;
}
try
{
$source_manager->save();
}
catch (IOException $e)
{
Console::outException('Cannot save remote sources file.', $e, 1);
return;
}
Console::out(sprintf('Entry \'%s\' added successfully.', $name));
}
/**
* Removes an existing entry from the vault.
*
* @param $args
* @return void
*/
private static function removeEntry($args): void
{
$ResolvedScope = Resolver::resolveScope();
if($ResolvedScope !== Scopes::System)
Console::outError('Insufficient permissions to remove entries');
$name = $args['name'] ?? null;
if($name == null)
{
Console::outError(sprintf('Missing required argument \'%s\'.', 'name'), true, 1);
return;
}
$source_manager = new RemoteSourcesManager();
if(!$source_manager->deleteRemoteSource($name))
{
Console::outError(sprintf('Cannot remove entry \'%s\', it does not exist', $name), true, 1);
return;
}
try
{
$source_manager->save();
}
catch (IOException $e)
{
Console::outException('Cannot save remote sources file.', $e, 1);
return;
}
Console::out(sprintf('Entry \'%s\' removed successfully.', $name));
}
/**
* Displays the main options section
*
* @return void
*/
private static function displayOptions(): void
{
Console::out('Usage: ncc sources {command} [options]');
Console::out('Options:');
Console::outHelpSections([
new CliHelpSection(['help'], 'Displays this help menu about the sources command'),
new CliHelpSection(['add'], 'Adds a new entry to the list of remote sources (See below)'),
new CliHelpSection(['remove', '--name'], 'Removes an entry from the list'),
new CliHelpSection(['list'], 'Lists all entries defined as remote sources'),
]);
Console::out((string)null);
}
}

View file

@ -1,59 +0,0 @@
<?php
namespace ncc\CLI;
use ncc\Objects\CliHelpSection;
use ncc\Utilities\Console;
class PhpMenu
{
/**
* Displays the main help menu
*
* @param $args
* @return void
*/
public static function start($args): void
{
if(isset($args['create']))
{
self::createProject($args);
}
self::displayOptions();
exit(0);
}
/**
* Generates a new Autoloader file for the project
*
* @param $args
* @return void
*/
private static function generateAutoload($args): void
{
}
/**
* Displays the main options section
*
* @return void
*/
private static function displayOptions(): void
{
$options = [
new CliHelpSection(['help'], 'Displays this help menu about the PHP command'),
new CliHelpSection(['build', '--autoload'], 'Builds a new Autoload file for the project (Development purposes only)')
];
$options_padding = \ncc\Utilities\Functions::detectParametersPadding($options) + 4;
Console::out('Usage: ncc php {command} [options]');
Console::out('Options:' . PHP_EOL);
foreach($options as $option)
{
Console::out(' ' . $option->toString($options_padding));
}
}
}

View file

@ -0,0 +1,56 @@
<?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\Classes\BashExtension;
use ncc\Exceptions\FileNotFoundException;
use ncc\Interfaces\RunnerInterface;
use ncc\Objects\Package\ExecutionUnit;
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
use ncc\Utilities\IO;
class BashRunner implements RunnerInterface
{
/**
* @inheritDoc
*/
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
{
$execution_unit = new ExecutionUnit();
if(!file_exists($path) && !is_file($path))
throw new FileNotFoundException($path);
$policy->Execute->Target = null;
$execution_unit->ExecutionPolicy = $policy;
$execution_unit->Data = IO::fread($path);
return $execution_unit;
}
/**
* @inheritDoc
*/
public static function getFileExtension(): string
{
return '.bash';
}
}

View file

@ -1,6 +1,26 @@
<?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\Classes\ComposerExtension;
namespace ncc\Classes\ComposerExtension;
use Exception;
use FilesystemIterator;
@ -28,10 +48,11 @@
use ncc\Exceptions\ProjectConfigurationNotFoundException;
use ncc\Exceptions\RuntimeException;
use ncc\Exceptions\UnsupportedCompilerExtensionException;
use ncc\Exceptions\UnsupportedRunnerException;
use ncc\Exceptions\UserAbortedOperationException;
use ncc\Interfaces\RemoteSourceInterface;
use ncc\Interfaces\ServiceSourceInterface;
use ncc\Managers\ProjectManager;
use ncc\ncc;
use ncc\Objects\ComposerJson;
use ncc\Objects\ComposerLock;
use ncc\Objects\ProjectConfiguration;
use ncc\Objects\RemotePackageInput;
@ -47,7 +68,7 @@
use ncc\Utilities\RuntimeCache;
use SplFileInfo;
class ComposerSource implements RemoteSourceInterface
class ComposerSourceBuiltin implements ServiceSourceInterface
{
/**
* Attempts to acquire the package from the composer repository and
@ -77,7 +98,6 @@
* @throws ProjectConfigurationNotFoundException
* @throws RuntimeException
* @throws UnsupportedCompilerExtensionException
* @throws UnsupportedRunnerException
* @throws UserAbortedOperationException
*/
public static function fetch(RemotePackageInput $packageInput): string
@ -95,6 +115,70 @@
throw new RuntimeException(sprintf('Could not find package %s in the compiled packages', $packageInput->toStandard()));
}
/**
* Works with a local composer.json file and attempts to compile the required packages
* and their dependencies, returns the path to the compiled package.
*
* @param string $path
* @return string
* @throws AccessDeniedException
* @throws BuildConfigurationNotFoundException
* @throws BuildException
* @throws ComposerDisabledException
* @throws ComposerException
* @throws ComposerNotAvailableException
* @throws DirectoryNotFoundException
* @throws FileNotFoundException
* @throws IOException
* @throws InternalComposerNotAvailableException
* @throws MalformedJsonException
* @throws PackageNotFoundException
* @throws PackagePreparationFailedException
* @throws ProjectConfigurationNotFoundException
* @throws UnsupportedCompilerExtensionException
* @throws UserAbortedOperationException
*/
public static function fromLocal(string $path): string
{
// Check if the file composer.json exists
if (!file_exists($path . DIRECTORY_SEPARATOR . 'composer.json'))
throw new FileNotFoundException(sprintf('File "%s" not found', $path . DIRECTORY_SEPARATOR . 'composer.json'));
// Execute composer with options
$options = self::getOptions();
$composer_exec = self::getComposerPath();
$process = new Process([$composer_exec, 'install']);
self::prepareProcess($process, $path, $options);
Console::outDebug(sprintf('executing %s', $process->getCommandLine()));
$process->run(function ($type, $buffer) {
Console::out($buffer, false);
});
if (!$process->isSuccessful())
throw new ComposerException($process->getErrorOutput());
$filesystem = new Filesystem();
if($filesystem->exists($path . DIRECTORY_SEPARATOR . 'build'))
$filesystem->remove($path . DIRECTORY_SEPARATOR . 'build');
$filesystem->mkdir($path . DIRECTORY_SEPARATOR . 'build');
// Compile dependencies
self::compilePackages($path . DIRECTORY_SEPARATOR . 'composer.lock');
$composer_lock = Functions::loadJson(IO::fread($path . DIRECTORY_SEPARATOR . 'composer.lock'), Functions::FORCE_ARRAY);
$version_map = self::getVersionMap(ComposerLock::fromArray($composer_lock));
// Finally convert the main package's composer.json to package.json and compile it
ComposerSourceBuiltin::convertProject($path, $version_map);
$project_manager = new ProjectManager($path);
$project_manager->load();
$built_package = $project_manager->build();
RuntimeCache::setFileAsTemporary($built_package);
return $built_package;
}
/**
* @param string $composer_lock_path
* @return array
@ -109,7 +193,6 @@
* @throws PackagePreparationFailedException
* @throws ProjectConfigurationNotFoundException
* @throws UnsupportedCompilerExtensionException
* @throws UnsupportedRunnerException
*/
private static function compilePackages(string $composer_lock_path): array
{
@ -129,108 +212,19 @@
}
$filesystem->mkdir($base_dir . DIRECTORY_SEPARATOR . 'build');
$version_map = self::getVersionMap($composer_lock);
foreach ($composer_lock->Packages as $package)
{
$package_path = $base_dir . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $package->Name;
// Generate the package configuration
$project_configuration = ComposerSource::generateProjectConfiguration($package->Name, $composer_lock);
// Process the source files
if ($package->Autoload !== null)
{
$source_directory = $package_path . DIRECTORY_SEPARATOR . '.src';
if ($filesystem->exists($source_directory))
{
$filesystem->remove($source_directory);
}
$filesystem->mkdir($source_directory);
$source_directories = [];
$static_files = [];
// Load the composer lock file
$composer_package = $composer_lock->getPackage($package->Name);
if ($composer_package == null)
throw new PackageNotFoundException(sprintf('Package "%s" not found in composer lock file', $package->Name));
// TODO: Implement static files handling
// Extract all the source directories
if ($package->Autoload->Psr4 !== null && count($package->Autoload->Psr4) > 0)
{
Console::outVerbose('Extracting PSR-4 source directories');
foreach ($package->Autoload->Psr4 as $namespace_pointer)
{
if ($namespace_pointer->Path !== null && !in_array($namespace_pointer->Path, $source_directories))
{
$source_directories[] = $package_path . DIRECTORY_SEPARATOR . $namespace_pointer->Path;
}
}
}
if ($package->Autoload->Psr0 !== null && count($package->Autoload->Psr0) > 0)
{
Console::outVerbose('Extracting PSR-0 source directories');
foreach ($package->Autoload->Psr0 as $namespace_pointer)
{
if ($namespace_pointer->Path !== null && !in_array($namespace_pointer->Path, $source_directories))
{
$source_directories[] = $package_path . DIRECTORY_SEPARATOR . $namespace_pointer->Path;
}
}
}
if ($package->Autoload->Files !== null && count($package->Autoload->Files) > 0)
{
Console::outVerbose('Extracting static files');
foreach ($package->Autoload->Files as $file)
{
$static_files[] = $package_path . DIRECTORY_SEPARATOR . $file;
}
}
Console::outDebug(sprintf('source directories: %s', implode(', ', $source_directories)));
// First scan the project files and create a file struct.
$DirectoryScanner = new DirectoryScanner();
// TODO: Implement exclude-class handling
try
{
$DirectoryScanner->unsetFlag(FilesystemIterator::FOLLOW_SYMLINKS);
}
catch (Exception $e)
{
throw new PackagePreparationFailedException('Cannot unset flag \'FOLLOW_SYMLINKS\' in DirectoryScanner, ' . $e->getMessage(), $e);
}
// Include file components that can be compiled
$DirectoryScanner->setIncludes(ComponentFileExtensions::Php);
foreach ($source_directories as $directory)
{
/** @var SplFileInfo $item */
/** @noinspection PhpRedundantOptionalArgumentInspection */
foreach ($DirectoryScanner($directory, True) as $item)
{
if (is_dir($item->getPathName()))
continue;
$parsed_path = str_ireplace($package_path . DIRECTORY_SEPARATOR, '', $item->getPathName());
Console::outDebug(sprintf('copying file %s for package %s', $parsed_path, $package->Name));
$filesystem->copy($item->getPathName(), $source_directory . DIRECTORY_SEPARATOR . $parsed_path);
}
}
if (count($static_files) > 0)
{
$project_configuration->Project->Options['static_files'] = $static_files;
$parsed_path = str_ireplace($package_path . DIRECTORY_SEPARATOR, '', $item->getPathName());
if (!$filesystem->exists($source_directory . DIRECTORY_SEPARATOR . $parsed_path))
{
Console::outDebug(sprintf('copying file %s for package %s', $parsed_path, $package->Name));
$filesystem->copy($item->getPathName(), $source_directory . DIRECTORY_SEPARATOR . $parsed_path);
}
}
$project_configuration->toFile($package_path . DIRECTORY_SEPARATOR . 'project.json');
}
// Convert it to a NCC project configuration
$project_configuration = self::convertProject($package_path, $version_map, $composer_package);
// Load the project
$project_manager = new ProjectManager($package_path);
@ -238,15 +232,31 @@
$built_package = $project_manager->build();
// Copy the project to the build directory
$out_path = $base_dir . DIRECTORY_SEPARATOR . 'build' . DIRECTORY_SEPARATOR . sprintf('%s=%s.ncc', $project_configuration->Assembly->Package, $project_configuration->Assembly->Version);
$out_path = $base_dir . DIRECTORY_SEPARATOR . 'build' . DIRECTORY_SEPARATOR . sprintf('%s.ncc', $project_configuration->Assembly->Package);
$filesystem->copy($built_package, $out_path);
$filesystem->remove($built_package);
$built_packages[$project_configuration->Assembly->Package] = $out_path;
}
return $built_packages;
}
/**
* Returns array of versions from the ComposerLock file
*
* @param ComposerLock $composerLock
* @return array
*/
private static function getVersionMap(ComposerLock $composerLock): array
{
$version_map = [];
foreach($composerLock->Packages as $package)
{
$version_map[$package->Name] = $package->Version;
}
return $version_map;
}
/**
* Converts a composer package name to a valid package name
*
@ -271,22 +281,33 @@
return null;
}
/**
* Returns a valid version from a version map
*
* @param string $package_name
* @param array $version_map
* @return string
*/
private static function versionMap(string $package_name, array $version_map): string
{
if (array_key_exists($package_name, $version_map))
{
return Functions::convertToSemVer($version_map[$package_name]);
}
return '1.0.0';
}
/**
* Generates a project configuration from a package selection
* from the composer.lock file
*
* @param string $package_name
* @param ComposerLock $composer_lock
* @param ComposerJson $composer_package
* @param array $version_map
* @return ProjectConfiguration
* @throws PackageNotFoundException
*/
private static function generateProjectConfiguration(string $package_name, ComposerLock $composer_lock): ProjectConfiguration
private static function generateProjectConfiguration(ComposerJson $composer_package, array $version_map): ProjectConfiguration
{
// Load the composer lock file
$composer_package = $composer_lock->getPackage($package_name);
if ($composer_package == null)
throw new PackageNotFoundException(sprintf('Package "%s" not found in composer lock file', $package_name));
// Generate a new project configuration object
$project_configuration = new ProjectConfiguration();
@ -294,37 +315,41 @@
$project_configuration->Assembly->Name = $composer_package->Name;
if (isset($composer_package->Description))
$project_configuration->Assembly->Description = $composer_package->Description;
if (isset($composer_package->Version))
$project_configuration->Assembly->Version = Functions::parseVersion($composer_package->Version);
if(isset($version_map[$composer_package->Name]))
$project_configuration->Assembly->Version = self::versionMap($composer_package->Name, $version_map);
if($project_configuration->Assembly->Version == null || $project_configuration->Assembly->Version == '')
$project_configuration->Assembly->Version = '1.0.0';
$project_configuration->Assembly->UUID = Uuid::v1()->toRfc4122();
$project_configuration->Assembly->Package = self::toPackageName($package_name);
$project_configuration->Assembly->Package = self::toPackageName($composer_package->Name);
// Add the update source
$project_configuration->Project->UpdateSource = new ProjectConfiguration\UpdateSource();
$project_configuration->Project->UpdateSource->Source = sprintf('%s@composer', str_ireplace('\\', '/', $composer_package->Name));
$project_configuration->Project->UpdateSource->Repository = null;
// Process the dependencies
foreach ($composer_package->Require as $item)
if($composer_package->Require !== null && count($composer_package->Require) > 0)
{
$package_name = self::toPackageName($item->PackageName);
$package_version = $composer_lock->getPackage($item->PackageName)?->Version;
if ($package_version == null)
foreach ($composer_package->Require as $item)
{
$package_version = '1.0.0';
// Check if the dependency is already in the project configuration
$package_name = self::toPackageName($item->PackageName);
if ($package_name == null)
continue;
$dependency = new ProjectConfiguration\Dependency();
$dependency->Name = $package_name;
$dependency->SourceType = DependencySourceType::Local;
$dependency->Version = self::versionMap($item->PackageName, $version_map);
$dependency->Source = $package_name . '.ncc';
$project_configuration->Build->addDependency($dependency);
}
else
{
$package_version = Functions::parseVersion($package_version);
}
if ($package_name == null)
continue;
$dependency = new ProjectConfiguration\Dependency();
$dependency->Name = $package_name;
$dependency->SourceType = DependencySourceType::Local;
$dependency->Version = $package_version;
$dependency->Source = $package_name . '=' . $dependency->Version . '.ncc';
$project_configuration->Build->Dependencies[] = $dependency;
}
// Create a build configuration
$build_configuration = new ProjectConfiguration\BuildConfiguration();
$build_configuration = new ProjectConfiguration\Build\BuildConfiguration();
$build_configuration->Name = 'default';
$build_configuration->OutputPath = 'build';
@ -341,22 +366,6 @@
return $project_configuration;
}
/**
* Extracts a version if available from the input
*
* @param string $input
* @return string|null
*/
private static function extractVersion(string $input): ?string
{
if (stripos($input, ':'))
{
return explode(':', $input)[1];
}
return null;
}
/**
* Gets the applicable options configured for composer
*
@ -437,7 +446,6 @@
* @param string $vendor
* @param string $package
* @param string|null $version
* @param array $options
* @return string
* @throws AccessDeniedException
* @throws ComposerDisabledException
@ -449,13 +457,15 @@
* @throws InvalidScopeException
* @throws UserAbortedOperationException
*/
private static function require(string $vendor, string $package, ?string $version = null, array $options = []): string
private static function require(string $vendor, string $package, ?string $version = null): string
{
if (Resolver::resolveScope() !== Scopes::System)
throw new AccessDeniedException('Insufficient permissions to require');
if ($version == null)
$version = '*';
if($version == 'latest')
$version = '*';
$tpl_file = __DIR__ . DIRECTORY_SEPARATOR . 'composer.jtpl';
if (!file_exists($tpl_file))
@ -482,29 +492,11 @@
// Execute composer with options
$options = self::getOptions();
$process = new Process(array_merge([$composer_exec, 'require'], $options));
$process->setWorkingDirectory($tmp_dir);
// Check if scripts are enabled while running as root
if (!in_array('--no-scripts', $options) && Resolver::resolveScope() == Scopes::System)
{
Console::outWarning('composer scripts are enabled while running as root, this can allow malicious scripts to run as root');
if (!isset($options['--no-interaction']))
{
if (!Console::getBooleanInput('Do you want to continue?'))
throw new UserAbortedOperationException('The operation was aborted by the user');
// The user understands the risks and wants to continue
$process->setEnv(['COMPOSER_ALLOW_SUPERUSER' => 1]);
}
}
else
{
// Composer is running "safely". We can disable the superuser check
$process->setEnv(['COMPOSER_ALLOW_SUPERUSER' => 1]);
}
self::prepareProcess($process, $tmp_dir, $options);
Console::outDebug(sprintf('executing %s', $process->getCommandLine()));
$process->run(function ($type, $buffer) {
$process->run(function ($type, $buffer)
{
Console::out($buffer, false);
});
@ -558,4 +550,206 @@
throw new ComposerNotAvailableException('No composer executable path is configured');
}
/**
* @param Process $process
* @param string $path
* @param array $options
* @return void
* @throws UserAbortedOperationException
*/
private static function prepareProcess(Process $process, string $path, array $options): void
{
$process->setWorkingDirectory($path);
// Check if scripts are enabled while running as root
if (!in_array('--no-scripts', $options) && Resolver::resolveScope() == Scopes::System)
{
Console::outWarning('composer scripts are enabled while running as root, this can allow malicious scripts to run as root');
if (!isset($options['--no-interaction']))
{
if (!Console::getBooleanInput('Do you want to continue?'))
throw new UserAbortedOperationException('The operation was aborted by the user');
// The user understands the risks and wants to continue
$process->setEnv(['COMPOSER_ALLOW_SUPERUSER' => 1]);
}
}
else
{
// Composer is running "safely". We can disable the superuser check
$process->setEnv(['COMPOSER_ALLOW_SUPERUSER' => 1]);
}
}
/**
* Converts a composer project to a NCC project
*
* @param string $package_path
* @param array $version_map
* @param mixed $composer_package
* @return ProjectConfiguration
* @throws AccessDeniedException
* @throws FileNotFoundException
* @throws IOException
* @throws MalformedJsonException
* @throws PackagePreparationFailedException
*/
private static function convertProject(string $package_path, array $version_map, ?ComposerJson $composer_package=null): ProjectConfiguration
{
if($composer_package == null)
$composer_package = ComposerJson::fromArray(Functions::loadJsonFile($package_path . DIRECTORY_SEPARATOR . 'composer.json', Functions::FORCE_ARRAY));
$project_configuration = ComposerSourceBuiltin::generateProjectConfiguration($composer_package, $version_map);
$filesystem = new Filesystem();
// Process the source files
if ($composer_package->Autoload !== null)
{
$source_directory = $package_path . DIRECTORY_SEPARATOR . '.src';
if ($filesystem->exists($source_directory))
$filesystem->remove($source_directory);
$filesystem->mkdir($source_directory);
$source_directories = [];
$static_files = [];
// Extract all the source directories
if ($composer_package->Autoload->Psr4 !== null && count($composer_package->Autoload->Psr4) > 0)
{
Console::outVerbose('Extracting PSR-4 source directories');
foreach ($composer_package->Autoload->Psr4 as $namespace_pointer)
{
if ($namespace_pointer->Path !== null && !in_array($namespace_pointer->Path, $source_directories))
{
$source_directories[] = $package_path . DIRECTORY_SEPARATOR . $namespace_pointer->Path;
}
}
}
if ($composer_package->Autoload->Psr0 !== null && count($composer_package->Autoload->Psr0) > 0)
{
Console::outVerbose('Extracting PSR-0 source directories');
foreach ($composer_package->Autoload->Psr0 as $namespace_pointer)
{
if ($namespace_pointer->Path !== null && !in_array($namespace_pointer->Path, $source_directories))
{
$source_directories[] = $package_path . DIRECTORY_SEPARATOR . $namespace_pointer->Path;
}
}
}
if ($composer_package->Autoload->Files !== null && count($composer_package->Autoload->Files) > 0)
{
Console::outVerbose('Extracting static files');
foreach ($composer_package->Autoload->Files as $file)
{
$static_files[] = $package_path . DIRECTORY_SEPARATOR . $file;
}
}
Console::outDebug(sprintf('source directories: %s', implode(', ', $source_directories)));
// First scan the project files and create a file struct.
$DirectoryScanner = new DirectoryScanner();
// TODO: Implement exclude-class handling
try
{
$DirectoryScanner->unsetFlag(FilesystemIterator::FOLLOW_SYMLINKS);
}
catch (Exception $e)
{
throw new PackagePreparationFailedException('Cannot unset flag \'FOLLOW_SYMLINKS\' in DirectoryScanner, ' . $e->getMessage(), $e);
}
// Include file components that can be compiled
$DirectoryScanner->setIncludes(ComponentFileExtensions::Php);
foreach ($source_directories as $directory)
{
/** @var SplFileInfo $item */
/** @noinspection PhpRedundantOptionalArgumentInspection */
foreach ($DirectoryScanner($directory, True) as $item)
{
if (is_dir($item->getPathName()))
continue;
$parsed_path = str_ireplace($package_path . DIRECTORY_SEPARATOR, '', $item->getPathName());
Console::outDebug(sprintf('copying file %s for package %s', $parsed_path, $composer_package->Name));
$filesystem->copy($item->getPathName(), $source_directory . DIRECTORY_SEPARATOR . $parsed_path);
}
}
if (count($static_files) > 0)
{
$project_configuration->Project->Options['static_files'] = $static_files;
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));
$filesystem->copy($file, $source_directory . DIRECTORY_SEPARATOR . $parsed_path);
}
unset($file);
}
}
$project_configuration->toFile($package_path . DIRECTORY_SEPARATOR . 'project.json');
// This part simply displays the package information to the command-line interface
if(ncc::cliMode())
{
$license_files = [
'LICENSE',
'license',
'LICENSE.txt',
'license.txt'
];
foreach($license_files as $license_file)
{
if($filesystem->exists($package_path . DIRECTORY_SEPARATOR . $license_file))
{
// Check configuration if composer.extension.display_licenses is set
if(Functions::cbool(Functions::getConfigurationProperty('composer.extension.display_licenses')))
{
Console::out(sprintf('License for package %s:', $composer_package->Name));
Console::out(IO::fread($package_path . DIRECTORY_SEPARATOR . $license_file));
break;
}
}
}
if(Functions::cbool(Functions::getConfigurationProperty('composer.extension.display_authors')))
{
if($composer_package->Authors !== null && count($composer_package->Authors) > 0)
{
Console::out(sprintf('Authors for package %s:', $composer_package->Name));
foreach($composer_package->Authors as $author)
{
Console::out(sprintf(' - %s', $author->Name));
if($author->Email !== null)
{
Console::out(sprintf(' %s', $author->Email));
}
if($author->Homepage !== null)
{
Console::out(sprintf(' %s', $author->Homepage));
}
if($author->Role !== null)
{
Console::out(sprintf(' %s', $author->Role));
}
}
}
}
}
return $project_configuration;
}
}

View file

@ -1,71 +0,0 @@
<?php
namespace ncc\Classes;
use ncc\Objects\PhpConfiguration;
class EnvironmentConfiguration
{
/**
* Returns an array of all the current configuration values set in this environment
*
* @return PhpConfiguration[]
*/
public static function getCurrentConfiguration(): array
{
$results = [];
foreach(ini_get_all() as $name => $config)
{
$results[$name] = PhpConfiguration::fromArray($config);
}
return $results;
}
/**
* Returns an array of only the changed configuration values
*
* @return PhpConfiguration[]
*/
public static function getChangedValues(): array
{
$results = [];
foreach(ini_get_all() as $name => $config)
{
$config = PhpConfiguration::fromArray($config);
if($config->LocalValue !== $config->GlobalValue)
{
$results[$name] = $config;
}
}
return $results;
}
/**
* @param string $file_path
* @return void
*/
public static function export(string $file_path)
{
$configuration = [];
foreach(self::getChangedValues() as $changedValue)
{
$configuration[$changedValue->getName()] = $changedValue->getValue();
}
// TODO: Implement ini writing process here
}
public static function import(string $file_path)
{
// TODO: Implement ini reading process here
$configuration = [];
foreach($configuration as $item => $value)
{
ini_set($item, $value);
}
}
}

View file

@ -0,0 +1,132 @@
<?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\Classes;
use ncc\Exceptions\GitCheckoutException;
use ncc\Exceptions\GitCloneException;
use ncc\Exceptions\GitTagsException;
use ncc\Exceptions\InvalidScopeException;
use ncc\ThirdParty\Symfony\Process\Process;
use ncc\Utilities\Console;
use ncc\Utilities\Functions;
class GitClient
{
/**
* Clones a remote repository to a temporary directory.
*
* @param string $url
* @return string
* @throws GitCloneException
* @throws InvalidScopeException
*/
public static function cloneRepository(string $url): string
{
Console::outVerbose('Cloning repository: ' . $url);
$path = Functions::getTmpDir();
$process = new Process(["git", "clone", $url, $path]);
$process->setTimeout(3600); // 1 hour
$process->run(function ($type, $buffer)
{
Console::outVerbose($buffer);
});
if (!$process->isSuccessful())
throw new GitCloneException($process->getErrorOutput());
Console::outVerbose('Repository cloned to: ' . $path);
return $path;
}
/**
* Checks out a specific branch or tag.
*
* @param string $path
* @param string $branch
* @throws GitCheckoutException
*/
public static function checkout(string $path, string $branch): void
{
Console::outVerbose('Checking out branch' . $branch);
$process = new Process(["git", "checkout", $branch], $path);
$process->setTimeout(3600); // 1 hour
$process->run(function ($type, $buffer)
{
if (Process::ERR === $type)
{
Console::outWarning($buffer);
}
else
{
Console::outVerbose($buffer);
}
});
if (!$process->isSuccessful())
throw new GitCheckoutException($process->getErrorOutput());
Console::outVerbose('Checked out branch: ' . $branch);
}
/**
* Returns an array of tags that are available in the repository.
*
* @param string $path
* @return array
* @throws GitTagsException
*/
public static function getTags(string $path): array
{
Console::outVerbose('Getting tags for repository: ' . $path);
$process = new Process(["git", "fetch", '--all', '--tags'] , $path);
$process->setTimeout(3600); // 1 hour
$process->run(function ($type, $buffer)
{
Console::outVerbose($buffer);
});
if (!$process->isSuccessful())
throw new GitTagsException($process->getErrorOutput());
$process = new Process(['git', '--no-pager', 'tag', '-l'] , $path);
$process->run(function ($type, $buffer)
{
Console::outVerbose($buffer);
});
if (!$process->isSuccessful())
throw new GitTagsException($process->getErrorOutput());
$tags = explode(PHP_EOL, $process->getOutput());
$tags = array_filter($tags, function ($tag)
{
return !empty($tag);
});
Console::outDebug('found ' . count($tags) . ' tags');
return array_filter($tags);
}
}

View file

@ -0,0 +1,277 @@
<?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\Classes\GithubExtension;
use ncc\Abstracts\HttpRequestType;
use ncc\Abstracts\Versions;
use ncc\Classes\HttpClient;
use ncc\Exceptions\AuthenticationException;
use ncc\Exceptions\GithubServiceException;
use ncc\Exceptions\GitlabServiceException;
use ncc\Exceptions\HttpException;
use ncc\Exceptions\MalformedJsonException;
use ncc\Exceptions\VersionNotFoundException;
use ncc\Interfaces\RepositorySourceInterface;
use ncc\Objects\DefinedRemoteSource;
use ncc\Objects\HttpRequest;
use ncc\Objects\RemotePackageInput;
use ncc\Objects\RepositoryQueryResults;
use ncc\Objects\Vault\Entry;
use ncc\ThirdParty\jelix\Version\VersionComparator;
use ncc\Utilities\Functions;
class GithubService implements RepositorySourceInterface
{
/**
* Returns the git repository url of the repository, versions cannot be specified.
*
* @param RemotePackageInput $packageInput
* @param DefinedRemoteSource $definedRemoteSource
* @param Entry|null $entry
* @return RepositoryQueryResults
* @throws AuthenticationException
* @throws GithubServiceException
* @throws GitlabServiceException
* @throws HttpException
* @throws MalformedJsonException
*/
public static function getGitRepository(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults
{
$httpRequest = new HttpRequest();
$protocol = ($definedRemoteSource->SSL ? "https" : "http");
$owner_f = str_ireplace("/", "%2F", $packageInput->Vendor);
$owner_f = str_ireplace(".", "%2F", $owner_f);
$repository = urlencode($packageInput->Package);
$httpRequest->Url = $protocol . '://' . $definedRemoteSource->Host . "/repos/$owner_f/$repository";
$response_decoded = self::getJsonResponse($httpRequest, $entry);
$query = new RepositoryQueryResults();
$query->Files->GitSshUrl = ($response_decoded['ssh_url'] ?? null);
$query->Files->GitHttpUrl = ($response_decoded['clone_url'] ?? null);
$query->Version = Functions::convertToSemVer($response_decoded['default_branch'] ?? null);
$query->ReleaseDescription = ($response_decoded['description'] ?? null);
$query->ReleaseName = ($response_decoded['name'] ?? null);
return $query;
}
/**
* Returns the download URL of the requested version of the package.
*
* @param RemotePackageInput $packageInput
* @param DefinedRemoteSource $definedRemoteSource
* @param Entry|null $entry
* @return RepositoryQueryResults
* @throws AuthenticationException
* @throws GithubServiceException
* @throws GitlabServiceException
* @throws HttpException
* @throws MalformedJsonException
* @throws VersionNotFoundException
*/
public static function getRelease(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults
{
return self::processReleases($packageInput, $definedRemoteSource, $entry);
}
/**
* @param RemotePackageInput $packageInput
* @param DefinedRemoteSource $definedRemoteSource
* @param Entry|null $entry
* @return RepositoryQueryResults
* @throws AuthenticationException
* @throws GithubServiceException
* @throws GitlabServiceException
* @throws HttpException
* @throws MalformedJsonException
* @throws VersionNotFoundException
*/
public static function getNccPackage(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults
{
return self::processReleases($packageInput, $definedRemoteSource, $entry);
}
/**
* Returns a list of all releases of the given repository with their download URL.
*
* @param RemotePackageInput $packageInput
* @param DefinedRemoteSource $definedRemoteSource
* @param Entry|null $entry
* @return array
* @throws AuthenticationException
* @throws GithubServiceException
* @throws GitlabServiceException
* @throws HttpException
* @throws MalformedJsonException
*/
private static function getReleases(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): array
{
$httpRequest = new HttpRequest();
$protocol = ($definedRemoteSource->SSL ? "https" : "http");
$owner_f = str_ireplace("/", "%2F", $packageInput->Vendor);
$owner_f = str_ireplace(".", "%2F", $owner_f);
$repository = urlencode($packageInput->Package);
$httpRequest->Url = $protocol . '://' . $definedRemoteSource->Host . "/repos/$owner_f/$repository/releases";
$response_decoded = self::getJsonResponse($httpRequest, $entry);
if(count($response_decoded) == 0)
return [];
$return = [];
foreach($response_decoded as $release)
{
$query_results = new RepositoryQueryResults();
$query_results->Version = Functions::convertToSemVer($release['tag_name']);
$query_results->ReleaseName = $release['name'];
$query_results->ReleaseDescription = $release['body'];
$query_results->Files->ZipballUrl = ($release['zipball_url'] ?? null);
$query_results->Files->TarballUrl = ($release['tarball_url'] ?? null);
if(isset($release['assets']))
{
foreach($release['assets'] as $asset)
{
$parsed_asset = self::parseAsset($asset);
if($parsed_asset !== null)
$query_results->Files->PackageUrl = $parsed_asset;
}
}
$return[$query_results->Version] = $query_results;
}
return $return;
}
/**
* Returns the asset download URL if it points to a .ncc package.
*
* @param array $asset
* @return string|null'
*/
private static function parseAsset(array $asset): ?string
{
if(isset($asset['browser_download_url']))
{
$file_extension = pathinfo($asset['browser_download_url'], PATHINFO_EXTENSION);
if($file_extension == 'ncc')
return $asset['browser_download_url'];
}
return null;
}
/**
* @param HttpRequest $httpRequest
* @param Entry|null $entry
* @return array
* @throws AuthenticationException
* @throws GithubServiceException
* @throws GitlabServiceException
* @throws HttpException
* @throws MalformedJsonException
*/
private static function getJsonResponse(HttpRequest $httpRequest, ?Entry $entry): array
{
$httpRequest->Type = HttpRequestType::GET;
$httpRequest = Functions::prepareGitServiceRequest($httpRequest, $entry, false);
$httpRequest->Headers[] = 'X-GitHub-Api-Version: 2022-11-28';
$httpRequest->Headers[] = 'Accept: application/vnd.github+json';
$response = HttpClient::request($httpRequest, true);
if ($response->StatusCode != 200)
throw new GithubServiceException(sprintf('Failed to fetch releases for the given repository. Status code: %s', $response->StatusCode));
return Functions::loadJson($response->Body, Functions::FORCE_ARRAY);
}
/**
* @param RemotePackageInput $packageInput
* @param DefinedRemoteSource $definedRemoteSource
* @param Entry|null $entry
* @return mixed
* @throws AuthenticationException
* @throws GithubServiceException
* @throws GitlabServiceException
* @throws HttpException
* @throws MalformedJsonException
* @throws VersionNotFoundException
*/
private static function processReleases(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry): mixed
{
$releases = self::getReleases($packageInput, $definedRemoteSource, $entry);
if (count($releases) === 0)
throw new VersionNotFoundException('No releases found for the given repository.');
if ($packageInput->Version == Versions::Latest)
{
$latest_version = null;
foreach ($releases as $release)
{
if ($latest_version == null)
{
$latest_version = $release->Version;
continue;
}
if (VersionComparator::compareVersion($release->Version, $latest_version) == 1)
$latest_version = $release->Version;
}
return $releases[$latest_version];
}
// Query a specific version
if (!isset($releases[$packageInput->Version]))
{
// Find the closest thing to the requested version
$selected_version = null;
foreach ($releases as $version => $url)
{
if ($selected_version == null)
{
$selected_version = $version;
continue;
}
if (VersionComparator::compareVersion($version, $packageInput->Version) == 1)
$selected_version = $version;
}
if ($selected_version == null)
throw new VersionNotFoundException('No releases found for the given repository.');
}
else
{
$selected_version = $packageInput->Version;
}
if (!isset($releases[$selected_version]))
throw new VersionNotFoundException(sprintf('No releases found for the given repository. (Selected version: %s)', $selected_version));
return $releases[$selected_version];
}
}

View file

@ -0,0 +1,242 @@
<?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\Classes\GitlabExtension;
use ncc\Abstracts\Versions;
use ncc\Classes\HttpClient;
use ncc\Exceptions\AuthenticationException;
use ncc\Exceptions\GitlabServiceException;
use ncc\Exceptions\HttpException;
use ncc\Exceptions\MalformedJsonException;
use ncc\Exceptions\NotSupportedException;
use ncc\Exceptions\VersionNotFoundException;
use ncc\Interfaces\RepositorySourceInterface;
use ncc\Objects\DefinedRemoteSource;
use ncc\Objects\HttpRequest;
use ncc\Objects\RemotePackageInput;
use ncc\Objects\RepositoryQueryResults;
use ncc\Objects\Vault\Entry;
use ncc\ThirdParty\jelix\Version\VersionComparator;
use ncc\Utilities\Functions;
class GitlabService implements RepositorySourceInterface
{
/**
* Attempts to return the gitRepositoryUrl of a release, cannot specify a version.
* This needs to be done using git
*
* @param RemotePackageInput $packageInput
* @param DefinedRemoteSource $definedRemoteSource
* @param Entry|null $entry
* @return RepositoryQueryResults
* @throws AuthenticationException
* @throws GitlabServiceException
* @throws HttpException
* @throws MalformedJsonException
*/
public static function getGitRepository(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry=null): RepositoryQueryResults
{
$httpRequest = new HttpRequest();
$protocol = ($definedRemoteSource->SSL ? "https" : "http");
$owner_f = str_ireplace("/", "%2F", $packageInput->Vendor);
$owner_f = str_ireplace(".", "%2F", $owner_f);
$project_f = str_ireplace("/", "%2F", $packageInput->Package);
$project_f = str_ireplace(".", "%2F", $project_f);
$httpRequest->Url = $protocol . '://' . $definedRemoteSource->Host . "/api/v4/projects/$owner_f%2F$project_f";
$httpRequest = Functions::prepareGitServiceRequest($httpRequest, $entry);
$response = HttpClient::request($httpRequest, true);
if($response->StatusCode != 200)
throw new GitlabServiceException(sprintf('Failed to fetch releases for the given repository. Status code: %s', $response->StatusCode));
$response_decoded = Functions::loadJson($response->Body, Functions::FORCE_ARRAY);
$query = new RepositoryQueryResults();
$query->Files->GitSshUrl = ($response_decoded['ssh_url_to_repo'] ?? null);
$query->Files->GitHttpUrl = ($response_decoded['http_url_to_repo'] ?? null);
$query->Version = Functions::convertToSemVer($response_decoded['default_branch']) ?? null;
$query->ReleaseDescription = ($response_decoded['description'] ?? null);
$query->ReleaseName = ($response_decoded['name'] ?? null);
return $query;
}
/**
* Returns the download URL of the requested version of the package.
*
* @param RemotePackageInput $packageInput
* @param DefinedRemoteSource $definedRemoteSource
* @param Entry|null $entry
* @return RepositoryQueryResults
* @throws AuthenticationException
* @throws GitlabServiceException
* @throws HttpException
* @throws MalformedJsonException
* @throws VersionNotFoundException
*/
public static function getRelease(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults
{
$releases = self::getReleases($packageInput->Vendor, $packageInput->Package, $definedRemoteSource, $entry);
if(count($releases) === 0)
throw new VersionNotFoundException('No releases found for the given repository.');
// Query the latest package only
if($packageInput->Version == Versions::Latest)
{
$latest_version = null;
foreach($releases as $release)
{
if($latest_version == null)
{
$latest_version = $release->Version;
continue;
}
if(VersionComparator::compareVersion($release->Version, $latest_version) == 1)
$latest_version = $release->Version;
}
return $releases[$latest_version];
}
// Query a specific version
if(!isset($releases[$packageInput->Version]))
{
// Find the closest thing to the requested version
$selected_version = null;
foreach($releases as $version => $url)
{
if($selected_version == null)
{
$selected_version = $version;
continue;
}
if(VersionComparator::compareVersion($version, $packageInput->Version) == 1)
$selected_version = $version;
}
if($selected_version == null)
throw new VersionNotFoundException('No releases found for the given repository.');
}
else
{
$selected_version = $packageInput->Version;
}
if(!isset($releases[$selected_version]))
throw new VersionNotFoundException(sprintf('No releases found for the given repository. (Selected version: %s)', $selected_version));
return $releases[$selected_version];
}
/**
* @param RemotePackageInput $packageInput
* @param DefinedRemoteSource $definedRemoteSource
* @param Entry|null $entry
* @return RepositoryQueryResults
* @throws NotSupportedException
*/
public static function getNccPackage(RemotePackageInput $packageInput, DefinedRemoteSource $definedRemoteSource, ?Entry $entry = null): RepositoryQueryResults
{
throw new NotSupportedException(sprintf('The given repository source "%s" does not support ncc packages.', $definedRemoteSource->Host));
}
/**
* Returns an array of all the tags for the given owner and repository name.
*
* @param string $owner
* @param string $repository
* @param DefinedRemoteSource $definedRemoteSource
* @param Entry|null $entry
* @return array
* @throws AuthenticationException
* @throws GitlabServiceException
* @throws HttpException
* @throws MalformedJsonException
*/
private static function getReleases(string $owner, string $repository, DefinedRemoteSource $definedRemoteSource, ?Entry $entry): array
{
$httpRequest = new HttpRequest();
$protocol = ($definedRemoteSource->SSL ? "https" : "http");
$owner_f = str_ireplace("/", "%2F", $owner);
$owner_f = str_ireplace(".", "%2F", $owner_f);
$repository_f = str_ireplace("/", "%2F", $repository);
$repository_f = str_ireplace(".", "%2F", $repository_f);
$httpRequest->Url = $protocol . '://' . $definedRemoteSource->Host . "/api/v4/projects/$owner_f%2F$repository_f/releases";
$httpRequest = Functions::prepareGitServiceRequest($httpRequest, $entry);
$response = HttpClient::request($httpRequest, true);
if($response->StatusCode != 200)
throw new GitlabServiceException(sprintf('Failed to fetch releases for the given repository. Status code: %s', $response->StatusCode));
$response_decoded = Functions::loadJson($response->Body, Functions::FORCE_ARRAY);
if(count($response_decoded) == 0)
return [];
$return = [];
foreach($response_decoded as $release)
{
$query_results = new RepositoryQueryResults();
$query_results->ReleaseName = ($release['name'] ?? null);
$query_results->ReleaseDescription = ($release['description'] ?? null);
$query_results->Version = Functions::convertToSemVer($release['tag_name']);
if(isset($release['assets']) && isset($release['assets']['sources']))
{
if(count($release['assets']['sources']) > 0)
{
foreach($release['assets']['sources'] as $source)
{
if($source['format'] == 'zip')
{
$query_results->Files->ZipballUrl = $source['url'];
break;
}
if($source['format'] == 'tar.gz')
{
$query_results->Files->ZipballUrl = $source['url'];
break;
}
if($source['format'] == 'ncc')
{
$query_results->Files->PackageUrl = $source['url'];
break;
}
}
}
}
$return[$query_results->Version] = $query_results;
}
return $return;
}
}

View file

@ -0,0 +1,241 @@
<?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\Classes;
use CurlHandle;
use ncc\Abstracts\HttpRequestType;
use ncc\Abstracts\LogLevel;
use ncc\CLI\Main;
use ncc\Exceptions\HttpException;
use ncc\Objects\HttpRequest;
use ncc\Objects\HttpResponse;
use ncc\Objects\HttpResponseCache;
use ncc\Utilities\Console;
use ncc\Utilities\RuntimeCache;
class HttpClient
{
/**
* Prepares the curl request
*
* @param HttpRequest $request
* @return CurlHandle
*/
private static function prepareCurl(HttpRequest $request): CurlHandle
{
$curl = curl_init($request->Url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_MAXREDIRS, 5);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, $request->Headers);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->Type);
switch($request->Type)
{
case HttpRequestType::GET:
curl_setopt($curl, CURLOPT_HTTPGET, true);
break;
case HttpRequestType::POST:
curl_setopt($curl, CURLOPT_POST, true);
if($request->Body !== null)
curl_setopt($curl, CURLOPT_POSTFIELDS, $request->Body);
break;
case HttpRequestType::PUT:
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
if($request->Body !== null)
curl_setopt($curl, CURLOPT_POSTFIELDS, $request->Body);
break;
case HttpRequestType::DELETE:
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'DELETE');
break;
}
if (is_array($request->Authentication))
{
curl_setopt($curl, CURLOPT_USERPWD, $request->Authentication[0] . ':' . $request->Authentication[1]);
}
else if (is_string($request->Authentication))
{
curl_setopt($curl, CURLOPT_USERPWD, $request->Authentication);
}
foreach ($request->Options as $option => $value)
curl_setopt($curl, $option, $value);
return $curl;
}
/**
* Creates a new HTTP request and returns the response.
*
* @param HttpRequest $httpRequest
* @param bool $cache
* @return HttpResponse
* @throws HttpException
*/
public static function request(HttpRequest $httpRequest, bool $cache=false): HttpResponse
{
if($cache)
{
/** @var HttpResponseCache $cache */
$cache = RuntimeCache::get(sprintf('http_cache_%s', $httpRequest->requestHash()));
if($cache !== null && $cache->getTtl() > time())
{
Console::outDebug(sprintf('using cached response for %s', $httpRequest->requestHash()));
return $cache->getHttpResponse();
}
}
$curl = self::prepareCurl($httpRequest);
Console::outDebug(sprintf(' => %s request %s', $httpRequest->Type, $httpRequest->Url));
if($httpRequest->Headers !== null && count($httpRequest->Headers) > 0)
Console::outDebug(sprintf(' => headers: %s', implode(', ', $httpRequest->Headers)));
if($httpRequest->Body !== null)
Console::outDebug(sprintf(' => body: %s', $httpRequest->Body));
$response = curl_exec($curl);
if ($response === false)
{
$error = curl_error($curl);
curl_close($curl);
throw new HttpException($error);
}
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$headers = substr($response, 0, $headerSize);
$body = substr($response, $headerSize);
$httpResponse = new HttpResponse();
$httpResponse->StatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
$httpResponse->Headers = self::parseHeaders($headers);
$httpResponse->Body = $body;
Console::outDebug(sprintf(' <= %s response', $httpResponse->StatusCode));/** @noinspection PhpConditionAlreadyCheckedInspection */
if($httpResponse->Headers !== null && count($httpResponse->Headers) > 0)
Console::outDebug(sprintf(' <= headers: %s', implode(', ', $httpResponse->Headers)));
/** @noinspection PhpConditionAlreadyCheckedInspection */
if($httpResponse->Body !== null)
Console::outDebug(sprintf(' <= body: %s', $httpResponse->Body));
curl_close($curl);
if($cache)
{
$httpCacheObject = new HttpResponseCache($httpResponse, time() + 60);
RuntimeCache::set(sprintf('http_cache_%s', $httpRequest->requestHash()), $httpCacheObject);
Console::outDebug(sprintf('cached response for %s', $httpRequest->requestHash()));
}
return $httpResponse;
}
/**
* Downloads a file from the given url and saves it to the given path.
*
* @param HttpRequest $httpRequest
* @param string $path
* @return void
* @throws HttpException
*/
public static function download(HttpRequest $httpRequest, string $path): void
{
$curl = self::prepareCurl($httpRequest);
$fp = fopen($path, 'w');
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_setopt($curl, CURLOPT_HEADER, 0);
$response = curl_exec($curl);
if ($response === false)
{
$error = curl_error($curl);
curl_close($curl);
throw new HttpException($error);
}
curl_close($curl);
fclose($fp);
}
/**
* Displays the download progress in the console
*
* @param $downloadSize
* @param $downloaded
* @return void
*/
public static function displayProgress($downloadSize, $downloaded): void
{
if(Main::getLogLevel() !== null)
{
switch(Main::getLogLevel())
{
case LogLevel::Verbose:
case LogLevel::Debug:
case LogLevel::Silent:
Console::outVerbose(sprintf(' <= %s of %s bytes downloaded', $downloaded, $downloadSize));
break;
default:
if ($downloadSize > 0)
Console::inlineProgressBar($downloaded, $downloadSize);
break;
}
}
}
/**
* Takes the return headers of a cURL request and parses them into an array.
*
* @param string $input
* @return array
*/
private static function parseHeaders(string $input): array
{
$headers = array();
$lines = explode("\n", $input);
$headers['HTTP'] = array_shift($lines);
foreach ($lines as $line) {
$header = explode(':', $line, 2);
if (count($header) == 2) {
$headers[trim($header[0])] = trim($header[1]);
}
}
return $headers;
}
}

View file

@ -0,0 +1,53 @@
<?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\Classes\LuaExtension;
use ncc\Interfaces\RunnerInterface;
use ncc\Objects\Package\ExecutionUnit;
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
use ncc\Utilities\IO;
class LuaRunner implements RunnerInterface
{
/**
* @inheritDoc
*/
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
{
$execution_unit = new ExecutionUnit();
$policy->Execute->Target = null;
$execution_unit->ExecutionPolicy = $policy;
$execution_unit->Data = IO::fread($path);
return $execution_unit;
}
/**
* @inheritDoc
*/
public static function getFileExtension(): string
{
return '.lua';
}
}

View file

@ -1,14 +1,33 @@
<?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\Classes\NccExtension;
namespace ncc\Classes\NccExtension;
use ncc\Abstracts\SpecialConstants\BuildConstants;
use ncc\Abstracts\SpecialConstants\DateTimeConstants;
use ncc\Abstracts\SpecialConstants\InstallConstants;
use ncc\Abstracts\SpecialConstants\AssemblyConstants;
use ncc\Abstracts\SpecialConstants\RuntimeConstants;
use ncc\Objects\InstallationPaths;
use ncc\Objects\Package;
use ncc\Objects\ProjectConfiguration;
use ncc\Objects\ProjectConfiguration\Assembly;
class ConstantCompiler
@ -126,4 +145,28 @@
return $input;
}
/**
* @param string|null $input
* @return string|null
* @noinspection PhpUnnecessaryLocalVariableInspection
*/
public static function compileRuntimeConstants(?string $input): ?string
{
if ($input == null)
return null;
if(function_exists('getcwd'))
$input = str_replace(RuntimeConstants::CWD, getcwd(), $input);
if(function_exists('getmypid'))
$input = str_replace(RuntimeConstants::PID, getmypid(), $input);
if(function_exists('getmyuid'))
$input = str_replace(RuntimeConstants::UID, getmyuid(), $input);
if(function_exists('getmygid'))
$input = str_replace(RuntimeConstants::GID, getmygid(), $input);
if(function_exists('get_current_user'))
$input = str_replace(RuntimeConstants::User, get_current_user(), $input);
return $input;
}
}

View file

@ -1,12 +1,34 @@
<?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\Classes\NccExtension;
namespace ncc\Classes\NccExtension;
use Exception;
use ncc\Abstracts\CompilerExtensions;
use ncc\Abstracts\ConstantReferences;
use ncc\Abstracts\LogLevel;
use ncc\Abstracts\Options\BuildConfigurationValues;
use ncc\Abstracts\ProjectType;
use ncc\Classes\ComposerExtension\ComposerSourceBuiltin;
use ncc\Classes\PhpExtension\PhpCompiler;
use ncc\CLI\Main;
use ncc\Exceptions\AccessDeniedException;
@ -17,8 +39,9 @@
use ncc\Exceptions\MalformedJsonException;
use ncc\Exceptions\PackagePreparationFailedException;
use ncc\Exceptions\ProjectConfigurationNotFoundException;
use ncc\Exceptions\RunnerExecutionException;
use ncc\Exceptions\UnsupportedCompilerExtensionException;
use ncc\Exceptions\UnsupportedRunnerException;
use ncc\Exceptions\UnsupportedProjectTypeException;
use ncc\Interfaces\CompilerInterface;
use ncc\Managers\ProjectManager;
use ncc\ncc;
@ -47,7 +70,6 @@
* @throws PackagePreparationFailedException
* @throws ProjectConfigurationNotFoundException
* @throws UnsupportedCompilerExtensionException
* @throws UnsupportedRunnerException
*/
public static function compile(ProjectManager $manager, string $build_configuration=BuildConfigurationValues::DefaultConfiguration): string
{
@ -84,6 +106,52 @@
);
}
/**
* Attempts to detect the project type and convert it accordingly before compiling
* Returns the compiled package path
*
* @param string $path
* @param string|null $version
* @return string
* @throws BuildException
*/
public static function tryCompile(string $path, ?string $version=null): string
{
$project_type = Resolver::detectProjectType($path);
try
{
if($project_type->ProjectType == ProjectType::Composer)
{
$project_path = ComposerSourceBuiltin::fromLocal($project_type->ProjectPath);
}
elseif($project_type->ProjectType == ProjectType::Ncc)
{
$project_manager = new ProjectManager($project_type->ProjectPath);
$project_manager->getProjectConfiguration()->Assembly->Version = $version;
$project_path = $project_manager->build();
}
else
{
throw new UnsupportedProjectTypeException('The project type \'' . $project_type->ProjectType . '\' is not supported');
}
if($version !== null)
{
$package = Package::load($project_path);
$package->Assembly->Version = Functions::convertToSemVer($version);
$package->save($project_path);
}
return $project_path;
}
catch(Exception $e)
{
throw new BuildException('Failed to build project', $e);
}
}
/**
* Compiles the execution policies of the package
*
@ -93,7 +161,7 @@
* @throws AccessDeniedException
* @throws FileNotFoundException
* @throws IOException
* @throws UnsupportedRunnerException
* @throws RunnerExecutionException
*/
public static function compileExecutionPolicies(string $path, ProjectConfiguration $configuration): array
{
@ -108,6 +176,8 @@
/** @var ProjectConfiguration\ExecutionPolicy $policy */
foreach($configuration->ExecutionPolicies as $policy)
{
Console::outVerbose(sprintf('Compiling Execution Policy %s', $policy->Name));
if($total_items > 5)
{
Console::inlineProgressBar($processed_items, $total_items);
@ -132,29 +202,29 @@
* @param string $build_configuration
* @return string
* @throws BuildConfigurationNotFoundException
* @throws BuildException
* @throws IOException
*/
public static function writePackage(string $path, Package $package, ProjectConfiguration $configuration, string $build_configuration=BuildConfigurationValues::DefaultConfiguration): string
{
Console::outVerbose(sprintf('Writing package to %s', $path));
// Write the package to disk
$FileSystem = new Filesystem();
$BuildConfiguration = $configuration->Build->getBuildConfiguration($build_configuration);
if($FileSystem->exists($path . $BuildConfiguration->OutputPath))
if(!$FileSystem->exists($path . $BuildConfiguration->OutputPath))
{
try
{
$FileSystem->remove($path . $BuildConfiguration->OutputPath);
}
catch(\ncc\ThirdParty\Symfony\Filesystem\Exception\IOException $e)
{
throw new BuildException('Cannot delete directory \'' . $path . $BuildConfiguration->OutputPath . '\', ' . $e->getMessage(), $e);
}
Console::outDebug(sprintf('creating output directory %s', $path . $BuildConfiguration->OutputPath));
$FileSystem->mkdir($path . $BuildConfiguration->OutputPath);
}
// Finally write the package to the disk
$FileSystem->mkdir($path . $BuildConfiguration->OutputPath);
$output_file = $path . $BuildConfiguration->OutputPath . DIRECTORY_SEPARATOR . $package->Assembly->Package . '.ncc';
if($FileSystem->exists($output_file))
{
Console::outDebug(sprintf('removing existing package %s', $output_file));
$FileSystem->remove($output_file);
}
$FileSystem->touch($output_file);
try
@ -169,35 +239,13 @@
return $output_file;
}
/**
* Compiles the special formatted constants
*
* @param Package $package
* @param int $timestamp
* @return array
*/
public static function compileRuntimeConstants(Package $package, int $timestamp): array
{
$compiled_constants = [];
foreach($package->Header->RuntimeConstants as $name => $value)
{
$compiled_constants[$name] = self::compileConstants($value, [
ConstantReferences::Assembly => $package->Assembly,
ConstantReferences::DateTime => $timestamp,
ConstantReferences::Build => null
]);
}
return $compiled_constants;
}
/**
* Compiles the constants in the package object
*
* @param Package $package
* @param array $refs
* @return void
* @noinspection PhpParameterByRefIsNotUsedAsReferenceInspection
*/
public static function compilePackageConstants(Package &$package, array $refs): void
{
@ -206,6 +254,7 @@
$assembly = [];
foreach($package->Assembly->toArray() as $key => $value)
{
Console::outDebug(sprintf('compiling consts Assembly.%s (%s)', $key, implode(', ', array_keys($refs))));
$assembly[$key] = self::compileConstants($value, $refs);
}
$package->Assembly = Assembly::fromArray($assembly);
@ -217,11 +266,44 @@
$units = [];
foreach($package->ExecutionUnits as $executionUnit)
{
Console::outDebug(sprintf('compiling execution unit consts %s (%s)', $executionUnit->ExecutionPolicy->Name, implode(', ', array_keys($refs))));
$units[] = self::compileExecutionUnitConstants($executionUnit, $refs);
}
$package->ExecutionUnits = $units;
unset($units);
}
$compiled_constants = [];
foreach($package->Header->RuntimeConstants as $name => $value)
{
Console::outDebug(sprintf('compiling runtime const %s (%s)', $name, implode(', ', array_keys($refs))));
$compiled_constants[$name] = self::compileConstants($value, $refs);
}
$options = [];
foreach($package->Header->Options as $name => $value)
{
if(is_array($value))
{
$options[$name] = [];
foreach($value as $key => $val)
{
if(!is_string($val))
continue;
Console::outDebug(sprintf('compiling option %s.%s (%s)', $name, $key, implode(', ', array_keys($refs))));
$options[$name][$key] = self::compileConstants($val, $refs);
}
}
else
{
Console::outDebug(sprintf('compiling option %s (%s)', $name, implode(', ', array_keys($refs))));
$options[$name] = self::compileConstants((string)$value, $refs);
}
}
$package->Header->Options = $options;
$package->Header->RuntimeConstants = $compiled_constants;
}
/**
@ -303,6 +385,9 @@
if(isset($refs[ConstantReferences::Install]))
$value = ConstantCompiler::compileInstallConstants($value, $refs[ConstantReferences::Install]);
if(isset($refs[ConstantReferences::Runtime]))
$value = ConstantCompiler::compileRuntimeConstants($value);
return $value;
}
}

View file

@ -1,20 +1,35 @@
<?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\Classes\NccExtension;
namespace ncc\Classes\NccExtension;
use ncc\Abstracts\Runners;
use ncc\Abstracts\Scopes;
use ncc\Exceptions\AccessDeniedException;
use ncc\Exceptions\ExecutionUnitNotFoundException;
use ncc\Exceptions\FileNotFoundException;
use ncc\Exceptions\IOException;
use ncc\Exceptions\NoAvailableUnitsException;
use ncc\Exceptions\RunnerExecutionException;
use ncc\Exceptions\UnsupportedRunnerException;
use ncc\Managers\ExecutionPointerManager;
use ncc\Objects\ExecutionPointers\ExecutionPointer;
use ncc\Objects\Package\ExecutionUnit;
use ncc\Utilities\PathFinder;
use ncc\Utilities\Resolver;
class Runner
@ -27,21 +42,19 @@
* @param ExecutionUnit $unit
* @return void
* @throws AccessDeniedException
* @throws UnsupportedRunnerException
* @throws ExecutionUnitNotFoundException
* @throws FileNotFoundException
* @throws IOException
* @throws NoAvailableUnitsException
* @throws RunnerExecutionException
*/
public static function temporaryExecute(string $package, string $version, ExecutionUnit $unit)
public static function temporaryExecute(string $package, string $version, ExecutionUnit $unit): void
{
if(Resolver::resolveScope() !== Scopes::System)
throw new AccessDeniedException('Cannot temporarily execute a unit with insufficent permissions');
throw new AccessDeniedException('Cannot temporarily execute a unit with insufficient permissions');
$ExecutionPointerManager = new ExecutionPointerManager();
$ExecutionPointerManager->addUnit($package, $version, $unit, true);
$ExecutionPointerManager->executeUnit($package, $version, $unit->ExecutionPolicy->Name);
$ExecutionPointerManager->cleanTemporaryUnits();;
$ExecutionPointerManager->cleanTemporaryUnits();
}
}

View file

@ -0,0 +1,56 @@
<?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\Classes\PerlExtension;
use ncc\Exceptions\FileNotFoundException;
use ncc\Interfaces\RunnerInterface;
use ncc\Objects\Package\ExecutionUnit;
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
use ncc\Utilities\IO;
class PerlRunner implements RunnerInterface
{
/**
* @inheritDoc
*/
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
{
$execution_unit = new ExecutionUnit();
$policy->Execute->Target = null;
if(!file_exists($path) && !is_file($path))
throw new FileNotFoundException($path);
$execution_unit->ExecutionPolicy = $policy;
$execution_unit->Data = IO::fread($path);
return $execution_unit;
}
/**
* @inheritDoc
*/
public static function getFileExtension(): string
{
return '.pl';
}
}

View file

@ -1,4 +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.
*
*/
/** @noinspection PhpMissingFieldTypeInspection */
@ -19,11 +39,10 @@
use ncc\Exceptions\IOException;
use ncc\Exceptions\PackageLockException;
use ncc\Exceptions\PackagePreparationFailedException;
use ncc\Exceptions\UnsupportedRunnerException;
use ncc\Exceptions\RunnerExecutionException;
use ncc\Exceptions\VersionNotFoundException;
use ncc\Interfaces\CompilerInterface;
use ncc\Managers\PackageLockManager;
use ncc\ncc;
use ncc\Objects\Package;
use ncc\Objects\ProjectConfiguration;
use ncc\ThirdParty\nikic\PhpParser\ParserFactory;
@ -92,11 +111,15 @@
$this->package->Dependencies = $this->project->Build->Dependencies;
$this->package->MainExecutionPolicy = $this->project->Build->Main;
// 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)
$this->package->Header->Options['create_symlink'] = true;
// Add both the defined constants from the build configuration and the global constants.
// Global constants are overridden
$this->package->Header->RuntimeConstants = [];
$this->package->Header->RuntimeConstants = array_merge(
($selected_build_configuration?->DefineConstants ?? []),
($selected_build_configuration->DefineConstants ?? []),
($this->project->Build->DefineConstants ?? []),
($this->package->Header->RuntimeConstants ?? [])
);
@ -105,6 +128,11 @@
$this->package->Header->CompilerVersion = NCC_VERSION_NUMBER;
$this->package->Header->Options = $this->project->Project->Options;
if($this->project->Project->UpdateSource !== null)
{
$this->package->Header->UpdateSource = $this->project->Project->UpdateSource;
}
Console::outDebug('scanning project files');
Console::outDebug('theseer\DirectoryScanner - Copyright (c) 2009-2014 Arne Blankerts <arne@blankerts.de> All rights reserved.');
@ -128,67 +156,75 @@
// TODO: Re-implement the scanning process outside the compiler, as this is will be redundant
// Scan for components first.
Console::outVerbose('Scanning for components... ');
/** @var SplFileInfo $item */
/** @noinspection PhpRedundantOptionalArgumentInspection */
foreach($DirectoryScanner($source_path, True) as $item)
if(file_exists($source_path))
{
// Ignore directories, they're not important. :-)
if(is_dir($item->getPathName()))
continue;
Console::outVerbose('Scanning for components... ');
/** @var SplFileInfo $item */
/** @noinspection PhpRedundantOptionalArgumentInspection */
foreach($DirectoryScanner($source_path, True) as $item)
{
// Ignore directories, they're not important. :-)
if(is_dir($item->getPathName()))
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)
{
Console::outVerbose(count($this->package->Components) . ' component(s) found');
if(count($this->package->Components) > 0)
{
Console::outVerbose(count($this->package->Components) . ' component(s) found');
}
else
{
Console::outVerbose('No components found');
}
// Clear previous excludes and includes
$DirectoryScanner->setExcludes();
$DirectoryScanner->setIncludes();
// Ignore component files
if($selected_build_configuration->ExcludeFiles !== null && count($selected_build_configuration->ExcludeFiles) > 0)
{
$DirectoryScanner->setExcludes(array_merge($selected_build_configuration->ExcludeFiles, ComponentFileExtensions::Php));
}
else
{
$DirectoryScanner->setExcludes(ComponentFileExtensions::Php);
}
Console::outVerbose('Scanning for resources... ');
/** @var SplFileInfo $item */
foreach($DirectoryScanner($source_path) as $item)
{
// Ignore directories, they're not important. :-)
if(is_dir($item->getPathName()))
continue;
$Resource = new Package\Resource();
$Resource->Name = Functions::removeBasename($item->getPathname(), $this->path);
$this->package->Resources[] = $Resource;
Console::outVerbose(sprintf('found resource %s', $Resource->Name));
}
if(count($this->package->Resources) > 0)
{
Console::outVerbose(count($this->package->Resources) . ' resources(s) found');
}
else
{
Console::outVerbose('No resources found');
}
}
else
{
Console::outVerbose('No components found');
}
// Clear previous excludes and includes
$DirectoryScanner->setExcludes([]);
$DirectoryScanner->setIncludes([]);
// Ignore component files
if($selected_build_configuration->ExcludeFiles !== null && count($selected_build_configuration->ExcludeFiles) > 0)
{
$DirectoryScanner->setExcludes(array_merge($selected_build_configuration->ExcludeFiles, ComponentFileExtensions::Php));
}
else
{
$DirectoryScanner->setExcludes(ComponentFileExtensions::Php);
}
Console::outVerbose('Scanning for resources... ');
/** @var SplFileInfo $item */
foreach($DirectoryScanner($source_path) as $item)
{
// Ignore directories, they're not important. :-)
if(is_dir($item->getPathName()))
continue;
$Resource = new Package\Resource();
$Resource->Name = Functions::removeBasename($item->getPathname(), $this->path);
$this->package->Resources[] = $Resource;
Console::outVerbose(sprintf('found resource %s', $Resource->Name));
}
if(count($this->package->Resources) > 0)
{
Console::outVerbose(count($this->package->Resources) . ' resources(s) found');
}
else
{
Console::outVerbose('No resources found');
Console::outWarning('Source path does not exist, skipping resource and component scanning');
}
$selected_dependencies = [];
@ -206,7 +242,6 @@
$lib_path = $selected_build_configuration->OutputPath . DIRECTORY_SEPARATOR . 'libs';
if($filesystem->exists($lib_path))
$filesystem->remove($lib_path);
$filesystem->mkdir($lib_path);
Console::outVerbose('Scanning for dependencies... ');
foreach($selected_dependencies as $dependency)
@ -222,6 +257,10 @@
$package = $package_lock_manager->getPackageLock()->getPackage($dependency->Name);
$version = $package->getVersion($dependency->Version);
Console::outDebug(sprintf('copying shadow package %s=%s to %s', $dependency->Name, $dependency->Version, $out_path));
if(!$filesystem->exists($lib_path))
$filesystem->mkdir($lib_path);
$filesystem->copy($version->Location, $out_path);
$dependency->Source = 'libs' . DIRECTORY_SEPARATOR . sprintf('%s=%s.lib', $dependency->Name, $dependency->Version);
@ -242,7 +281,7 @@
break;
}
$this->package->Dependencies[] = $dependency;
$this->package->addDependency($dependency);
}
if(count($this->package->Dependencies) > 0)
@ -265,7 +304,6 @@
* @throws BuildException
* @throws FileNotFoundException
* @throws IOException
* @throws UnsupportedRunnerException
*/
public function build(): ?Package
{
@ -404,11 +442,11 @@
* @throws AccessDeniedException
* @throws FileNotFoundException
* @throws IOException
* @throws UnsupportedRunnerException
* @throws RunnerExecutionException
*/
public function compileExecutionPolicies(): void
{
PackageCompiler::compileExecutionPolicies($this->path, $this->project);
$this->package->ExecutionUnits = PackageCompiler::compileExecutionPolicies($this->path, $this->project);
}
/**

View file

@ -1,4 +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.
*
*/
/** @noinspection PhpPropertyOnlyWrittenInspection */
/** @noinspection PhpMissingFieldTypeInspection */
@ -13,7 +33,6 @@
use ncc\Exceptions\ComponentChecksumException;
use ncc\Exceptions\ComponentDecodeException;
use ncc\Exceptions\FileNotFoundException;
use ncc\Exceptions\InstallationException;
use ncc\Exceptions\IOException;
use ncc\Exceptions\NoUnitsFoundException;
use ncc\Exceptions\ResourceChecksumException;
@ -31,7 +50,6 @@
use ncc\ThirdParty\theseer\Autoload\Factory;
use ncc\Utilities\Base64;
use ncc\Utilities\IO;
use ncc\ZiProto\ZiProto;
use ReflectionClass;
use ReflectionException;
use RuntimeException;
@ -115,24 +133,8 @@
*/
public function postInstall(InstallationPaths $installationPaths): void
{
$static_files_exists = false;
if($this->package->Header->Options !== null && isset($this->package->Header->Options['static_files']))
{
$static_files = $this->package->Header->Options['static_files'];
$static_files_path = $installationPaths->getBinPath() . DIRECTORY_SEPARATOR . 'static_autoload.bin';
foreach($static_files as $file)
{
if(!file_exists($file))
throw new InstallationException(sprintf('Static file %s does not exist', $file));
}
$static_files_exists = true;
IO::fwrite($static_files_path, ZiProto::encode($static_files));
}
$autoload_path = $installationPaths->getBinPath() . DIRECTORY_SEPARATOR . 'autoload.php';
$autoload_src = $this->generateAutoload($installationPaths->getSourcePath(), $autoload_path, $static_files_exists);
$autoload_src = $this->generateAutoload($installationPaths->getSourcePath(), $autoload_path);
IO::fwrite($autoload_path, $autoload_src);
}
@ -286,15 +288,13 @@
*
* @param string $src
* @param string $output
* @param bool $ignore_units
* @return string
* @throws AccessDeniedException
* @throws CollectorException
* @throws FileNotFoundException
* @throws IOException
* @throws NoUnitsFoundException
*/
private function generateAutoload(string $src, string $output, bool $ignore_units=false): string
private function generateAutoload(string $src, string $output): string
{
// Construct configuration
$configuration = new Config([$src]);
@ -315,10 +315,6 @@
$result = self::runCollector($factory, $configuration);
// Exception raises when there are no files in the project that can be processed by the autoloader
if(!$result->hasUnits() && !$ignore_units)
{
throw new NoUnitsFoundException('No units were found in the project');
}
$template = IO::fread($configuration->getTemplate());

View file

@ -1,18 +1,33 @@
<?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\Classes\PhpExtension;
namespace ncc\Classes\PhpExtension;
use ncc\Exceptions\AccessDeniedException;
use ncc\Exceptions\FileNotFoundException;
use ncc\Exceptions\IOException;
use ncc\Exceptions\RunnerExecutionException;
use ncc\Interfaces\RunnerInterface;
use ncc\Objects\ExecutionPointers\ExecutionPointer;
use ncc\Objects\Package\ExecutionUnit;
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
use ncc\ThirdParty\Symfony\Process\ExecutableFinder;
use ncc\ThirdParty\Symfony\Process\Process;
use ncc\Utilities\Base64;
use ncc\Utilities\IO;
class PhpRunner implements RunnerInterface
@ -28,12 +43,11 @@
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
{
$execution_unit = new ExecutionUnit();
$target_file = $path;
if(!file_exists($target_file) && !is_file($target_file))
throw new FileNotFoundException($target_file);
if(!file_exists($path) && !is_file($path))
throw new FileNotFoundException($path);
$policy->Execute->Target = null;
$execution_unit->ExecutionPolicy = $policy;
$execution_unit->Data = Base64::encode(IO::fread($target_file));
$execution_unit->Data = IO::fread($path);
return $execution_unit;
}
@ -47,21 +61,4 @@
{
return '.php';
}
/**
* @param ExecutionPointer $pointer
* @return Process
* @throws RunnerExecutionException
*/
public static function prepareProcess(ExecutionPointer $pointer): Process
{
$php_bin = new ExecutableFinder();
$php_bin = $php_bin->find('php');
if($php_bin == null)
throw new RunnerExecutionException('Cannot locate PHP executable');
if($pointer->ExecutionPolicy->Execute->Options !== null && count($pointer->ExecutionPolicy->Execute->Options) > 0)
return new Process(array_merge([$php_bin, $pointer->FilePointer], $pointer->ExecutionPolicy->Execute->Options));
return new Process([$php_bin, $pointer->FilePointer]);
}
}

View file

@ -0,0 +1,124 @@
<?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\Classes\PhpExtension;
use Exception;
use ncc\Abstracts\Options\RuntimeImportOptions;
use ncc\Classes\NccExtension\ConstantCompiler;
use ncc\Exceptions\ConstantReadonlyException;
use ncc\Exceptions\ImportException;
use ncc\Exceptions\InvalidConstantNameException;
use ncc\Interfaces\RuntimeInterface;
use ncc\Objects\PackageLock\VersionEntry;
use ncc\Objects\ProjectConfiguration\Assembly;
use ncc\Runtime\Constants;
use ncc\Utilities\IO;
use ncc\ZiProto\ZiProto;
class PhpRuntime implements RuntimeInterface
{
/**
* Attempts to import a PHP package
*
* @param VersionEntry $versionEntry
* @param array $options
* @return bool
* @throws ImportException
*/
public static function import(VersionEntry $versionEntry, array $options=[]): bool
{
$autoload_path = $versionEntry->getInstallPaths()->getBinPath() . DIRECTORY_SEPARATOR . 'autoload.php';
$static_files = $versionEntry->getInstallPaths()->getBinPath() . DIRECTORY_SEPARATOR . 'static_autoload.bin';
$constants_path = $versionEntry->getInstallPaths()->getDataPath() . DIRECTORY_SEPARATOR . 'const';
$assembly_path = $versionEntry->getInstallPaths()->getDataPath() . DIRECTORY_SEPARATOR . 'assembly';
if(!file_exists($assembly_path))
throw new ImportException('Cannot locate assembly file \'' . $assembly_path . '\'');
try
{
$assembly_content = ZiProto::decode(IO::fread($assembly_path));
$assembly = Assembly::fromArray($assembly_content);
}
catch(Exception $e)
{
throw new ImportException('Failed to load assembly file \'' . $assembly_path . '\': ' . $e->getMessage());
}
if(file_exists($constants_path))
{
try
{
$constants = ZiProto::decode(IO::fread($constants_path));
}
catch(Exception $e)
{
throw new ImportException('Failed to load constants file \'' . $constants_path . '\': ' . $e->getMessage());
}
foreach($constants as $name => $value)
{
$value = ConstantCompiler::compileRuntimeConstants($value);
try
{
Constants::register($assembly->Package, $name, $value, true);
}
catch (ConstantReadonlyException $e)
{
trigger_error('Constant \'' . $name . '\' is readonly (' . $assembly->Package . ')', E_USER_WARNING);
}
catch (InvalidConstantNameException $e)
{
throw new ImportException('Invalid constant name \'' . $name . '\' (' . $assembly->Package . ')', $e);
}
}
}
if(file_exists($autoload_path) && !in_array(RuntimeImportOptions::ImportAutoloader, $options))
{
require_once($autoload_path);
}
if(file_exists($static_files) && !in_array(RuntimeImportOptions::ImportStaticFiles, $options))
{
try
{
$static_files = ZiProto::decode(IO::fread($static_files));
foreach($static_files as $file)
require_once($file);
}
catch(Exception $e)
{
throw new ImportException('Failed to load static files: ' . $e->getMessage(), $e);
}
}
if(!file_exists($autoload_path) && !file_exists($static_files))
return false;
return true;
}
}

View file

@ -0,0 +1,56 @@
<?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\Classes\PythonExtension;
use ncc\Exceptions\FileNotFoundException;
use ncc\Interfaces\RunnerInterface;
use ncc\Objects\Package\ExecutionUnit;
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
use ncc\Utilities\IO;
class Python2Runner implements RunnerInterface
{
/**
* @inheritDoc
*/
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
{
$execution_unit = new ExecutionUnit();
if(!file_exists($path) && !is_file($path))
throw new FileNotFoundException($path);
$policy->Execute->Target = null;
$execution_unit->ExecutionPolicy = $policy;
$execution_unit->Data = IO::fread($path);
return $execution_unit;
}
/**
* @inheritDoc
*/
public static function getFileExtension(): string
{
return '.py';
}
}

View file

@ -0,0 +1,56 @@
<?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\Classes\PythonExtension;
use ncc\Exceptions\FileNotFoundException;
use ncc\Interfaces\RunnerInterface;
use ncc\Objects\Package\ExecutionUnit;
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
use ncc\Utilities\IO;
class Python3Runner implements RunnerInterface
{
/**
* @inheritDoc
*/
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
{
$execution_unit = new ExecutionUnit();
if(!file_exists($path) && !is_file($path))
throw new FileNotFoundException($path);
$policy->Execute->Target = null;
$execution_unit->ExecutionPolicy = $policy;
$execution_unit->Data = IO::fread($path);
return $execution_unit;
}
/**
* @inheritDoc
*/
public static function getFileExtension(): string
{
return '.py';
}
}

View file

@ -0,0 +1,56 @@
<?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\Classes\PythonExtension;
use ncc\Exceptions\FileNotFoundException;
use ncc\Interfaces\RunnerInterface;
use ncc\Objects\Package\ExecutionUnit;
use ncc\Objects\ProjectConfiguration\ExecutionPolicy;
use ncc\Utilities\IO;
class PythonRunner implements RunnerInterface
{
/**
* @inheritDoc
*/
public static function processUnit(string $path, ExecutionPolicy $policy): ExecutionUnit
{
$execution_unit = new ExecutionUnit();
if(!file_exists($path) && !is_file($path))
throw new FileNotFoundException($path);
$policy->Execute->Target = null;
$execution_unit->ExecutionPolicy = $policy;
$execution_unit->Data = IO::fread($path);
return $execution_unit;
}
/**
* @inheritDoc
*/
public static function getFileExtension(): string
{
return '.py';
}
}

View file

@ -1,6 +1,26 @@
<?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\Exceptions;
namespace ncc\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;

View file

@ -0,0 +1,39 @@
<?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\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
use Throwable;
class ArchiveException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::ArchiveException, $previous);
}
}

View file

@ -0,0 +1,39 @@
<?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\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
use Throwable;
class AuthenticationException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::AuthenticationException, $previous);
}
}

View file

@ -1,6 +1,26 @@
<?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\Exceptions;
namespace ncc\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;

View file

@ -1,8 +1,26 @@
<?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.
*
*/
/** @noinspection PhpPropertyOnlyWrittenInspection */
namespace ncc\Exceptions;
namespace ncc\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
@ -10,8 +28,6 @@
class BuildConfigurationNotFoundException extends Exception
{
private ?Throwable $previous;
/**
* @param string $message
* @param Throwable|null $previous
@ -19,7 +35,5 @@
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::BuildConfigurationNotFoundException, $previous);
$this->message = $message;
$this->previous = $previous;
}
}

View file

@ -1,8 +1,26 @@
<?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.
*
*/
/** @noinspection PhpPropertyOnlyWrittenInspection */
namespace ncc\Exceptions;
namespace ncc\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
@ -10,11 +28,6 @@
class BuildException extends Exception
{
/**
* @var Throwable|null
*/
private ?Throwable $previous;
/**
* @param string $message
* @param Throwable|null $previous
@ -22,7 +35,5 @@
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::BuildException, $previous);
$this->message = $message;
$this->previous = $previous;
}
}

View file

@ -1,8 +1,26 @@
<?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.
*
*/
/** @noinspection PhpPropertyOnlyWrittenInspection */
namespace ncc\Exceptions;
namespace ncc\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
@ -10,10 +28,6 @@
class ComponentChecksumException extends Exception
{
/**
* @var Throwable|null
*/
private ?Throwable $previous;
/**
* @param string $message
@ -22,7 +36,5 @@
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::ComponentChecksumException, $previous);
$this->message = $message;
$this->previous = $previous;
}
}

View file

@ -1,8 +1,26 @@
<?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.
*
*/
/** @noinspection PhpPropertyOnlyWrittenInspection */
namespace ncc\Exceptions;
namespace ncc\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
@ -10,11 +28,6 @@
class ComponentDecodeException extends Exception
{
/**
* @var Throwable|null
*/
private ?Throwable $previous;
/**
* @param string $message
* @param Throwable|null $previous
@ -22,7 +35,5 @@
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::ComponentDecodeException, $previous);
$this->message = $message;
$this->previous = $previous;
}
}

View file

@ -1,6 +1,26 @@
<?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\Exceptions;
namespace ncc\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;

View file

@ -1,19 +1,33 @@
<?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.
*
*/
/** @noinspection PhpPropertyOnlyWrittenInspection */
namespace ncc\Exceptions;
namespace ncc\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
use Throwable;
class ComposerDisabledException extends \Exception
class ComposerDisabledException extends Exception
{
/**
* @var Throwable|null
*/
private ?Throwable $previous;
/**
* @param string $message
* @param Throwable|null $previous
@ -21,7 +35,5 @@
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::ComposerDisabledException, $previous);
$this->message = $message;
$this->previous = $previous;
}
}

View file

@ -1,8 +1,26 @@
<?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.
*
*/
/** @noinspection PhpPropertyOnlyWrittenInspection */
namespace ncc\Exceptions;
namespace ncc\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
@ -10,11 +28,6 @@
class ComposerException extends Exception
{
/**
* @var Throwable|null
*/
private ?Throwable $previous;
/**
* @param string $message
* @param Throwable|null $previous
@ -22,7 +35,5 @@
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::ComposerException, $previous);
$this->message = $message;
$this->previous = $previous;
}
}

View file

@ -1,20 +1,32 @@
<?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.
*
*/
/** @noinspection PhpPropertyOnlyWrittenInspection */
/** @noinspection PhpMissingFieldTypeInspection */
namespace ncc\Exceptions;
namespace ncc\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
class ComposerNotAvailableException extends Exception
{
/**
* @var null
*/
private $previous;
/**
* @param string $message
* @param $previous
@ -22,7 +34,5 @@
public function __construct(string $message = "", $previous = null)
{
parent::__construct($message, ExceptionCodes::ComposerNotAvailableException, $previous);
$this->message = $message;
$this->previous = $previous;
}
}

View file

@ -1,6 +1,26 @@
<?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\Exceptions;
namespace ncc\Exceptions;
use Exception;

View file

@ -1,6 +1,26 @@
<?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\Exceptions;
namespace ncc\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
@ -17,6 +37,5 @@
public function __construct(string $path = "", ?Throwable $previous = null)
{
parent::__construct('The file \'' . realpath($path) . '\' was not found', ExceptionCodes::DirectoryNotFoundException, $previous);
$this->code = ExceptionCodes::DirectoryNotFoundException;
}
}

View file

@ -1,8 +0,0 @@
<?php
namespace ncc\Exceptions;
class ExecutionUnitNotFoundException extends \Exception
{
}

View file

@ -1,6 +1,26 @@
<?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\Exceptions;
namespace ncc\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
@ -19,6 +39,5 @@
public function __construct(string $path = "", ?Throwable $previous = null)
{
parent::__construct('The file \'' . realpath($path) . '\' was not found', ExceptionCodes::FileNotFoundException, $previous);
$this->code = ExceptionCodes::FileNotFoundException;
}
}

View file

@ -0,0 +1,39 @@
<?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\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
use Throwable;
class GitCheckoutException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::GitCheckoutException, $previous);
}
}

View file

@ -0,0 +1,39 @@
<?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\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
use Throwable;
class GitCloneException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::GitCloneException, $previous);
}
}

View file

@ -0,0 +1,39 @@
<?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\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
use Throwable;
class GitTagsException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::GitTagsException, $previous);
}
}

View file

@ -0,0 +1,39 @@
<?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\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
use Throwable;
class GithubServiceException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::GithubServiceException, $previous);
}
}

View file

@ -0,0 +1,39 @@
<?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\Exceptions;
use Exception;
use ncc\Abstracts\ExceptionCodes;
use Throwable;
class GitlabServiceException extends Exception
{
/**
* @param string $message
* @param Throwable|null $previous
*/
public function __construct(string $message = "", ?Throwable $previous = null)
{
parent::__construct($message, ExceptionCodes::GitlabServiceException, $previous);
}
}

Some files were not shown because too many files have changed in this diff Show more