From 27e7a4cc9cc6f1e20251a5127de4f9a5b256691d Mon Sep 17 00:00:00 2001 From: Chris Lloyd Date: Sun, 11 Apr 2021 09:10:16 +0100 Subject: [PATCH] WIP --- src/PathSegment/Metadata.php.orig | 334 ------------------------------ 1 file changed, 334 deletions(-) delete mode 100644 src/PathSegment/Metadata.php.orig diff --git a/src/PathSegment/Metadata.php.orig b/src/PathSegment/Metadata.php.orig deleted file mode 100644 index 38b52a3a5..000000000 --- a/src/PathSegment/Metadata.php.orig +++ /dev/null @@ -1,334 +0,0 @@ -'); - $version = $transaction->getVersion(); - $root->addAttribute('Version', $version); - - foreach (Lodata::getReferences() as $reference) { - $reference->append($root); - } - - $dataServices = $root->addChild('DataServices'); - $namespace = Lodata::getNamespace(); - - // http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_Schema - $schema = $dataServices->addChild('Schema', null, 'http://docs.oasis-open.org/odata/ns/edm'); - $schema->addAttribute('Namespace', $namespace); - - // http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_EntityContainer - $entityContainer = $schema->addChild('EntityContainer'); - $entityContainer->addAttribute('Name', 'DefaultContainer'); - - // http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_EntityType - foreach (Lodata::getEntityTypes() as $entityType) { - $entityTypeElement = $schema->addChild('EntityType'); - $entityTypeElement->addAttribute('Name', $entityType->getResolvedName($namespace)); - - // http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_Key - $keyField = $entityType->getKey(); - - if ($keyField) { - $entityTypeKey = $entityTypeElement->addChild('Key'); - $entityTypeKeyPropertyRef = $entityTypeKey->addChild('PropertyRef'); - $entityTypeKeyPropertyRef->addAttribute('Name', $keyField->getName()); - } - - // http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_StructuralProperty - foreach ($entityType->getDeclaredProperties() as $property) { - $entityTypeProperty = $entityTypeElement->addChild('Property'); - $entityTypeProperty->addAttribute('Name', $property->getName()); - - // http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_Type - $entityTypeProperty->addAttribute('Type', $property->getType()->getIdentifier()); - - // http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_TypeFacets - $entityTypeProperty->addAttribute( - 'Nullable', - Boolean::factory($property->isNullable())->toUrl() - ); - - foreach ($property->getAnnotations() as $annotation) { - $annotation->append($entityTypeProperty); - } - } - - // http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#_Toc38530365 - /** @var NavigationProperty $navigationProperty */ - foreach ($entityType->getNavigationProperties() as $navigationProperty) { - /** @var EntityType $targetEntityType */ - $targetEntityType = $navigationProperty->getType(); - - $navigationPropertyElement = $entityTypeElement->addChild('NavigationProperty'); - $navigationPropertyElement->addAttribute('Name', $navigationProperty->getName()); - $navigationPropertyType = $targetEntityType->getIdentifier(); - if ($navigationProperty->isCollection()) { - $navigationPropertyType = 'Collection('.$navigationPropertyType.')'; - } - - $navigationPropertyPartner = $navigationProperty->getPartner(); - if ($navigationPropertyPartner) { - $navigationPropertyElement->addAttribute( - 'Partner', - $navigationPropertyPartner->getName() - ); - } - - $navigationPropertyElement->addAttribute('Type', $navigationPropertyType); - $navigationPropertyElement->addAttribute( - 'Nullable', - Boolean::factory($navigationProperty->isNullable())->toUrl() - ); - - /** @var ReferentialConstraint $constraint */ - foreach ($navigationProperty->getConstraints() as $constraint) { - $referentialConstraint = $navigationPropertyElement->addChild('ReferentialConstraint'); - $referentialConstraint->addAttribute('Property', $constraint->getProperty()->getName()); - $referentialConstraint->addAttribute( - 'ReferencedProperty', - $constraint->getReferencedProperty()->getName() - ); - } - } - } - - foreach (Lodata::getEnumerationTypes() as $enumerationType) { - $enumerationTypeElement = $schema->addChild('EnumType'); - $enumerationTypeElement->addAttribute('Name', $enumerationType->getResolvedName($namespace)); - $enumerationTypeElement->addAttribute( - 'UnderlyingType', - $enumerationType->getUnderlyingType()->getResolvedName($namespace) - ); - $enumerationTypeElement->addAttribute('IsFlags', Boolean::factory($enumerationType->getIsFlags())->toUrl()); - - /** @var EnumMember $memberValue */ - foreach ($enumerationType->getMembers() as $memberName => $memberValue) { - $memberElement = $enumerationTypeElement->addChild('Member'); - $memberElement->addAttribute('Name', $memberName); - $memberElement->addAttribute('Value', $memberValue->getValue()); - } - } - - foreach (Lodata::getResources() as $resource) { - $resourceElement = null; - - switch (true) { - case $resource instanceof Singleton: - // https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#_Toc38530395 -<<<<<<< Updated upstream - $resourceElement = $entityContainer->addChild('Singleton'); - $resourceElement->addAttribute('Name', $resource->getResolvedName($namespace)); - $resourceElement->addAttribute('Type', $resource->getType()->getIdentifier()); -======= - $resourceElement = $singletonElement = $entityContainer->addChild('Singleton'); - $singletonElement->addAttribute('Name', $resource->getResolvedName($namespace)); - $singletonElement->addAttribute('Type', $resource->getType()->getIdentifier()); ->>>>>>> Stashed changes - break; - - case $resource instanceof EntitySet: - // http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_EntitySet -<<<<<<< Updated upstream - $resourceElement = $entityContainer->addChild('EntitySet'); - $resourceElement->addAttribute('Name', $resource->getResolvedName($namespace)); - $resourceElement->addAttribute( - 'EntityType', - $resource->getType()->getIdentifier() - ); - - // http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_NavigationPropertyBinding - /** @var NavigationBinding $binding */ - foreach ($resource->getNavigationBindings() as $binding) { - $navigationPropertyBindingElement = $resourceElement->addChild('NavigationPropertyBinding'); - $navigationPropertyBindingElement->addAttribute( - 'Path', - $binding->getPath()->getName() - ); - $navigationPropertyBindingElement->addAttribute( - 'Target', - $binding->getTarget()->getResolvedName($namespace) - ); - } -======= - $resourceElement = $entitySetElement = $entityContainer->addChild('EntitySet'); - $entitySetElement->addAttribute('Name', $resource->getResolvedName($namespace)); - $entitySetElement->addAttribute( - 'EntityType', - $resource->getType()->getIdentifier() - ); ->>>>>>> Stashed changes - break; - - /** @var Operation $resource */ - case $resource instanceof Operation: -<<<<<<< Updated upstream - $resourceElement = $schema->addChild($resource->getKind()); - $resourceElement->addAttribute('Name', $resource->getResolvedName($namespace)); -======= - $resourceElement = $operationElement = $schema->addChild($resource->getKind()); - $operationElement->addAttribute('Name', $resource->getResolvedName($namespace)); ->>>>>>> Stashed changes - if ($resource->getBindingParameterName()) { - $resourceElement->addAttribute('IsBound', Constants::TRUE); - } - - // Ensure the binding parameter is first, if it exists. Filter out non-odata arguments. - $arguments = $resource->getArguments()->sort(function (Argument $a, Argument $b) use ($resource) { - if ($a->getName() === $resource->getBindingParameterName()) { - return -1; - } - - if ($b->getName() === $resource->getBindingParameterName()) { - return 1; - } - - return 0; - })->filter(function ($argument) use ($resource) { - if ($argument instanceof PrimitiveArgument) { - return true; - } - - if (($argument instanceof EntitySetArgument || $argument instanceof EntityArgument) && $resource->getBindingParameterName() === $argument->getName()) { - return true; - } - - return false; - }); - - /** @var Argument $argument */ - foreach ($arguments as $argument) { - $parameterElement = $resourceElement->addChild('Parameter'); - $parameterElement->addAttribute('Name', $argument->getName()); - $parameterElement->addAttribute('Type', $argument->getType()->getIdentifier()); - $parameterElement->addAttribute( - 'Nullable', - Boolean::factory($argument->isNullable())->toUrl() - ); - } - - $returnType = $resource->getReturnType(); - if (null !== $returnType) { - $returnTypeElement = $resourceElement->addChild('ReturnType'); - - if ($resource->returnsCollection()) { - $returnTypeElement->addAttribute('Type', - 'Collection('.$returnType->getIdentifier().')'); - } else { - $returnTypeElement->addAttribute('Type', $returnType->getIdentifier()); - } - - $returnTypeElement->addAttribute( - 'Nullable', - Boolean::factory($resource->isNullable())->toUrl() - ); - } - - $operationImport = $entityContainer->addChild($resource->getKind().'Import'); - $operationImport->addAttribute('Name', $resource->getResolvedName($namespace)); - $operationImport->addAttribute( - $resource->getKind(), - $resource->getResolvedName($namespace) - ); - break; - } - - // http://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_NavigationPropertyBinding - /** @var NavigationBinding $binding */ - foreach ($resource->getNavigationBindings() as $binding) { - $navigationPropertyBindingElement = $resourceElement->addChild('NavigationPropertyBinding'); - $navigationPropertyBindingElement->addAttribute( - 'Path', - $binding->getPath()->getName() - ); - $navigationPropertyBindingElement->addAttribute( - 'Target', - $binding->getTarget()->getResolvedName($namespace) - ); - } - - // https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#_Toc38530341 - if ($resource instanceof AnnotationInterface) { - /** @var Annotation $annotation */ - foreach ($resource->getAnnotations() as $annotation) { - $annotation->append($resourceElement); - } - } - } - - $schemaAnnotations = $schema->addChild('Annotations'); - $schemaAnnotations->addAttribute('Target', $namespace.'.'.'DefaultContainer'); - - foreach (Lodata::getAnnotations() as $annotation) { - $annotation->append($schemaAnnotations); - } - - $transaction->sendOutput($root->asXML()); - } - - public function response(Transaction $transaction, ?ContextInterface $context = null): Response - { - $transaction->assertMethod(Request::METHOD_GET); - - return $transaction->getResponse()->setCallback(function () use ($transaction) { - $this->emitStream($transaction); - }); - } -}