Added method \ncc\Objects\ProjectConfiguration > Dependency > validate()
https://git.n64.cc/nosial/ncc/-/issues/4
This commit is contained in:
parent
a3c3322f28
commit
405f53673a
1 changed files with 30 additions and 0 deletions
|
@ -5,7 +5,9 @@
|
|||
namespace ncc\Objects\ProjectConfiguration;
|
||||
|
||||
use ncc\Abstracts\DependencySourceType;
|
||||
use ncc\Exceptions\InvalidDependencyConfiguration;
|
||||
use ncc\Utilities\Functions;
|
||||
use ncc\Utilities\Validate;
|
||||
|
||||
/**
|
||||
* @author Zi Xing Narrakas
|
||||
|
@ -84,4 +86,32 @@
|
|||
|
||||
return $DependencyObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the dependency configuration
|
||||
*
|
||||
* @param bool $throw_exception
|
||||
* @return bool
|
||||
* @throws InvalidDependencyConfiguration
|
||||
*/
|
||||
public function validate(bool $throw_exception): bool
|
||||
{
|
||||
if(!Validate::packageName($this->Name))
|
||||
{
|
||||
if($throw_exception)
|
||||
throw new InvalidDependencyConfiguration(sprintf('Invalid dependency name "%s"', $this->Name));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if($this->Version !== null && !Validate::version($this->Version))
|
||||
{
|
||||
if($throw_exception)
|
||||
throw new InvalidDependencyConfiguration(sprintf('Invalid dependency version "%s"', $this->Version));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue