Refactor ncc extension registration logic, this also allows for debian packages to install the ncc extension automatically.
The logic related to the registration of the ncc extension has been refactored. Previously, the code that registered the ncc extension was contained in the installer. However, this change moves the code that registers the ncc extension from the installer to the Utilities/Functions class. This change was made because the extension registration is not only applicable to the installer, but is also required for several other components. This fact justified the need for the logic to be located in a more generic and accessible class. The Makefile, installer, generate_build_files.php files have been updated to reflect this change. Components using these should now work properly with the changes.
This commit is contained in:
parent
89b0c931b9
commit
71214e769e
6 changed files with 64 additions and 80 deletions
|
@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Changed
|
||||
- Updated fetchPackage method to include authentication
|
||||
- Update dependencies import in \ncc\Classes > Runtime > importFromPackage()
|
||||
- Refactor ncc extension registration logic, this also allows for debian packages to install the ncc extension
|
||||
automatically.
|
||||
|
||||
### Fixed
|
||||
- Fixed issue where some build artifacts are being bundled with package builds such as `output_path` and `static`
|
||||
|
|
1
Makefile
1
Makefile
|
@ -76,7 +76,6 @@ redist: autoload
|
|||
cp -f $(CONFIG_PATH)/ncc.yaml $(GENERIC_BUILD_PATH)/CLI/template_config.yaml
|
||||
cp -f $(CONFIG_PATH)/default_repositories.json $(GENERIC_BUILD_PATH)/default_repositories.json
|
||||
cp -f $(INSTALLER_SRC_PATH)/ncc-package.xml $(GENERIC_BUILD_PATH)/ncc-package.xml
|
||||
cp -f $(INSTALLER_SRC_PATH)/extension $(GENERIC_BUILD_PATH)/extension
|
||||
chmod +x $(GENERIC_BUILD_PATH)/INSTALL
|
||||
cp -f LICENSE $(GENERIC_BUILD_PATH)/LICENSE
|
||||
cp -f README.md $(GENERIC_BUILD_PATH)/README.md
|
||||
|
|
|
@ -41,8 +41,7 @@
|
|||
'installer',
|
||||
'checksum.bin',
|
||||
'build_files',
|
||||
'ncc.sh',
|
||||
'extension'
|
||||
'ncc.sh'
|
||||
];
|
||||
|
||||
ncc\Utilities\Console::out('Creating build_files ...');
|
||||
|
|
|
@ -345,83 +345,6 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Register the ncc extension
|
||||
try
|
||||
{
|
||||
Console::out('Registering extension');
|
||||
$extension_shortcut = str_ireplace('%ncc_install', $NCC_INSTALL_PATH, IO::fread(__DIR__ . DIRECTORY_SEPARATOR . 'extension'));
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
Console::outException(sprintf('Failed to read file \'%s\', %s', __DIR__ . DIRECTORY_SEPARATOR . 'extension', $e->getMessage()), $e, 1);
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove all the old extensions first.
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
* @param Filesystem $filesystem
|
||||
* @param string $extension_shortcut
|
||||
* @return bool
|
||||
*/
|
||||
function install_extension(string $path, Filesystem $filesystem, string $extension_shortcut): bool
|
||||
{
|
||||
if ($filesystem->exists($path . DIRECTORY_SEPARATOR . 'ncc'))
|
||||
{
|
||||
$filesystem->remove($path . DIRECTORY_SEPARATOR . 'ncc');
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
IO::fwrite($path . DIRECTORY_SEPARATOR . 'ncc', $extension_shortcut);
|
||||
}
|
||||
catch (\ncc\Exceptions\IOException $e)
|
||||
{
|
||||
Console::outException($e->getMessage(), $e, 1);
|
||||
return false;
|
||||
}
|
||||
|
||||
return $filesystem->exists($path . DIRECTORY_SEPARATOR . 'ncc');
|
||||
}
|
||||
|
||||
if(function_exists('get_include_path'))
|
||||
{
|
||||
$default_share = DIRECTORY_SEPARATOR . 'usr' . DIRECTORY_SEPARATOR . 'share' . DIRECTORY_SEPARATOR . 'php';
|
||||
$include_paths = explode(':', get_include_path());
|
||||
$extension_registered = false;
|
||||
|
||||
if(!in_array($default_share, $include_paths))
|
||||
{
|
||||
foreach($include_paths as $path)
|
||||
{
|
||||
if($extension_registered)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
switch($path)
|
||||
{
|
||||
// Ignore local files
|
||||
case '.':
|
||||
case '..':
|
||||
break;
|
||||
|
||||
// First real include path is /usr/share/php
|
||||
default:
|
||||
// Install the extension
|
||||
$extension_registered = install_extension($path, $NCC_FILESYSTEM, $extension_shortcut);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove the old extension
|
||||
install_extension($default_share, $NCC_FILESYSTEM, $extension_shortcut);
|
||||
}
|
||||
}
|
||||
|
||||
// Backup the configuration file
|
||||
$config_backup = null;
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
use ncc\Enums\Scopes;
|
||||
use ncc\Enums\Versions;
|
||||
use ncc\Exceptions\IOException;
|
||||
use ncc\Exceptions\NotSupportedException;
|
||||
use ncc\Exceptions\OperationException;
|
||||
use ncc\Exceptions\PathNotFoundException;
|
||||
use ncc\Managers\ConfigurationManager;
|
||||
|
@ -338,6 +339,66 @@
|
|||
{
|
||||
throw new OperationException('Failed to initialize repository database, ' . $e->getMessage(), $e);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
self::registerExtension($filesystem);
|
||||
}
|
||||
catch(Exception $e)
|
||||
{
|
||||
throw new OperationException('Failed to register ncc extension, ' . $e->getMessage(), $e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the ncc extension with the given filesystem.
|
||||
*
|
||||
* @param Filesystem $filesystem The filesystem object used for file operations.
|
||||
* @throws IOException If the extension cannot be registered.
|
||||
* @throws NotSupportedException If `get_include_path()` function is not available.
|
||||
* @throws PathNotFoundException If the default include path is not available.
|
||||
*/
|
||||
private static function registerExtension(Filesystem $filesystem): void
|
||||
{
|
||||
if(!function_exists('get_include_path'))
|
||||
{
|
||||
throw new NotSupportedException('Cannot register ncc extension, get_include_path() is not available');
|
||||
}
|
||||
|
||||
$default_share = DIRECTORY_SEPARATOR . 'usr' . DIRECTORY_SEPARATOR . 'share' . DIRECTORY_SEPARATOR . 'php';
|
||||
$include_paths = explode(':', get_include_path());
|
||||
$extension = str_ireplace('%ncc_install', NCC_EXEC_LOCATION, IO::fread(__DIR__ . DIRECTORY_SEPARATOR . 'extension'));
|
||||
|
||||
if(in_array($default_share, $include_paths))
|
||||
{
|
||||
if($filesystem->exists($default_share . DIRECTORY_SEPARATOR . 'ncc'))
|
||||
{
|
||||
$filesystem->remove($default_share . DIRECTORY_SEPARATOR . 'ncc');
|
||||
}
|
||||
|
||||
IO::fwrite($default_share . DIRECTORY_SEPARATOR . 'ncc', $extension);
|
||||
return;
|
||||
}
|
||||
|
||||
foreach($include_paths as $include_path)
|
||||
{
|
||||
try
|
||||
{
|
||||
if($filesystem->exists($include_path . DIRECTORY_SEPARATOR . 'ncc'))
|
||||
{
|
||||
$filesystem->remove($include_path . DIRECTORY_SEPARATOR . 'ncc');
|
||||
}
|
||||
|
||||
IO::fwrite($include_path . DIRECTORY_SEPARATOR . 'ncc', $extension);
|
||||
return;
|
||||
}
|
||||
catch(IOException $e)
|
||||
{
|
||||
Console::outWarning(sprintf('Failed to register ncc extension in %s: %s', $include_path, $e->getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
throw new IOException('Cannot register ncc extension, no include path is available');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue