Skip to content

Commit

Permalink
Add support for optional @alias in edmx:Include (#846)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgerzabek authored Nov 12, 2024
1 parent 5785ee1 commit 27cfa1e
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/Annotation/Reference.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,25 @@
class Reference
{
/**
* URI of the service document, without the xml/json suffix
* @var string $uri URI
* The URI SHOULD be a URL that locates the referenced document. If the URI is not dereferencable it
* SHOULD identify a well-known schema. The URI MAY be absolute or relative URI; relative URLs are
* relative to the URL of the document containing the reference, or relative to a base URL specified
* in a format-specific way.
*
* @var string $uri URI an absolute or relative URI without extension .xml or .json;
*/
protected $uri;

/**
* @var string $namespace Namespace
* @var string $namespace Namespace the namespace of a schema defined in the referenced CSDL document.
*/
protected $namespace;

/**
* @var string $alias Alias a simple identifier that can be used in qualified names instead of the namespace.
*/
protected $alias;

/**
* Append this reference to the provided XML element
* @param SimpleXMLElement $schema Schema
Expand All @@ -35,7 +44,9 @@ public function appendXml(SimpleXMLElement $schema): self
$reference->addAttribute('Uri', $this->uri.'.xml');
$include = $reference->addChild('Include');
$include->addAttribute('Namespace', $this->namespace);

if (!is_null($this->alias)) {
$include->addAttribute('Alias', $this->alias);
}
return $this;
}

Expand All @@ -46,11 +57,15 @@ public function appendXml(SimpleXMLElement $schema): self
*/
public function appendJson(object $json): self
{
$include = [
'$Namespace' => $this->namespace,
];
if (!is_null($this->alias)) {
$include[]['$Alias'] = $this->alias;
}
$json->{'$Reference'}[$this->uri.'.json'] = [
'$Include' => [
[
'$Namespace' => $this->namespace,
]
$include
]
];

Expand All @@ -62,6 +77,6 @@ public function appendJson(object $json): self
*/
public function __toString()
{
return $this->namespace;
return is_null($this->alias) ? $this->namespace : $this->alias . '=' . $this->namespace;
}
}

0 comments on commit 27cfa1e

Please sign in to comment.