-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implementation of pagination for Apigee X Teams-3x
- Loading branch information
1 parent
dd41043
commit 7b6c2fe
Showing
8 changed files
with
447 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Apigee\Edge\Api\ApigeeX\Controller; | ||
|
||
use Apigee\Edge\Api\Management\Controller\OrganizationController; | ||
use Apigee\Edge\Api\Management\Controller\OrganizationControllerInterface; | ||
use Apigee\Edge\ClientInterface; | ||
use Apigee\Edge\Controller\EntityController; | ||
use Apigee\Edge\Controller\OrganizationControllerAwareTrait; | ||
use Apigee\Edge\Serializer\EntitySerializerInterface; | ||
|
||
/** | ||
* Class PaginatedEntityController. | ||
* | ||
* @see \Apigee\Edge\Api\ApigeeX\Controller\PaginatedEntityControllerInterface | ||
*/ | ||
abstract class PaginatedEntityController extends EntityController implements PaginatedEntityControllerInterface | ||
{ | ||
use OrganizationControllerAwareTrait; | ||
|
||
/** @var \Apigee\Edge\Api\Management\Controller\OrganizationControllerInterface */ | ||
protected $organizationController; | ||
|
||
/** | ||
* PaginatedEntityController constructor. | ||
* | ||
* @param string $organization | ||
* @param \Apigee\Edge\ClientInterface $client | ||
* @param \Apigee\Edge\Serializer\EntitySerializerInterface|null $entitySerializer | ||
* @param OrganizationControllerInterface|null $organizationController | ||
*/ | ||
public function __construct( | ||
string $organization, | ||
ClientInterface $client, | ||
?EntitySerializerInterface $entitySerializer = null, | ||
OrganizationControllerInterface $organizationController = null | ||
) { | ||
parent::__construct($organization, $client, $entitySerializer); | ||
$this->organizationController = $organizationController ?: new OrganizationController($client); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getOrganizationController(): OrganizationControllerInterface | ||
{ | ||
return $this->organizationController; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/Api/ApigeeX/Controller/PaginatedEntityControllerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Apigee\Edge\Api\ApigeeX\Controller; | ||
|
||
use Apigee\Edge\Api\ApigeeX\Structure\PagerInterface; | ||
|
||
/** | ||
* Interface PaginatedEntityControllerInterface. | ||
* | ||
* For those controllers that contains as least one method that communicates | ||
* with an endpoint which supports pagination. | ||
*/ | ||
interface PaginatedEntityControllerInterface | ||
{ | ||
/** | ||
* Creates a pager. | ||
* | ||
* @param int $limit | ||
* Number of items to return. Default is 0 which means load as much as | ||
* supported. (Different endpoints have different limits, ex.: | ||
* 100 for AppGroup apps.) | ||
* @param string|null $pageToken | ||
* First item in the list, if it is not set then Apigee Edge decides the | ||
* first item. | ||
* | ||
* @return \Apigee\Edge\Api\ApigeeX\Structure\PagerInterface | ||
* The pager object. | ||
*/ | ||
public function createPager(int $limit = 0, ?string $pageToken = null): PagerInterface; | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Api/ApigeeX/Controller/PaginatedEntityListingControllerInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Apigee\Edge\Api\ApigeeX\Controller; | ||
|
||
use Apigee\Edge\Api\ApigeeX\Structure\PagerInterface; | ||
|
||
/** | ||
* Interface PaginatedEntityListingControllerInterface. | ||
* | ||
* For those entities that can be listed as objects and pagination is supported | ||
* on their endpoint. | ||
*/ | ||
interface PaginatedEntityListingControllerInterface extends PaginatedEntityControllerInterface | ||
{ | ||
/** | ||
* Returns list of entities fro Apigee Edge. The returned number of entities | ||
* can be limited, if you do not provide a limit then all entities are | ||
* returned. | ||
* | ||
* On pagination enabled endpoints Apigee X only | ||
* returns certain number of entities in one API call so we have to collect | ||
* all entities by sending multiple API calls to Apigee X synchronously. | ||
* If you do not actually need _all_ entities of a type then always set | ||
* a limit to reduce memory usage and increase speed. | ||
* | ||
* @param \Apigee\Edge\Api\ApigeeX\Structure\PagerInterface|null $pager | ||
* Pager. | ||
* @param string $key_provider | ||
* Getter method on the entity that should provide a unique array key. | ||
* | ||
* @return \Apigee\Edge\Entity\EntityInterface[] | ||
*/ | ||
public function getEntities(PagerInterface $pager = null, string $key_provider = 'id'): array; | ||
} |
44 changes: 44 additions & 0 deletions
44
src/Api/ApigeeX/Controller/PaginatedEntityListingControllerTrait.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
namespace Apigee\Edge\Api\ApigeeX\Controller; | ||
|
||
use Apigee\Edge\Api\ApigeeX\Structure\PagerInterface; | ||
|
||
/** | ||
* Trait PaginatedEntityListingControllerTrait. | ||
* | ||
* @see \Apigee\Edge\Api\ApigeeX\Controller\PaginatedEntityListingControllerInterface | ||
*/ | ||
trait PaginatedEntityListingControllerTrait | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
* | ||
* @return \Apigee\Edge\Entity\EntityInterface[] | ||
*/ | ||
public function getEntities(PagerInterface $pager = null, string $key_provider = 'id'): array | ||
{ | ||
return $this->listEntities($pager, [], $key_provider); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
abstract protected function listEntities(PagerInterface $pager = null, array $query_params = [], string $key_provider = 'id'): array; | ||
} |
Oops, something went wrong.