Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
/tools/ export-ignore
/tests/bootstrap.php export-ignore
/tests/resources/xml export-ignore
/tests/InterOperability/ export-ignore
/tests/Utils/ export-ignore
/tests/XML/ export-ignore
/tests/XMLSchema/ export-ignore
codecov.yml export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
Expand Down
30 changes: 30 additions & 0 deletions src/XML/Type/BaseValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XML\Type;

use SimpleSAML\XML\Attribute;
use SimpleSAML\XML\Constants as C;
use SimpleSAML\XMLSchema\Type\Builtin\AnyURIValue;
use SimpleSAML\XMLSchema\Type\Helper\AttributeTypeInterface;

/**
* @package simplesaml/xml-common
*/
class BaseValue extends AnyURIValue implements AttributeTypeInterface
{
/** @var string */
public const SCHEMA_TYPE = 'xs:anyURI';


/**
* Convert this value to an attribute
*
* @return \SimpleSAML\XML\Attribute
*/
public function toAttribute(): Attribute
{
return new Attribute(C::NS_XML, 'xml', 'base', $this);
}
}
30 changes: 30 additions & 0 deletions src/XML/Type/IDValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XML\Type;

use SimpleSAML\XML\Attribute;
use SimpleSAML\XML\Constants as C;
use SimpleSAML\XMLSchema\Type\Builtin\IDValue as BaseIDValue;
use SimpleSAML\XMLSchema\Type\Helper\AttributeTypeInterface;

/**
* @package simplesaml/xml-common
*/
class IDValue extends BaseIDValue implements AttributeTypeInterface
{
/** @var string */
public const SCHEMA_TYPE = 'xs:ID';


/**
* Convert this value to an attribute
*
* @return \SimpleSAML\XML\Attribute
*/
public function toAttribute(): Attribute
{
return new Attribute(C::NS_XML, 'xml', 'id', $this);
}
}
47 changes: 47 additions & 0 deletions src/XML/Type/LangValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XML\Type;

use SimpleSAML\XML\Attribute;
use SimpleSAML\XML\Constants as C;
use SimpleSAML\XMLSchema\Type\Builtin\LanguageValue;
use SimpleSAML\XMLSchema\Type\Helper\AttributeTypeInterface;

/**
* @package simplesaml/xml-common
*/
class LangValue extends LanguageValue implements AttributeTypeInterface
{
/** @var string */
public const SCHEMA_TYPE = 'xs:language';


/**
* Validate the value.
*
* @param string $value
* @throws \SimpleSAML\XMLSchema\Exception\SchemaViolationException on failure
* @return void
*/
protected function validateValue(string $value): void
{
$sanitized = $this->sanitizeValue($value);

if ($sanitized !== '') {
parent::validateValue($sanitized);
}
}


/**
* Convert this value to an attribute
*
* @return \SimpleSAML\XML\Attribute
*/
public function toAttribute(): Attribute
{
return new Attribute(C::NS_XML, 'xml', 'lang', $this);
}
}
71 changes: 71 additions & 0 deletions src/XML/Type/SpaceValue.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XML\Type;

use SimpleSAML\XML\Assert\Assert;
use SimpleSAML\XML\Attribute;
use SimpleSAML\XML\Constants as C;
use SimpleSAML\XML\XML\xml\SpaceEnum;
use SimpleSAML\XMLSchema\Exception\SchemaViolationException;
use SimpleSAML\XMLSchema\Type\Builtin\NCNameValue;
use SimpleSAML\XMLSchema\Type\Helper\AttributeTypeInterface;

/**
* @package simplesaml/xml-common
*/
class SpaceValue extends NCNameValue implements AttributeTypeInterface
{
/**
* Validate the value.
*
* @param string $value
* @throws \SimpleSAML\XMLSchema\Exception\SchemaViolationException on failure
* @return void
*/
protected function validateValue(string $value): void
{
$sanitized = $this->sanitizeValue($value);
parent::validateValue($sanitized);

Assert::oneOf(
$sanitized,
[
SpaceEnum::Default->value,
SpaceEnum::Preserve->value,
],
SchemaViolationException::class,
);
}


/**
* @param \SimpleSAML\XML\XML\xml\SpaceEnum $value
* @return static
*/
public static function fromEnum(SpaceEnum $value): static
{
return new static($value->value);
}


/**
* @return \SimpleSAML\XML\XML\xml\SpaceEnum $value
*/
public function toEnum(): SpaceEnum
{
return SpaceEnum::from($this->getValue());
}


/**
* Convert this value to an attribute
*
* @return \SimpleSAML\XML\Attribute
*/
public function toAttribute(): Attribute
{
return new Attribute(C::NS_XML, 'xml', 'space', $this);
}
}
11 changes: 11 additions & 0 deletions src/XML/XML/xml/SpaceEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XML\XML\xml;

enum SpaceEnum: string
{
case Default = 'default';
case Preserve = 'preserve';
}
134 changes: 134 additions & 0 deletions src/XML/XML/xml/SpecialAttrsTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XML\XML\xml;

use SimpleSAML\XML\Type\{BaseValue, IDValue, LangValue, SpaceValue};

/**
* Trait grouping common functionality for elements that use the specialAttrs-attributeGroup.
*
* @package simplesamlphp/xml-common
*/
trait SpecialAttrsTrait
{
/**
* The base.
*
* @var \SimpleSAML\XML\Type\BaseValue|null
*/
protected ?BaseValue $base = null;


/**
* The id.
*
* @var \SimpleSAML\XML\Type\IDValue|null
*/
protected ?IDValue $id = null;


/**
* The lang.
*
* @var \SimpleSAML\XML\Type\LangValue|null
*/
protected ?LangValue $lang = null;


/**
* The space.
*
* @var \SimpleSAML\XML\Type\SpaceValue|null
*/
protected ?SpaceValue $space = null;


/**
* Collect the value of the base-property
*
* @return \SimpleSAML\XML\Type\BaseValue|null
*/
public function getBase(): ?BaseValue
{
return $this->base;
}


/**
* Set the value of the base-property
*
* @param \SimpleSAML\XML\Type\BaseValue|null $base
*/
protected function setBase(?BaseValue $base): void
{
$this->base = $base;
}


/**
* Collect the value of the id-property
*
* @return \SimpleSAML\XML\Type\IDValue|null
*/
public function getId(): ?IDValue
{
return $this->id;
}


/**
* Set the value of the id-property
*
* @param \SimpleSAML\XML\Type\IDValue|null $id
*/
protected function setID(?IDValue $id): void
{
$this->id = $id;
}


/**
* Collect the value of the lang-property
*
* @return \SimpleSAML\XML\Type\LangValue|null
*/
public function getLang(): ?LangValue
{
return $this->lang;
}


/**
* Set the value of the lang-property
*
* @param \SimpleSAML\XML\Type\LangValue|null $id
*/
protected function setLang(?LangValue $lang): void
{
$this->lang = $lang;
}


/**
* Collect the value of the space-property
*
* @return \SimpleSAML\XML\Type\SpaceValue|null
*/
public function getSpace(): ?SpaceValue
{
return $this->space;
}


/**
* Set the value of the space-property
*
* @param \SimpleSAML\XML\Type\SpaceValue|null $id
*/
protected function setSpace(?SpaceValue $space): void
{
$this->space = $space;
}
}
22 changes: 22 additions & 0 deletions src/XMLSchema/Type/Helper/AttributeTypeInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace SimpleSAML\XMLSchema\Type\Helper;

use SimpleSAML\XML\Attribute;

/**
* interface class to be implemented by all the classes that represent a DOM Attribute
*
* @package simplesamlphp/xml-common
*/
interface AttributeTypeInterface extends ValueTypeInterface
{
/**
* Convert this value to an attribute
*
* @return \SimpleSAML\XML\Attribute
*/
public function toAttribute(): Attribute;
}
2 changes: 1 addition & 1 deletion tests/InterOperability/SchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testUnmarshalling(DOMElement $schema): void
*/
public static function provideSchema(): array
{
$dir = dirname(__FILE__, 3);
$dir = dirname(__FILE__, 2);

/** @var string $xml */
$xml = file_get_contents($dir . '/resources/schemas/xml.xsd');
Expand Down
Loading
Loading