Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix using $this pseudo variable inside a static function #181

Merged
merged 3 commits into from
Sep 20, 2020
Merged
Show file tree
Hide file tree
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
21 changes: 12 additions & 9 deletions lib/Core/Site/QueryType/Location/Children.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,21 @@ protected function configureOptions(OptionsResolver $resolver): void
$resolver->setRequired('location');
$resolver->setAllowedTypes('location', SiteLocation::class);

$resolver->setDefault('sort', static function (Options $options): array {
/** @var \Netgen\EzPlatformSiteApi\API\Values\Location $location */
$location = $options['location'];
$resolver->setDefault(
'sort',
function (Options $options): array {
/** @var \Netgen\EzPlatformSiteApi\API\Values\Location $location */
$location = $options['location'];

try {
return $location->innerLocation->getSortClauses();
} catch (NotImplementedException $e) {
$this->logger->notice("Cannot use sort clausses from parent location: {$e->getMessage()}");
try {
return $location->innerLocation->getSortClauses();
} catch (NotImplementedException $e) {
$this->logger->notice("Cannot use sort clauses from parent location: {$e->getMessage()}");

return [];
return [];
}
}
});
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions lib/Core/Site/QueryType/Location/Siblings.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ protected function configureOptions(OptionsResolver $resolver): void

$resolver->setDefault(
'sort',
static function (Options $options): array {
function (Options $options): array {
/** @var \Netgen\EzPlatformSiteApi\API\Values\Location $location */
$location = $options['location'];

try {
return $location->parent->innerLocation->getSortClauses();
} catch (NotImplementedException $e) {
$this->logger->notice("Cannot use sort clausses from parent location: {$e->getMessage()}");
$this->logger->notice("Cannot use sort clauses from parent location: {$e->getMessage()}");

return [];
}
Expand Down
8 changes: 4 additions & 4 deletions lib/Core/Site/Values/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,18 @@ public function filterSiblings(array $contentTypeIdentifiers = [], int $maxPerPa
private function getFilterPager(array $criteria, int $maxPerPage = 25, int $currentPage = 1): Pagerfanta
{
try {
$sortClausses = $this->innerLocation->getSortClauses();
$sortClauses = $this->innerLocation->getSortClauses();
} catch (NotImplementedException $e) {
$this->logger->notice("Cannot use sort clausses from parent location: {$e->getMessage()}");
$this->logger->notice("Cannot use sort clauses from parent location: {$e->getMessage()}");

$sortClausses = [];
$sortClauses = [];
}

$pager = new Pagerfanta(
new FilterAdapter(
new LocationQuery([
'filter' => new LogicalAnd($criteria),
'sortClauses' => $sortClausses,
'sortClauses' => $sortClauses,
]),
$this->site->getFilterService()
)
Expand Down