Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/xsd types #6

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"psr/clock": "^1.0",
"psr/log": "^2.0 | ^3.0",
"simplesamlphp/assert": "^1.8",
"simplesamlphp/xml-common": "~1.24.0",
"simplesamlphp/xml-security": "~1.13.0"
"simplesamlphp/xml-common": "dev-feature/xsd-types",
"simplesamlphp/xml-security": "dev-feature/xsd-types"
},
"require-dev": {
"beste/clock": "^3.0",
Expand Down
76 changes: 0 additions & 76 deletions phpstan-baseline.neon

This file was deleted.

2 changes: 0 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,3 @@ parameters:
level: 1
paths:
- src
includes:
- phpstan-baseline.neon
39 changes: 39 additions & 0 deletions src/SAML11/Assert/AnyURITrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\SAML11\Assert;

use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\SAML11\Exception\ProtocolViolationException;

/**
* @package simplesamlphp/saml11
*/
trait AnyURITrait
{
/**
* @param string $value
* @param string $message
*/
protected static function validAnyURI(string $value, string $message = ''): void
{
parent::validAnyURI($value, $message);

try {
/**
* 1.2.1 String and URI Values
*
* Unless otherwise indicated in this specification, all URI reference values MUST consist
* of at least one non-whitespace character
*/
static::notWhitespaceOnly(
$value,
$message ?: '%s is not a SAML1.1-compliant URI',
ProtocolViolationException::class,
);
} catch (AssertionFailedException $e) {
throw new ProtocolViolationException($e->getMessage());
}
}
}
10 changes: 6 additions & 4 deletions src/SAML11/Assert/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
* @package simplesamlphp/saml11
*
* @method static void validDateTime(mixed $value, string $message = '', string $exception = '')
* @method static void validURI(mixed $value, string $message = '', string $exception = '')
* @method static void validEntityID(mixed $value, string $message = '', string $exception = '')
* @method static void validURI(mixed $value, string $message = '', string $exception = '')
* @method static void nullOrValidDateTime(mixed $value, string $message = '', string $exception = '')
* @method static void nullOrValidURI(mixed $value, string $message = '', string $exception = '')
* @method static void nullOrValidEntityID(mixed $value, string $message = '', string $exception = '')
* @method static void nullOrValidURI(mixed $value, string $message = '', string $exception = '')
* @method static void allValidDateTime(mixed $value, string $message = '', string $exception = '')
* @method static void allValidURI(mixed $value, string $message = '', string $exception = '')
* @method static void allValidEntityID(mixed $value, string $message = '', string $exception = '')
* @method static void allValidURI(mixed $value, string $message = '', string $exception = '')
*/
class Assert extends BaseAssert
{
use CustomAssertionTrait;
use AnyURITrait;
use DateTimeTrait;
use StringTrait;
}
63 changes: 0 additions & 63 deletions src/SAML11/Assert/CustomAssertionTrait.php

This file was deleted.

39 changes: 39 additions & 0 deletions src/SAML11/Assert/DateTimeTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\SAML11\Assert;

use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\SAML11\Exception\ProtocolViolationException;

/**
* @package simplesamlphp/saml11
*/
trait DateTimeTrait
{
/**
* @param string $value
* @param string $message
*/
protected static function validDateTime(string $value, string $message = ''): void
{
parent::validDateTime($value, $message);

try {
/**
* 1.2.2 Time Values
*
* All SAML time values have the type xsd:dateTime, which is built in to the W3C XML Schema Datatypes
* specification [Schema2], and MUST be expressed in UTC form
*/
static::endsWith(
$value,
'Z',
$message ?: '%s is not a DateTime expressed in the UTC timezone using the \'Z\' timezone identifier.',
);
} catch (AssertionFailedException $e) {
throw new ProtocolViolationException($e->getMessage());
}
}
}
37 changes: 37 additions & 0 deletions src/SAML11/Assert/StringTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\SAML11\Assert;

use SimpleSAML\Assert\AssertionFailedException;
use SimpleSAML\SAML11\Exception\ProtocolViolationException;
use SimpleSAML\XML\Exception\SchemaViolationException;

/**
* @package simplesamlphp/saml11
*/
trait StringTrait
{
/**
* @param string $value
* @param string $message
*/
protected static function validString(string $value, string $message = ''): void
{
parent::validString($value, $message, SchemaViolationException::class);

try {
/**
* 1.2.1 String and URI Values
*
* All strings in SAML messages MUST consist of at least one non-whitespace character
* (whitespace is defined in the XML Recommendation [XML] §2.3).
* Empty and whitespace-only values are disallowed.
*/
static::notWhitespaceOnly($value, $message ?: '%s is not a SAML1.1-compliant string');
} catch (AssertionFailedException $e) {
throw new ProtocolViolationException($e->getMessage());
}
}
}
Loading