-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create type-classes for all xsd-types
- Loading branch information
Showing
45 changed files
with
1,462 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XML\Assert; | ||
|
||
use InvalidArgumentException; | ||
|
||
use function filter_var; | ||
use function sprintf; | ||
|
||
/** | ||
* @package simplesamlphp/xml-common | ||
*/ | ||
trait EntitiesTrait | ||
{ | ||
/** @var string */ | ||
private static string $entities_regex = '/^([\p{L}a-zA-Z-][\w.-]*)([\s][\p{L}a-zA-Z-][\w.-]*)*$/Du'; | ||
|
||
/*********************************************************************************** | ||
* NOTE: Custom assertions may be added below this line. * | ||
* They SHOULD be marked as `protected` to ensure the call is forced * | ||
* through __callStatic(). * | ||
* Assertions marked `public` are called directly and will * | ||
* not handle any custom exception passed to it. * | ||
***********************************************************************************/ | ||
|
||
|
||
/** | ||
* @param string $value | ||
* @param string $message | ||
*/ | ||
protected static function validEntities(string $value, string $message = ''): void | ||
{ | ||
if (filter_var($value, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => self::$entities_regex]]) === false) { | ||
throw new InvalidArgumentException(sprintf( | ||
$message ?: '\'%s\' is not a valid xs:ENTITIES', | ||
$value, | ||
)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XML\Assert; | ||
|
||
use InvalidArgumentException; | ||
|
||
/** | ||
* @package simplesamlphp/xml-common | ||
*/ | ||
trait EntityTrait | ||
{ | ||
/*********************************************************************************** | ||
* NOTE: Custom assertions may be added below this line. * | ||
* They SHOULD be marked as `protected` to ensure the call is forced * | ||
* through __callStatic(). * | ||
* Assertions marked `public` are called directly and will * | ||
* not handle any custom exception passed to it. * | ||
***********************************************************************************/ | ||
|
||
|
||
/** | ||
* @param string $value | ||
* @param string $message | ||
*/ | ||
protected static function validEntity(string $value, string $message = ''): void | ||
{ | ||
Assert::validNCName( | ||
$value, | ||
$message ?: '\'%s\' is not a valid xs:Entity', | ||
InvalidArgumentException::class, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XML\Assert; | ||
|
||
use InvalidArgumentException; | ||
|
||
/** | ||
* @package simplesamlphp/xml-common | ||
*/ | ||
trait IDRefTrait | ||
{ | ||
/*********************************************************************************** | ||
* NOTE: Custom assertions may be added below this line. * | ||
* They SHOULD be marked as `protected` to ensure the call is forced * | ||
* through __callStatic(). * | ||
* Assertions marked `public` are called directly and will * | ||
* not handle any custom exception passed to it. * | ||
***********************************************************************************/ | ||
|
||
|
||
/** | ||
* @param string $value | ||
* @param string $message | ||
*/ | ||
protected static function validIDRef(string $value, string $message = ''): void | ||
{ | ||
Assert::validNCName( | ||
$value, | ||
$message ?: '\'%s\' is not a xs:IDREF', | ||
InvalidArgumentException::class, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XML\Assert; | ||
|
||
use InvalidArgumentException; | ||
|
||
use function filter_var; | ||
use function sprintf; | ||
|
||
/** | ||
* @package simplesamlphp/xml-common | ||
*/ | ||
trait IDRefsTrait | ||
{ | ||
/** @var string */ | ||
private static string $idrefs_regex = '/^([\p{L}a-zA-Z-][\w.-]*)([\s][\p{L}a-zA-Z-][\w.-]*)*$/Du'; | ||
|
||
/*********************************************************************************** | ||
* NOTE: Custom assertions may be added below this line. * | ||
* They SHOULD be marked as `protected` to ensure the call is forced * | ||
* through __callStatic(). * | ||
* Assertions marked `public` are called directly and will * | ||
* not handle any custom exception passed to it. * | ||
***********************************************************************************/ | ||
|
||
|
||
/** | ||
* @param string $value | ||
* @param string $message | ||
*/ | ||
protected static function validIDRefs(string $value, string $message = ''): void | ||
{ | ||
if (filter_var($value, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => self::$idrefs_regex]]) === false) { | ||
throw new InvalidArgumentException(sprintf( | ||
$message ?: '\'%s\' is not a valid xs:IDREFS', | ||
$value, | ||
)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XML\Assert; | ||
|
||
use InvalidArgumentException; | ||
|
||
/** | ||
* @package simplesamlphp/xml-common | ||
*/ | ||
trait IDTrait | ||
{ | ||
/*********************************************************************************** | ||
* NOTE: Custom assertions may be added below this line. * | ||
* They SHOULD be marked as `protected` to ensure the call is forced * | ||
* through __callStatic(). * | ||
* Assertions marked `public` are called directly and will * | ||
* not handle any custom exception passed to it. * | ||
***********************************************************************************/ | ||
|
||
|
||
/** | ||
* @param string $value | ||
* @param string $message | ||
*/ | ||
protected static function validID(string $value, string $message = ''): void | ||
{ | ||
Assert::validNCName( | ||
$value, | ||
$message ?: '\'%s\' is not a valid xs:ID', | ||
InvalidArgumentException::class, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace SimpleSAML\XML\Assert; | ||
|
||
use InvalidArgumentException; | ||
|
||
use function filter_var; | ||
use function sprintf; | ||
|
||
/** | ||
* @package simplesamlphp/xml-common | ||
*/ | ||
trait LangTrait | ||
{ | ||
/** @var string */ | ||
private static string $lang_regex = '/^(i[-]|x[-])?([a-z]{1,8})([-][a-z]{1,8})?$/Di'; | ||
|
||
/*********************************************************************************** | ||
* NOTE: Custom assertions may be added below this line. * | ||
* They SHOULD be marked as `protected` to ensure the call is forced * | ||
* through __callStatic(). * | ||
* Assertions marked `public` are called directly and will * | ||
* not handle any custom exception passed to it. * | ||
***********************************************************************************/ | ||
|
||
|
||
/** | ||
* @param string $value | ||
* @param string $message | ||
*/ | ||
protected static function validLang(string $value, string $message = ''): void | ||
{ | ||
if (filter_var($value, FILTER_VALIDATE_REGEXP, ['options' => ['regexp' => self::$lang_regex]]) === false) { | ||
throw new InvalidArgumentException(sprintf( | ||
$message ?: '\'%s\' is not a valid xs:language', | ||
$value, | ||
)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.