Skip to content

Commit

Permalink
feat: Allow monitors to override select, condition, and query argumen…
Browse files Browse the repository at this point in the history
…ts to `locate`
  • Loading branch information
hellopablo committed Aug 2, 2024
1 parent f7fef67 commit c75cb81
Showing 1 changed file with 43 additions and 8 deletions.
51 changes: 43 additions & 8 deletions src/Cdn/Monitor/ObjectIsInWidgetData.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Nails\Common\Exception\ModelException;
use Nails\Common\Helper\ArrayHelper;
use Nails\Common\Helper\Model\Condition;
use Nails\Common\Helper\Model\Where;
use Nails\Common\Resource\Entity;
use Nails\Factory;

Expand All @@ -31,17 +32,14 @@ public function locate(CdnObject $oObject): array

$aWidgets = array_keys($aMappings);

$aConditions = array_map(
fn(string $sSlug) => $this->getJsonExtractPath($sSlug),
$aWidgets
);

/** @var Entity[] $aResults */
$aResults = $this
->getModel()
->getAll([
new Condition(implode(PHP_EOL . ' OR ', $aConditions)),
]);
->getAll(array_merge(
$this->getQuerySelect(),
$this->getQueryConditions($aMappings, $aWidgets),
$this->getQuerySort(),
));

$aDetails = [];
foreach ($aResults as $oEntity) {
Expand All @@ -67,6 +65,43 @@ public function locate(CdnObject $oObject): array

// --------------------------------------------------------------------------

/**
* @return Select[]
*/
protected function getQuerySelect(): array
{
return [];
}

// --------------------------------------------------------------------------

/**
* @return Where[]|Condition[]
*/
protected function getQueryConditions(array $aMappings, array $aWidgets): array
{
$aConditions = array_map(
fn(string $sSlug) => $this->getJsonExtractPath($sSlug),
$aWidgets
);

return [
new Condition(implode(PHP_EOL . ' OR ', $aConditions)),
];
}

// --------------------------------------------------------------------------

/**
* @return Sort[]
*/
protected function getQuerySort(): array
{
return [];
}

// --------------------------------------------------------------------------

protected function getWidgetMappings(): array
{
/** @var Cdn $oCdnMonitor */
Expand Down

0 comments on commit c75cb81

Please sign in to comment.