1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-09 00:06:55 +02:00

Add ability for PageFinder and PagesLoader to retain additional info about selectors and PageFinder instance for debugging purposes

This commit is contained in:
Ryan Cramer
2019-11-12 11:07:39 -05:00
parent 0478c65938
commit 4eeca2eeeb
2 changed files with 37 additions and 0 deletions

View File

@@ -171,6 +171,7 @@ class PageFinder extends Wire {
protected $reverseAfter = false; // reverse order after load?
protected $pageArrayData = array(); // any additional data that should be populated back to any resulting PageArray objects
protected $partialMatchOperators = array('%=', '^=', '$=', '%^=', '%$=', '*=');
protected $finalSelectors = null; // Fully parsed final selectors
protected $singlesFields = array( // fields that can only be used by themselves (not OR'd with other fields)
'has_parent',
'hasParent',
@@ -1426,6 +1427,7 @@ class PageFinder extends Wire {
}
$this->postProcessQuery($query);
$this->finalSelectors = $selectors;
return $query;
}
@@ -2889,5 +2891,20 @@ class PageFinder extends Wire {
return false;
}
/**
* Get the fully parsed/final selectors used in the last find() operation
*
* Should only be called after a find() or findIDs() operation, otherwise returns null.
*
* #pw-internal
*
* @return Selectors|null
* @since 3.0.146
*
*/
public function getSelectors() {
return $this->finalSelectors;
}
}

View File

@@ -48,6 +48,14 @@ class PagesLoader extends Wire {
*/
protected $totalPagesLoaded = 0;
/**
* Last used instance of PageFinder
*
* @var PageFinder|null
*
*/
protected $lastPageFinder = null;
/**
* Debug mode for pages class
*
@@ -359,6 +367,7 @@ class PagesLoader extends Wire {
$pages->setStart($start);
$pages->setSelectors($selectorString);
$pages->setTrackChanges(true);
$this->lastPageFinder = $pageFinder;
if($loadPages && $cachePages) {
if(strpos($selectorString, 'sort=random') !== false) {
@@ -1229,5 +1238,16 @@ class PagesLoader extends Wire {
public function getTotalPagesLoaded() {
return $this->totalPagesLoaded;
}
/**
* Get last used instance of PageFinder (for debugging purposes)
*
* @return PageFinder|null
* @since 3.0.146
*
*/
public function getLastPageFinder() {
return $this->lastPageFinder;
}
}