Added function validate() to \ncc\Objects\ProjectConfiguration > Project
Added function validate() to \ncc\Objects\ProjectConfiguration > Compiler Updated ExceptionCodes.php Added UnsupportedExtensionVersionException.php Added UnsupportedCompilerExtensionException.php Added InvalidVersionConfigurationException.php Added InvalidPropertyValueException.php
This commit is contained in:
parent
781ee06c67
commit
45ddb06831
7 changed files with 219 additions and 1 deletions
|
@ -16,12 +16,15 @@
|
||||||
use ncc\Exceptions\InvalidProjectBuildConfiguration;
|
use ncc\Exceptions\InvalidProjectBuildConfiguration;
|
||||||
use ncc\Exceptions\InvalidProjectConfigurationException;
|
use ncc\Exceptions\InvalidProjectConfigurationException;
|
||||||
use ncc\Exceptions\InvalidProjectNameException;
|
use ncc\Exceptions\InvalidProjectNameException;
|
||||||
|
use ncc\Exceptions\InvalidPropertyValueException;
|
||||||
use ncc\Exceptions\InvalidScopeException;
|
use ncc\Exceptions\InvalidScopeException;
|
||||||
|
use ncc\Exceptions\InvalidVersionConfigurationException;
|
||||||
use ncc\Exceptions\InvalidVersionNumberException;
|
use ncc\Exceptions\InvalidVersionNumberException;
|
||||||
use ncc\Exceptions\MalformedJsonException;
|
use ncc\Exceptions\MalformedJsonException;
|
||||||
use ncc\Exceptions\NoUnitsFoundException;
|
use ncc\Exceptions\NoUnitsFoundException;
|
||||||
use ncc\Exceptions\ProjectAlreadyExistsException;
|
use ncc\Exceptions\ProjectAlreadyExistsException;
|
||||||
use ncc\Exceptions\RuntimeException;
|
use ncc\Exceptions\RuntimeException;
|
||||||
|
use ncc\Exceptions\UnsupportedCompilerExtensionException;
|
||||||
use ncc\Exceptions\UnsupportedPackageException;
|
use ncc\Exceptions\UnsupportedPackageException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -145,6 +148,26 @@
|
||||||
*/
|
*/
|
||||||
const InvalidProjectBuildConfiguration = -1722;
|
const InvalidProjectBuildConfiguration = -1722;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see UnsupportedCompilerExtensionException
|
||||||
|
*/
|
||||||
|
const UnsupportedCompilerExtensionException = -1723;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InvalidPropertyValueException
|
||||||
|
*/
|
||||||
|
const InvalidPropertyValueException = -1724;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InvalidVersionConfigurationException
|
||||||
|
*/
|
||||||
|
const InvalidVersionConfigurationException = -1725;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see UnsupportedExtensionVersionException
|
||||||
|
*/
|
||||||
|
const UnsupportedExtensionVersionException = -1726;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* All the exception codes from NCC
|
* All the exception codes from NCC
|
||||||
*/
|
*/
|
||||||
|
@ -171,6 +194,10 @@
|
||||||
self::InvalidConstantNameException,
|
self::InvalidConstantNameException,
|
||||||
self::PackagePreparationFailedException,
|
self::PackagePreparationFailedException,
|
||||||
self::BuildConfigurationNotFoundException,
|
self::BuildConfigurationNotFoundException,
|
||||||
self::InvalidProjectBuildConfiguration
|
self::InvalidProjectBuildConfiguration,
|
||||||
|
self::UnsupportedCompilerExtensionException,
|
||||||
|
self::InvalidPropertyValueException,
|
||||||
|
self::InvalidVersionConfigurationException,
|
||||||
|
self::UnsupportedExtensionVersionException
|
||||||
];
|
];
|
||||||
}
|
}
|
11
src/ncc/Exceptions/InvalidPropertyValueException.php
Normal file
11
src/ncc/Exceptions/InvalidPropertyValueException.php
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ncc\Exceptions;
|
||||||
|
|
||||||
|
class InvalidPropertyValueException extends \Exception
|
||||||
|
{
|
||||||
|
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
|
||||||
|
{
|
||||||
|
parent::__construct($message, $code, $previous);
|
||||||
|
}
|
||||||
|
}
|
28
src/ncc/Exceptions/InvalidVersionConfigurationException.php
Normal file
28
src/ncc/Exceptions/InvalidVersionConfigurationException.php
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/** @noinspection PhpPropertyOnlyWrittenInspection */
|
||||||
|
|
||||||
|
namespace ncc\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use ncc\Abstracts\ExceptionCodes;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class InvalidVersionConfigurationException extends Exception
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Throwable|null
|
||||||
|
*/
|
||||||
|
private ?Throwable $previous;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $message
|
||||||
|
* @param Throwable|null $previous
|
||||||
|
*/
|
||||||
|
public function __construct(string $message = "", ?Throwable $previous = null)
|
||||||
|
{
|
||||||
|
parent::__construct($message, ExceptionCodes::InvalidVersionConfigurationException, $previous);
|
||||||
|
$this->message = $message;
|
||||||
|
$this->previous = $previous;
|
||||||
|
}
|
||||||
|
}
|
28
src/ncc/Exceptions/UnsupportedCompilerExtensionException.php
Normal file
28
src/ncc/Exceptions/UnsupportedCompilerExtensionException.php
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/** @noinspection PhpPropertyOnlyWrittenInspection */
|
||||||
|
|
||||||
|
namespace ncc\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use ncc\Abstracts\ExceptionCodes;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
|
class UnsupportedCompilerExtensionException extends Exception
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var Throwable|null
|
||||||
|
*/
|
||||||
|
private ?Throwable $previous;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $message
|
||||||
|
* @param Throwable|null $previous
|
||||||
|
*/
|
||||||
|
public function __construct(string $message = "", ?Throwable $previous = null)
|
||||||
|
{
|
||||||
|
parent::__construct($message, ExceptionCodes::UnsupportedCompilerExtensionException, $previous);
|
||||||
|
$this->message = $message;
|
||||||
|
$this->previous = $previous;
|
||||||
|
}
|
||||||
|
}
|
13
src/ncc/Exceptions/UnsupportedExtensionVersionException.php
Normal file
13
src/ncc/Exceptions/UnsupportedExtensionVersionException.php
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace ncc\Exceptions;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class UnsupportedExtensionVersionException extends Exception
|
||||||
|
{
|
||||||
|
public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
|
||||||
|
{
|
||||||
|
parent::__construct($message, $code, $previous);
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,6 +4,15 @@
|
||||||
|
|
||||||
namespace ncc\Objects\ProjectConfiguration;
|
namespace ncc\Objects\ProjectConfiguration;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use ncc\Abstracts\CompilerExtensions;
|
||||||
|
use ncc\Abstracts\CompilerExtensionSupportedVersions;
|
||||||
|
use ncc\Exceptions\InvalidPropertyValueException;
|
||||||
|
use ncc\Exceptions\InvalidVersionConfigurationException;
|
||||||
|
use ncc\Exceptions\RuntimeException;
|
||||||
|
use ncc\Exceptions\UnsupportedCompilerExtensionException;
|
||||||
|
use ncc\Exceptions\UnsupportedExtensionVersionException;
|
||||||
|
use ncc\ThirdParty\jelix\Version\VersionComparator;
|
||||||
use ncc\Utilities\Functions;
|
use ncc\Utilities\Functions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,6 +42,86 @@
|
||||||
*/
|
*/
|
||||||
public $MaximumVersion;
|
public $MaximumVersion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the compiler object
|
||||||
|
*
|
||||||
|
* @param bool $throw_exception
|
||||||
|
* @return bool
|
||||||
|
* @throws InvalidPropertyValueException
|
||||||
|
* @throws RuntimeException
|
||||||
|
* @throws UnsupportedCompilerExtensionException
|
||||||
|
* @throws UnsupportedExtensionVersionException
|
||||||
|
*/
|
||||||
|
public function validate(bool $throw_exception=True): bool
|
||||||
|
{
|
||||||
|
if($this->Extension == null)
|
||||||
|
{
|
||||||
|
if($throw_exception)
|
||||||
|
throw new InvalidPropertyValueException('The property \'extension\' must not be null.');
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->MinimumVersion == null)
|
||||||
|
{
|
||||||
|
if($throw_exception)
|
||||||
|
throw new InvalidPropertyValueException('The property \'minimum_version\' must not be null.');
|
||||||
|
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
if($this->MaximumVersion == null)
|
||||||
|
{
|
||||||
|
if($throw_exception)
|
||||||
|
throw new InvalidPropertyValueException('The property \'maximum_version\' must not be null.');
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if(VersionComparator::compareVersion($this->MinimumVersion, $this->MaximumVersion) == 1)
|
||||||
|
{
|
||||||
|
if($throw_exception)
|
||||||
|
throw new InvalidVersionConfigurationException('The minimum version cannot be greater version number than the maximum version');
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
throw new RuntimeException('Version comparison failed: ' . $e->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!in_array($this->Extension, CompilerExtensions::All))
|
||||||
|
{
|
||||||
|
if($throw_exception)
|
||||||
|
throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $this->Extension . '\' is not supported');
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch($this->Extension)
|
||||||
|
{
|
||||||
|
case CompilerExtensions::PHP:
|
||||||
|
if(!in_array($this->MaximumVersion, CompilerExtensionSupportedVersions::PHP))
|
||||||
|
{
|
||||||
|
if($throw_exception)
|
||||||
|
throw new UnsupportedExtensionVersionException('The MaximumVersion does not support version ' . $this->MaximumVersion . ' for the extension ' . $this->Extension);
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!in_array($this->MinimumVersion, CompilerExtensionSupportedVersions::PHP))
|
||||||
|
{
|
||||||
|
if($throw_exception)
|
||||||
|
throw new UnsupportedExtensionVersionException('The MinimumVersion does not support version ' . $this->MinimumVersion . ' for the extension ' . $this->Extension);
|
||||||
|
return False;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new UnsupportedCompilerExtensionException('The compiler extension \'' . $this->Extension . '\' is not supported');
|
||||||
|
}
|
||||||
|
|
||||||
|
return True;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array representation of the object
|
* Returns an array representation of the object
|
||||||
*
|
*
|
||||||
|
|
|
@ -4,6 +4,10 @@
|
||||||
|
|
||||||
namespace ncc\Objects\ProjectConfiguration;
|
namespace ncc\Objects\ProjectConfiguration;
|
||||||
|
|
||||||
|
use ncc\Exceptions\InvalidPropertyValueException;
|
||||||
|
use ncc\Exceptions\RuntimeException;
|
||||||
|
use ncc\Exceptions\UnsupportedCompilerExtensionException;
|
||||||
|
use ncc\Exceptions\UnsupportedExtensionVersionException;
|
||||||
use ncc\Utilities\Functions;
|
use ncc\Utilities\Functions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,6 +35,24 @@
|
||||||
$this->Options = [];
|
$this->Options = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the Project object
|
||||||
|
*
|
||||||
|
* @param bool $throw_exception
|
||||||
|
* @return bool
|
||||||
|
* @throws InvalidPropertyValueException
|
||||||
|
* @throws RuntimeException
|
||||||
|
* @throws UnsupportedCompilerExtensionException
|
||||||
|
* @throws UnsupportedExtensionVersionException
|
||||||
|
*/
|
||||||
|
public function validate(bool $throw_exception=True): bool
|
||||||
|
{
|
||||||
|
if(!$this->Compiler->validate($throw_exception))
|
||||||
|
return False;
|
||||||
|
|
||||||
|
return True;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array representation of the object
|
* Returns an array representation of the object
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue