Skip to content

Commit

Permalink
Add extension-point infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Feb 27, 2024
1 parent 8506dbb commit 954a927
Show file tree
Hide file tree
Showing 3 changed files with 120 additions and 1 deletion.
44 changes: 44 additions & 0 deletions src/SAML11/XML/ExtensionPointInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\SAML11\XML;

/**
* Interface for several extension points objects.
*
* @package simplesamlphp/saml11
*/
interface ExtensionPointInterface
{
/**
* Get the local name for the element's xsi:type.
*
* @return string
*/
public static function getXsiTypeName(): string;


/**
* Get the namespace for the element's xsi:type.
*
* @return string
*/
public static function getXsiTypeNamespaceURI(): string;


/**
* Get the namespace-prefix for the element's xsi:type.
*
* @return string
*/
public static function getXsiTypePrefix(): string;


/**
* Return the xsi:type value corresponding this element.
*
* @return string
*/
public function getXsiType(): string;
}
75 changes: 75 additions & 0 deletions src/SAML11/XML/ExtensionPointTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\SAML11\XML;

use RuntimeException;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Exception\SchemaViolationException;

/**
* Trait for several extension points objects.
*
* @package simplesamlphp/saml11
*/
trait ExtensionPointTrait
{
/**
* Get the local name for the element's xsi:type.
*
* @return string
*/
public static function getXsiTypeName(): string
{
Assert::true(
defined('static::XSI_TYPE_NAME'),
self::getClassName(static::class)
. '::XSI_TYPE_NAME constant must be defined and set to unprefixed type for the xsi:type it represents.',
RuntimeException::class,
);

Assert::validNCName(static::XSI_TYPE_NAME, SchemaViolationException::class);
return static::XSI_TYPE_NAME;
}


/**
* Get the namespace for the element's xsi:type.
*
* @return string
*/
public static function getXsiTypeNamespaceURI(): string
{
Assert::true(
defined('static::XSI_TYPE_NAMESPACE'),
self::getClassName(static::class)
. '::XSI_TYPE_NAMESPACE constant must be defined and set to the namespace for the xsi:type it represents.',
RuntimeException::class,
);

Assert::validURI(static::XSI_TYPE_NAMESPACE, SchemaViolationException::class);
return static::XSI_TYPE_NAMESPACE;
}


/**
* Get the namespace-prefix for the element's xsi:type.
*
* @return string
*/
public static function getXsiTypePrefix(): string
{
Assert::true(
defined('static::XSI_TYPE_PREFIX'),
sprintf(
'%s::XSI_TYPE_PREFIX constant must be defined and set to the namespace for the xsi:type it represents.',
self::getClassName(static::class),
),
RuntimeException::class,
);

Assert::validNCName(static::XSI_TYPE_PREFIX, SchemaViolationException::class);
return static::XSI_TYPE_PREFIX;
}
}
2 changes: 1 addition & 1 deletion src/SAML11/XML/saml/AbstractAuthorityBindingType.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use DOMElement;
use SimpleSAML\Assert\Assert;
use SimpleSAML\XML\Constants as C;
use SimpleSAML\SAML11\Constants as C;
use SimpleSAML\XML\Exception\InvalidDOMElementException;

/**
Expand Down

0 comments on commit 954a927

Please sign in to comment.