Added path resolver system
This commit is contained in:
parent
5fb82027e1
commit
643f49a2de
14 changed files with 594 additions and 5 deletions
2
Makefile
Normal file
2
Makefile
Normal file
|
@ -0,0 +1,2 @@
|
|||
autoload:
|
||||
phpab --output src/ncc/autoload.php src/ncc
|
14
README.md
14
README.md
|
@ -2,11 +2,15 @@
|
|||
|
||||
Nosial Code Compiler is a program written in PHP designed to be a multi-purpose compiler, package manager and toolkit.
|
||||
|
||||
# Copyright
|
||||
- Copyright (C) 2022-2022. Nosial - All Rights Reserved.
|
||||
- Copyright (c) 2015-2016 PHP School
|
||||
- Copyright (c) 2011-2013, Benjamin Eberlei All rights reserved.
|
||||
- Copyright (c) 2004-2022 Fabien Potencier
|
||||
## Authors
|
||||
- Zi Xing Narrakas (netkas) <[netkas@n64.cc](mailto:netkas@64.cc)>
|
||||
- Marc Gutt (mgutt) <[marc@gutt.it](mailto:marc@gutt.it)>
|
||||
|
||||
## Copyright
|
||||
- Copyright (c) 2022-2022, Nosial - All Rights Reserved
|
||||
- Copyright (c) 2015-2016, PHP School
|
||||
- Copyright (c) 2011-2013, Benjamin Eberlei - All rights reserved
|
||||
- Copyright (c) 2004-2022, Fabien Potencier
|
||||
|
||||
# Licenses
|
||||
|
||||
|
|
|
@ -2,8 +2,11 @@
|
|||
|
||||
namespace ncc\Abstracts;
|
||||
|
||||
use ncc\Exceptions\AccessDeniedException;
|
||||
use ncc\Exceptions\DirectoryNotFoundException;
|
||||
use ncc\Exceptions\FileNotFoundException;
|
||||
use ncc\Exceptions\InvalidProjectConfigurationException;
|
||||
use ncc\Exceptions\InvalidScopeException;
|
||||
|
||||
/**
|
||||
* @author Zi Xing Narrakas
|
||||
|
@ -20,4 +23,19 @@
|
|||
* @see FileNotFoundException;
|
||||
*/
|
||||
const FileNotFoundException = -1701;
|
||||
|
||||
/**
|
||||
* @see DirectoryNotFoundException
|
||||
*/
|
||||
const DirectoryNotFoundException = -1702;
|
||||
|
||||
/**
|
||||
* @see InvalidScopeException
|
||||
*/
|
||||
const InvalidScopeException = -1703;
|
||||
|
||||
/**
|
||||
* @see AccessDeniedException
|
||||
*/
|
||||
const AccessDeniedException = -1704;
|
||||
}
|
12
src/ncc/Abstracts/Scopes.php
Normal file
12
src/ncc/Abstracts/Scopes.php
Normal file
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace ncc\Abstracts;
|
||||
|
||||
abstract class Scopes
|
||||
{
|
||||
const Auto = 'AUTO';
|
||||
|
||||
const User = 'USER';
|
||||
|
||||
const System = 'SYSTEM';
|
||||
}
|
19
src/ncc/Exceptions/AccessDeniedException.php
Normal file
19
src/ncc/Exceptions/AccessDeniedException.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace ncc\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use ncc\Abstracts\ExceptionCodes;
|
||||
use Throwable;
|
||||
|
||||
class AccessDeniedException extends Exception
|
||||
{
|
||||
/**
|
||||
* @param string $message
|
||||
* @param Throwable|null $previous
|
||||
*/
|
||||
public function __construct(string $message = "", ?Throwable $previous = null)
|
||||
{
|
||||
parent::__construct($message, ExceptionCodes::AccessDeniedException, $previous);
|
||||
}
|
||||
}
|
22
src/ncc/Exceptions/DirectoryNotFoundException.php
Normal file
22
src/ncc/Exceptions/DirectoryNotFoundException.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace ncc\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use ncc\Abstracts\ExceptionCodes;
|
||||
use Throwable;
|
||||
|
||||
class DirectoryNotFoundException extends Exception
|
||||
{
|
||||
/**
|
||||
* Public Constructor
|
||||
*
|
||||
* @param string $path
|
||||
* @param Throwable|null $previous
|
||||
*/
|
||||
public function __construct(string $path = "", ?Throwable $previous = null)
|
||||
{
|
||||
parent::__construct('The file \'' . realpath($path) . '\' was not found', ExceptionCodes::DirectoryNotFoundException, $previous);
|
||||
$this->code = ExceptionCodes::DirectoryNotFoundException;
|
||||
}
|
||||
}
|
21
src/ncc/Exceptions/InvalidScopeException.php
Normal file
21
src/ncc/Exceptions/InvalidScopeException.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace ncc\Exceptions;
|
||||
|
||||
use Exception;
|
||||
use ncc\Abstracts\ExceptionCodes;
|
||||
use Throwable;
|
||||
|
||||
class InvalidScopeException extends Exception
|
||||
{
|
||||
/**
|
||||
* Public Constructor
|
||||
*
|
||||
* @param string $scope
|
||||
* @param Throwable|null $previous
|
||||
*/
|
||||
public function __construct(string $scope = "", ?Throwable $previous = null)
|
||||
{
|
||||
parent::__construct('The given scope \'' . $scope . '\' is not valid', ExceptionCodes::InvalidScopeException, $previous);
|
||||
}
|
||||
}
|
252
src/ncc/Utilities/PathFinder.php
Normal file
252
src/ncc/Utilities/PathFinder.php
Normal file
|
@ -0,0 +1,252 @@
|
|||
<?php
|
||||
|
||||
namespace ncc\Utilities;
|
||||
|
||||
use ncc\Abstracts\Scopes;
|
||||
use ncc\Exceptions\InvalidScopeException;
|
||||
|
||||
class PathFinder
|
||||
{
|
||||
/**
|
||||
* Returns the root path of the system
|
||||
*
|
||||
* @param bool $win32
|
||||
* @return string
|
||||
*/
|
||||
public static function getRootPath(bool $win32=false): string
|
||||
{
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN' && $win32)
|
||||
return "C:/"; // Emulation for unix only
|
||||
|
||||
return realpath(DIRECTORY_SEPARATOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path for where NCC is installed
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getInstallationPath(): string
|
||||
{
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
|
||||
{
|
||||
return realpath(self::getRootPath() . DIRECTORY_SEPARATOR . 'ncc');
|
||||
}
|
||||
|
||||
return realpath(self::getRootPath() . DIRECTORY_SEPARATOR . 'etc' . DIRECTORY_SEPARATOR . 'ncc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the home directory of the user
|
||||
*
|
||||
* @param string $scope
|
||||
* @param bool $win32
|
||||
* @return string
|
||||
* @throws InvalidScopeException
|
||||
*/
|
||||
public static function getHomePath(string $scope=Scopes::Auto, bool $win32=false): string
|
||||
{
|
||||
$scope = Resolver::resolveScope($scope);
|
||||
|
||||
if(!Validate::scope($scope, false))
|
||||
{
|
||||
throw new InvalidScopeException($scope);
|
||||
}
|
||||
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' || $win32)
|
||||
{
|
||||
switch($scope)
|
||||
{
|
||||
case Scopes::User:
|
||||
return self::getRootPath($win32) . 'ncc' . DIRECTORY_SEPARATOR . 'user_home';
|
||||
case Scopes::System:
|
||||
return self::getRootPath($win32) . 'ncc' . DIRECTORY_SEPARATOR . 'system_home';
|
||||
}
|
||||
}
|
||||
|
||||
switch($scope)
|
||||
{
|
||||
case Scopes::User:
|
||||
$uid = posix_getuid();
|
||||
return posix_getpwuid($uid)['dir'] . DIRECTORY_SEPARATOR . '.ncc';
|
||||
|
||||
case Scopes::System:
|
||||
return posix_getpwuid(0)['dir'] . DIRECTORY_SEPARATOR . '.ncc';
|
||||
}
|
||||
|
||||
throw new InvalidScopeException($scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path where all NCC installation data is stored
|
||||
*
|
||||
* @param string $scope
|
||||
* @param bool $win32
|
||||
* @return string
|
||||
* @throws InvalidScopeException
|
||||
*/
|
||||
public static function getDataPath(string $scope=Scopes::Auto, bool $win32=false): string
|
||||
{
|
||||
$scope = Resolver::resolveScope($scope);
|
||||
|
||||
if(!Validate::scope($scope, false))
|
||||
{
|
||||
throw new InvalidScopeException($scope);
|
||||
}
|
||||
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' || $win32)
|
||||
{
|
||||
switch($scope)
|
||||
{
|
||||
case Scopes::User:
|
||||
return self::getRootPath($win32) . 'ncc' . DIRECTORY_SEPARATOR . 'user';
|
||||
case Scopes::System:
|
||||
return self::getRootPath($win32) . 'ncc' . DIRECTORY_SEPARATOR . 'system';
|
||||
}
|
||||
}
|
||||
|
||||
switch($scope)
|
||||
{
|
||||
case Scopes::User:
|
||||
$uid = posix_getuid();
|
||||
return posix_getpwuid($uid)['dir'] . DIRECTORY_SEPARATOR . '.ncc' . DIRECTORY_SEPARATOR . 'data';
|
||||
|
||||
case Scopes::System:
|
||||
return self::getRootPath() . 'var' . DIRECTORY_SEPARATOR . 'ncc';
|
||||
}
|
||||
|
||||
throw new InvalidScopeException($scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path where packages are installed
|
||||
*
|
||||
* @param string $scope
|
||||
* @param bool $win32
|
||||
* @return string
|
||||
* @throws InvalidScopeException
|
||||
*/
|
||||
public static function getPackagesPath(string $scope=Scopes::Auto, bool $win32=false): string
|
||||
{
|
||||
return self::getDataPath($scope, $win32) . DIRECTORY_SEPARATOR . 'packages';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path where cache files are stored
|
||||
*
|
||||
* @param string $scope
|
||||
* @param bool $win32
|
||||
* @return string
|
||||
* @throws InvalidScopeException
|
||||
*/
|
||||
public static function getCachePath(string $scope=Scopes::Auto, bool $win32=false): string
|
||||
{
|
||||
return self::getDataPath($scope, $win32) . DIRECTORY_SEPARATOR . 'cache';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the path where temporary files are stored
|
||||
*
|
||||
* @param string $scope
|
||||
* @param bool $win32
|
||||
* @return string
|
||||
* @throws InvalidScopeException
|
||||
*/
|
||||
public static function getTmpPath(string $scope=Scopes::Auto, bool $win32=false): string
|
||||
{
|
||||
return self::getDataPath($scope, $win32) . DIRECTORY_SEPARATOR . 'tmp';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the configuration file
|
||||
*
|
||||
* @param string $scope
|
||||
* @param bool $win32
|
||||
* @return string
|
||||
* @throws InvalidScopeException
|
||||
*/
|
||||
public static function getConfigurationFile(string $scope=Scopes::Auto, bool $win32=false): string
|
||||
{
|
||||
return self::getDataPath($scope, $win32) . DIRECTORY_SEPARATOR . 'config';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all the configuration files the current user can access (For global-cross referencing)
|
||||
*
|
||||
* @param bool $win32
|
||||
* @return array
|
||||
* @throws InvalidScopeException
|
||||
*/
|
||||
public static function getConfigurationFiles(bool $win32=false): array
|
||||
{
|
||||
$results = [];
|
||||
$results[] = self::getConfigurationFile(Scopes::System, $win32);
|
||||
|
||||
if(!in_array(self::getConfigurationFile(Scopes::User, $win32), $results))
|
||||
{
|
||||
$results[] = self::getConfigurationFile(Scopes::User, $win32);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the package lock file
|
||||
*
|
||||
* @param string $scope
|
||||
* @param bool $win32
|
||||
* @return string
|
||||
* @throws InvalidScopeException
|
||||
*/
|
||||
public static function getPackageLock(string $scope=Scopes::Auto, bool $win32=false): string
|
||||
{
|
||||
return self::getDataPath($scope, $win32) . DIRECTORY_SEPARATOR . 'package.lck';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all the package lock files the current user can access (For global-cross referencing)
|
||||
*
|
||||
* @param bool $win32
|
||||
* @return array
|
||||
* @throws InvalidScopeException
|
||||
*/
|
||||
public static function getPackageLockFiles(bool $win32=false): array
|
||||
{
|
||||
$results = [];
|
||||
$results[] = self::getPackageLock(Scopes::System, $win32);
|
||||
|
||||
if(!in_array(self::getPackageLock(Scopes::User, $win32), $results))
|
||||
{
|
||||
$results[] = self::getPackageLock(Scopes::User, $win32);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file path where files for the given extension is stored
|
||||
*
|
||||
* @param string $scope
|
||||
* @param bool $win32
|
||||
* @return string
|
||||
* @throws InvalidScopeException
|
||||
*/
|
||||
public static function getExtensionPath(string $scope=Scopes::Auto, bool $win32=false): string
|
||||
{
|
||||
return self::getDataPath($scope, $win32) . DIRECTORY_SEPARATOR . 'ext';
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the file path where files for the given extension is stored
|
||||
*
|
||||
* @param string $extension_name
|
||||
* @param string $scope
|
||||
* @param bool $win32
|
||||
* @return string
|
||||
* @throws InvalidScopeException
|
||||
*/
|
||||
public static function getNamedExtensionPath(string $extension_name, string $scope=Scopes::Auto, bool $win32=false): string
|
||||
{
|
||||
return self::getExtensionPath($scope, $win32) . DIRECTORY_SEPARATOR . Security::sanitizeFilename($extension_name);
|
||||
}
|
||||
}
|
44
src/ncc/Utilities/Resolver.php
Normal file
44
src/ncc/Utilities/Resolver.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
|
||||
namespace ncc\Utilities;
|
||||
|
||||
use ncc\Abstracts\Scopes;
|
||||
|
||||
class Resolver
|
||||
{
|
||||
/**
|
||||
* @param string|null $input
|
||||
* @return string
|
||||
*/
|
||||
public static function resolveScope(?string $input=null): string
|
||||
{
|
||||
// Set the scope to automatic if it's null
|
||||
if($input == null)
|
||||
{
|
||||
$input = Scopes::Auto;
|
||||
}
|
||||
|
||||
$input = strtoupper($input);
|
||||
|
||||
// Resolve the scope if it's set to automatic
|
||||
if($input == Scopes::Auto)
|
||||
{
|
||||
if(posix_getuid() == 0)
|
||||
{
|
||||
$input = Scopes::System;
|
||||
}
|
||||
else
|
||||
{
|
||||
$input = Scopes::User;
|
||||
}
|
||||
}
|
||||
|
||||
// Auto-Correct the scope if the current user ID is 0
|
||||
if($input == Scopes::User && posix_getuid() == 0)
|
||||
{
|
||||
$input = Scopes::System;
|
||||
}
|
||||
|
||||
return $input;
|
||||
}
|
||||
}
|
64
src/ncc/Utilities/Security.php
Normal file
64
src/ncc/Utilities/Security.php
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?php
|
||||
|
||||
namespace ncc\Utilities;
|
||||
|
||||
class Security
|
||||
{
|
||||
/**
|
||||
* @param string $input
|
||||
* @param bool $beautify
|
||||
* @return string
|
||||
* @author Marc Gutt <marc@gutt.it>
|
||||
*/
|
||||
public static function sanitizeFilename(string $input, bool $beautify=true): string
|
||||
{
|
||||
// sanitize filename
|
||||
$input = preg_replace(
|
||||
'~
|
||||
[<>:"/\\\|?*]| # file system reserved https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words
|
||||
[\x00-\x1F]| # control characters http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx
|
||||
[\x7F\xA0\xAD]| # non-printing characters DEL, NO-BREAK SPACE, SOFT HYPHEN
|
||||
[#\[\]@!$&\'()+,;=]| # URI reserved https://www.rfc-editor.org/rfc/rfc3986#section-2.2
|
||||
[{}^\~`] # URL unsafe characters https://www.ietf.org/rfc/rfc1738.txt
|
||||
~x',
|
||||
'-', $input);
|
||||
// avoids ".", ".." or ".hiddenFiles"
|
||||
$input = ltrim($input, '.-');
|
||||
// optional beautification
|
||||
if ($beautify) $input = self::beautifyFilename($input);
|
||||
// maximize filename length to 255 bytes http://serverfault.com/a/9548/44086
|
||||
$ext = pathinfo($input, PATHINFO_EXTENSION);
|
||||
$input = mb_strcut(pathinfo($input, PATHINFO_FILENAME), 0, 255 - ($ext ? strlen($ext) + 1 : 0), mb_detect_encoding($input)) . ($ext ? '.' . $ext : '');
|
||||
return $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $input
|
||||
* @return string
|
||||
* @author Marc Gutt <marc@gutt.it>
|
||||
*/
|
||||
public static function beautifyFilename(string $input): string
|
||||
{
|
||||
// reduce consecutive characters
|
||||
$input = preg_replace(array(
|
||||
// "file name.zip" becomes "file-name.zip"
|
||||
'/ +/',
|
||||
// "file___name.zip" becomes "file-name.zip"
|
||||
'/_+/',
|
||||
// "file---name.zip" becomes "file-name.zip"
|
||||
'/-+/'
|
||||
), '-', $input);
|
||||
$input = preg_replace(array(
|
||||
// "file--.--.-.--name.zip" becomes "file.name.zip"
|
||||
'/-*\.-*/',
|
||||
// "file...name..zip" becomes "file.name.zip"
|
||||
'/\.{2,}/'
|
||||
), '.', $input);
|
||||
// lowercase for windows/unix interoperability http://support.microsoft.com/kb/100625
|
||||
$input = mb_strtolower($input, mb_detect_encoding($input));
|
||||
// ".file-name.-" becomes "file-name"
|
||||
$input = trim($input, '.-');
|
||||
|
||||
return $input;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,8 @@
|
|||
namespace ncc\Utilities;
|
||||
|
||||
use ncc\Abstracts\RegexPatterns;
|
||||
use ncc\Abstracts\Scopes;
|
||||
use ncc\Exceptions\AccessDeniedException;
|
||||
|
||||
/**
|
||||
* @author Zi Xing Narrakas
|
||||
|
@ -29,4 +31,46 @@
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the scope
|
||||
*
|
||||
* @param string $input
|
||||
* @param bool $resolve
|
||||
* @return bool
|
||||
* @noinspection PhpSwitchCanBeReplacedWithMatchExpressionInspection
|
||||
*/
|
||||
public static function scope(string $input, bool $resolve=true): bool
|
||||
{
|
||||
if($resolve)
|
||||
{
|
||||
$input = Resolver::resolveScope($input);
|
||||
}
|
||||
|
||||
switch($input)
|
||||
{
|
||||
case Scopes::System:
|
||||
case Scopes::User:
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if the user has access to the given scope permission
|
||||
*
|
||||
* @param string|null $input
|
||||
* @return bool
|
||||
*/
|
||||
public static function scopePermission(?string $input=null): bool
|
||||
{
|
||||
$input = Resolver::resolveScope($input);
|
||||
|
||||
if($input == Scopes::System && posix_getuid() !== 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ spl_autoload_register(
|
|||
$classes = array(
|
||||
'ncc\\abstracts\\exceptioncodes' => '/Abstracts/ExceptionCodes.php',
|
||||
'ncc\\abstracts\\regexpatterns' => '/Abstracts/RegexPatterns.php',
|
||||
'ncc\\abstracts\\scopes' => '/Abstracts/Scopes.php',
|
||||
'ncc\\assert\\assert' => '/ThirdParty/beberlei/assert/Assert.php',
|
||||
'ncc\\assert\\assertion' => '/ThirdParty/beberlei/assert/Assertion.php',
|
||||
'ncc\\assert\\assertionchain' => '/ThirdParty/beberlei/assert/AssertionChain.php',
|
||||
|
@ -16,8 +17,11 @@ spl_autoload_register(
|
|||
'ncc\\assert\\invalidargumentexception' => '/ThirdParty/beberlei/assert/InvalidArgumentException.php',
|
||||
'ncc\\assert\\lazyassertion' => '/ThirdParty/beberlei/assert/LazyAssertion.php',
|
||||
'ncc\\assert\\lazyassertionexception' => '/ThirdParty/beberlei/assert/LazyAssertionException.php',
|
||||
'ncc\\exceptions\\accessdeniedexception' => '/Exceptions/AccessDeniedException.php',
|
||||
'ncc\\exceptions\\directorynotfoundexception' => '/Exceptions/DirectoryNotFoundException.php',
|
||||
'ncc\\exceptions\\filenotfoundexception' => '/Exceptions/FileNotFoundException.php',
|
||||
'ncc\\exceptions\\invalidprojectconfigurationexception' => '/Exceptions/InvalidProjectConfigurationException.php',
|
||||
'ncc\\exceptions\\invalidscopeexception' => '/Exceptions/InvalidScopeException.php',
|
||||
'ncc\\ncc' => '/ncc.php',
|
||||
'ncc\\objects\\projectconfiguration' => '/Objects/ProjectConfiguration.php',
|
||||
'ncc\\objects\\projectconfiguration\\assembly' => '/Objects/ProjectConfiguration/Assembly.php',
|
||||
|
@ -97,6 +101,9 @@ spl_autoload_register(
|
|||
'ncc\\symfony\\component\\process\\process' => '/ThirdParty/Symfony/Process/Process.php',
|
||||
'ncc\\symfony\\component\\process\\processutils' => '/ThirdParty/Symfony/Process/ProcessUtils.php',
|
||||
'ncc\\utilities\\functions' => '/Utilities/Functions.php',
|
||||
'ncc\\utilities\\pathfinder' => '/Utilities/PathFinder.php',
|
||||
'ncc\\utilities\\resolver' => '/Utilities/Resolver.php',
|
||||
'ncc\\utilities\\security' => '/Utilities/Security.php',
|
||||
'ncc\\utilities\\validate' => '/Utilities/Validate.php'
|
||||
);
|
||||
}
|
||||
|
|
75
tests/utils/pathfinder.php
Normal file
75
tests/utils/pathfinder.php
Normal file
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
|
||||
require(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'autoload.php');
|
||||
|
||||
print('Unix Root Directory: ' . \ncc\Utilities\PathFinder::getRootPath(false) . PHP_EOL);
|
||||
print('Win32 Root Directory: ' . \ncc\Utilities\PathFinder::getRootPath(true) . PHP_EOL);
|
||||
print(PHP_EOL);
|
||||
|
||||
print('Unix Home Directory (Auto): ' . \ncc\Utilities\PathFinder::getHomePath(\ncc\Abstracts\Scopes::Auto, false) . PHP_EOL);
|
||||
print('Unix Home Directory (User): ' . \ncc\Utilities\PathFinder::getHomePath(\ncc\Abstracts\Scopes::User, false) . PHP_EOL);
|
||||
print('Unix Home Directory (System): ' . \ncc\Utilities\PathFinder::getHomePath(\ncc\Abstracts\Scopes::System, false) . PHP_EOL);
|
||||
print('Win32 Home Directory (Auto): ' . \ncc\Utilities\PathFinder::getHomePath(\ncc\Abstracts\Scopes::Auto, true) . PHP_EOL);
|
||||
print('Win32 Home Directory (User): ' . \ncc\Utilities\PathFinder::getHomePath(\ncc\Abstracts\Scopes::User, true) . PHP_EOL);
|
||||
print('Win32 Home Directory (System): ' . \ncc\Utilities\PathFinder::getHomePath(\ncc\Abstracts\Scopes::System, true) . PHP_EOL);
|
||||
print(PHP_EOL);
|
||||
|
||||
print('Unix Data Directory (Auto): ' . \ncc\Utilities\PathFinder::getDataPath(\ncc\Abstracts\Scopes::Auto, false) . PHP_EOL);
|
||||
print('Unix Data Directory (User): ' . \ncc\Utilities\PathFinder::getDataPath(\ncc\Abstracts\Scopes::User, false) . PHP_EOL);
|
||||
print('Unix Data Directory (System): ' . \ncc\Utilities\PathFinder::getDataPath(\ncc\Abstracts\Scopes::System, false) . PHP_EOL);
|
||||
print('Win32 Data Directory (Auto): ' . \ncc\Utilities\PathFinder::getDataPath(\ncc\Abstracts\Scopes::Auto, true) . PHP_EOL);
|
||||
print('Win32 Data Directory (User): ' . \ncc\Utilities\PathFinder::getDataPath(\ncc\Abstracts\Scopes::User, true) . PHP_EOL);
|
||||
print('Win32 Data Directory (System): ' . \ncc\Utilities\PathFinder::getDataPath(\ncc\Abstracts\Scopes::System, true) . PHP_EOL);
|
||||
print(PHP_EOL);
|
||||
|
||||
print('Unix Packages Directory (Auto): ' . \ncc\Utilities\PathFinder::getPackagesPath(\ncc\Abstracts\Scopes::Auto, false) . PHP_EOL);
|
||||
print('Unix Packages Directory (User): ' . \ncc\Utilities\PathFinder::getPackagesPath(\ncc\Abstracts\Scopes::User, false) . PHP_EOL);
|
||||
print('Unix Packages Directory (System): ' . \ncc\Utilities\PathFinder::getPackagesPath(\ncc\Abstracts\Scopes::System, false) . PHP_EOL);
|
||||
print('Win32 Packages Directory (Auto): ' . \ncc\Utilities\PathFinder::getPackagesPath(\ncc\Abstracts\Scopes::Auto, true) . PHP_EOL);
|
||||
print('Win32 Packages Directory (User): ' . \ncc\Utilities\PathFinder::getPackagesPath(\ncc\Abstracts\Scopes::User, true) . PHP_EOL);
|
||||
print('Win32 Packages Directory (System): ' . \ncc\Utilities\PathFinder::getPackagesPath(\ncc\Abstracts\Scopes::System, true) . PHP_EOL);
|
||||
print(PHP_EOL);
|
||||
|
||||
print('Unix Cache Directory (Auto): ' . \ncc\Utilities\PathFinder::getCachePath(\ncc\Abstracts\Scopes::Auto, false) . PHP_EOL);
|
||||
print('Unix Cache Directory (User): ' . \ncc\Utilities\PathFinder::getCachePath(\ncc\Abstracts\Scopes::User, false) . PHP_EOL);
|
||||
print('Unix Cache Directory (System): ' . \ncc\Utilities\PathFinder::getCachePath(\ncc\Abstracts\Scopes::System, false) . PHP_EOL);
|
||||
print('Win32 Cache Directory (Auto): ' . \ncc\Utilities\PathFinder::getCachePath(\ncc\Abstracts\Scopes::Auto, true) . PHP_EOL);
|
||||
print('Win32 Cache Directory (User): ' . \ncc\Utilities\PathFinder::getCachePath(\ncc\Abstracts\Scopes::User, true) . PHP_EOL);
|
||||
print('Win32 Cache Directory (System): ' . \ncc\Utilities\PathFinder::getCachePath(\ncc\Abstracts\Scopes::System, true) . PHP_EOL);
|
||||
print(PHP_EOL);
|
||||
|
||||
print('Unix Tmp Directory (Auto): ' . \ncc\Utilities\PathFinder::getTmpPath(\ncc\Abstracts\Scopes::Auto, false) . PHP_EOL);
|
||||
print('Unix Tmp Directory (User): ' . \ncc\Utilities\PathFinder::getTmpPath(\ncc\Abstracts\Scopes::User, false) . PHP_EOL);
|
||||
print('Unix Tmp Directory (System): ' . \ncc\Utilities\PathFinder::getTmpPath(\ncc\Abstracts\Scopes::System, false) . PHP_EOL);
|
||||
print('Win32 Tmp Directory (Auto): ' . \ncc\Utilities\PathFinder::getTmpPath(\ncc\Abstracts\Scopes::Auto, true) . PHP_EOL);
|
||||
print('Win32 Tmp Directory (User): ' . \ncc\Utilities\PathFinder::getTmpPath(\ncc\Abstracts\Scopes::User, true) . PHP_EOL);
|
||||
print('Win32 Tmp Directory (System): ' . \ncc\Utilities\PathFinder::getTmpPath(\ncc\Abstracts\Scopes::System, true) . PHP_EOL);
|
||||
print(PHP_EOL);
|
||||
|
||||
print('Unix Extension Directory (Auto): ' . \ncc\Utilities\PathFinder::getExtensionPath(\ncc\Abstracts\Scopes::Auto, false) . PHP_EOL);
|
||||
print('Unix Extension Directory (User): ' . \ncc\Utilities\PathFinder::getExtensionPath(\ncc\Abstracts\Scopes::User, false) . PHP_EOL);
|
||||
print('Unix Extension Directory (System): ' . \ncc\Utilities\PathFinder::getExtensionPath(\ncc\Abstracts\Scopes::System, false) . PHP_EOL);
|
||||
print('Win32 Extension Directory (Auto): ' . \ncc\Utilities\PathFinder::getExtensionPath(\ncc\Abstracts\Scopes::Auto, true) . PHP_EOL);
|
||||
print('Win32 Extension Directory (User): ' . \ncc\Utilities\PathFinder::getExtensionPath(\ncc\Abstracts\Scopes::User, true) . PHP_EOL);
|
||||
print('Win32 Extension Directory (System): ' . \ncc\Utilities\PathFinder::getExtensionPath(\ncc\Abstracts\Scopes::System, true) . PHP_EOL);
|
||||
print(PHP_EOL);
|
||||
|
||||
print('Unix Configuration File (Auto): ' . \ncc\Utilities\PathFinder::getConfigurationFile(\ncc\Abstracts\Scopes::Auto, false) . PHP_EOL);
|
||||
print('Unix Configuration File (User): ' . \ncc\Utilities\PathFinder::getConfigurationFile(\ncc\Abstracts\Scopes::User, false) . PHP_EOL);
|
||||
print('Unix Configuration File (System): ' . \ncc\Utilities\PathFinder::getConfigurationFile(\ncc\Abstracts\Scopes::System, false) . PHP_EOL);
|
||||
print('Unix Configuration File(s): ' . json_encode(\ncc\Utilities\PathFinder::getConfigurationFiles(false), JSON_UNESCAPED_SLASHES) . PHP_EOL);
|
||||
print('Win32 Configuration File (Auto): ' . \ncc\Utilities\PathFinder::getConfigurationFile(\ncc\Abstracts\Scopes::Auto, true) . PHP_EOL);
|
||||
print('Win32 Configuration File (User): ' . \ncc\Utilities\PathFinder::getConfigurationFile(\ncc\Abstracts\Scopes::User, true) . PHP_EOL);
|
||||
print('Win32 Configuration File (System): ' . \ncc\Utilities\PathFinder::getConfigurationFile(\ncc\Abstracts\Scopes::System, true) . PHP_EOL);
|
||||
print('Win32 Configuration File(s): ' . json_encode(\ncc\Utilities\PathFinder::getConfigurationFiles(true), JSON_UNESCAPED_SLASHES) . PHP_EOL);
|
||||
print(PHP_EOL);
|
||||
|
||||
print('Unix Package Lock (Auto): ' . \ncc\Utilities\PathFinder::getPackageLock(\ncc\Abstracts\Scopes::Auto, false) . PHP_EOL);
|
||||
print('Unix Package Lock (User): ' . \ncc\Utilities\PathFinder::getPackageLock(\ncc\Abstracts\Scopes::User, false) . PHP_EOL);
|
||||
print('Unix Package Lock (System): ' . \ncc\Utilities\PathFinder::getPackageLock(\ncc\Abstracts\Scopes::System, false) . PHP_EOL);
|
||||
print('Unix Package Lock(s): ' . json_encode(\ncc\Utilities\PathFinder::getPackageLockFiles(false), JSON_UNESCAPED_SLASHES) . PHP_EOL);
|
||||
print('Win32 Package Lock (Auto): ' . \ncc\Utilities\PathFinder::getPackageLock(\ncc\Abstracts\Scopes::Auto, true) . PHP_EOL);
|
||||
print('Win32 Package Lock (User): ' . \ncc\Utilities\PathFinder::getPackageLock(\ncc\Abstracts\Scopes::User, true) . PHP_EOL);
|
||||
print('Win32 Package Lock (System): ' . \ncc\Utilities\PathFinder::getPackageLock(\ncc\Abstracts\Scopes::System, true) . PHP_EOL);
|
||||
print('Win32 Package Lock(s): ' . json_encode(\ncc\Utilities\PathFinder::getPackageLockFiles(true), JSON_UNESCAPED_SLASHES) . PHP_EOL);
|
||||
print(PHP_EOL);
|
5
tests/utils/scope_resolver.php
Normal file
5
tests/utils/scope_resolver.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
|
||||
require(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'autoload.php');
|
||||
|
||||
print('Detected Scope: ' . \ncc\Utilities\Resolver::resolveScope() . PHP_EOL);
|
Loading…
Add table
Reference in a new issue