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

Add support for optional @Alias in edmx:Include #846

Merged
merged 2 commits into from
Nov 12, 2024
Merged
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
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;
}
}
Loading