Skip to content

Commit

Permalink
Support assigning API products to Apps on creation (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
phdhiren committed Mar 13, 2023
1 parent a6a24db commit 7bae0d5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
"preferred-install": {
"symfony/property-access": "source",
"*": "dist"
},
"allow-plugins": {
"php-http/discovery": true
}
},
"minimum-stability": "dev",
Expand Down
32 changes: 32 additions & 0 deletions src/Api/Management/Entity/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ abstract class App extends Entity implements AppInterface
/** @var \Apigee\Edge\Api\Management\Entity\AppCredential[] */
protected $credentials = [];

/** @var string[] */
protected $initialApiProducts = [];

/**
* App constructor.
*
Expand Down Expand Up @@ -216,4 +219,33 @@ public function setScopes(string ...$scopes): void
{
$this->privateSetScopes(...$scopes);
}

/**
* Get Initial API Products only during app creation.
*
* @return array $initialApiProducts
*
* @internal
*/
final public function getApiProducts(): array
{
return $this->initialApiProducts;
}

/**
* Set Initial API Products only during app creation.
* The method is not supported to update existing App.
*
* @param array $initialApiProducts
*
* @throws \LogicException If used to update existing App.
*/
final public function setInitialApiProducts(array $initialApiProducts): void
{
if (!$this->appId) {
$this->initialApiProducts = $initialApiProducts;
} else {
throw new \LogicException('This method is only supported for creating a new app.');
}
}
}
3 changes: 3 additions & 0 deletions tests/Api/Management/Controller/AppControllerTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ protected function alterArraysBeforeCompareSentAndReceivedPayloadsInCreate(array
{
// This is not returned in the POST/PUT API call responses only in GET.
unset($sentEntityAsArray['appFamily']);
unset($sentEntityAsArray['apiProducts']);
}

/**
Expand All @@ -116,6 +117,8 @@ protected function alterObjectsBeforeCompareResponseAndCreatedEntity(\stdClass &
{
/* @var \Apigee\Edge\Api\Management\Entity\DeveloperAppInterface $created */
$responseObject->appFamily = $created->getAppFamily();

$responseObject->apiProducts = $created->getApiProducts();
}

/**
Expand Down

0 comments on commit 7bae0d5

Please sign in to comment.