Skip to content

Commit

Permalink
FindAll iterator() using getResourceNameFromClass()
Browse files Browse the repository at this point in the history
  • Loading branch information
ecoologic committed Oct 25, 2023
1 parent 5922fb6 commit 0842d6f
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 23 deletions.
4 changes: 0 additions & 4 deletions src/Zendesk/API/Resources/Core/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,4 @@ public function merge(array $params = [])

return $response;
}

protected function paginatedPath() {
return 'tickets';
}
}
14 changes: 0 additions & 14 deletions src/Zendesk/API/Resources/Core/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,6 @@ class Users extends ResourceAbstract
*/
protected $identities;

/**
* Usage:
* foreach ($usersIterator as $user) {
* process($user)
* }
*
* @return PaginationIterator to fetch all pages.
*/
public function iterator()
{
$strategy = new CbpStrategy($this, 'users', 2);
return new PaginationIterator($strategy);
}

/**
* {@inheritdoc}
*/
Expand Down
1 change: 0 additions & 1 deletion src/Zendesk/API/Resources/ResourceAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ protected function getResourceNameFromClass()
// This converts the resource name from camel case to underscore case.
// e.g. MyClass => my_class
$underscored = strtolower(preg_replace('/(?<!^)([A-Z])/', '_$1', $resourceName));

return strtolower($underscored);
}

Expand Down
7 changes: 3 additions & 4 deletions src/Zendesk/API/Traits/Resource/FindAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function findAll(array $params = [], $routeKey = __FUNCTION__)
public function iterator()
{
$strategyClass = $this->paginationStrategyClass();
$strategy = new $strategyClass($this, $this->paginatedPath(), 2);
$strategy = new $strategyClass($this, $this->resourcesRoot(), 2);
return new PaginationIterator($strategy);
}

Expand All @@ -59,8 +59,7 @@ private function paginationStrategyClass() {
return CbpStrategy::class;
}

// TODO: abstract
protected function paginatedPath() {
return "/";
protected function resourcesRoot() {
return $this->getResourceNameFromClass();
}
}

0 comments on commit 0842d6f

Please sign in to comment.