Skip to content

Commit

Permalink
Use templates for Builder::addStage
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Mar 17, 2023
1 parent f1bd9a7 commit e35e5d8
Showing 1 changed file with 34 additions and 59 deletions.
93 changes: 34 additions & 59 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ public function __construct(DocumentManager $dm, string $documentName)
public function addFields(): Stage\AddFields
{
$stage = new Stage\AddFields($this);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -103,9 +102,8 @@ public function addFields(): Stage\AddFields
public function bucket(): Stage\Bucket
{
$stage = new Stage\Bucket($this, $this->dm, $this->class);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -125,9 +123,8 @@ public function bucket(): Stage\Bucket
public function bucketAuto(): Stage\BucketAuto
{
$stage = new Stage\BucketAuto($this, $this->dm, $this->class);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -141,9 +138,8 @@ public function bucketAuto(): Stage\BucketAuto
public function collStats(): Stage\CollStats
{
$stage = new Stage\CollStats($this);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -155,9 +151,8 @@ public function collStats(): Stage\CollStats
public function count(string $fieldName): Stage\Count
{
$stage = new Stage\Count($this, $fieldName);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -168,9 +163,8 @@ public function count(string $fieldName): Stage\Count
public function densify(string $fieldName): Stage\Densify
{
$stage = new Stage\Densify($this, $fieldName);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand Down Expand Up @@ -208,9 +202,8 @@ public function expr(): Expr
public function facet(): Stage\Facet
{
$stage = new Stage\Facet($this);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -221,9 +214,8 @@ public function facet(): Stage\Facet
public function fill(): Stage\Fill
{
$stage = new Stage\Fill($this);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -244,9 +236,8 @@ public function fill(): Stage\Fill
public function geoNear($x, $y = null): Stage\GeoNear
{
$stage = new Stage\GeoNear($this, $x, $y);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand Down Expand Up @@ -347,9 +338,8 @@ public function getStage(int $index): Stage
public function graphLookup(string $from): Stage\GraphLookup
{
$stage = new Stage\GraphLookup($this, $from, $this->dm, $this->class);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -361,9 +351,8 @@ public function graphLookup(string $from): Stage\GraphLookup
public function group(): Stage\Group
{
$stage = new Stage\Group($this);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -384,9 +373,8 @@ public function hydrate(?string $className): self
public function indexStats(): Stage\IndexStats
{
$stage = new Stage\IndexStats($this);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -397,9 +385,8 @@ public function indexStats(): Stage\IndexStats
public function limit(int $limit): Stage\Limit
{
$stage = new Stage\Limit($this, $limit);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -412,9 +399,8 @@ public function limit(int $limit): Stage\Limit
public function lookup(string $from): Stage\Lookup
{
$stage = new Stage\Lookup($this, $from, $this->dm, $this->class);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -426,9 +412,8 @@ public function lookup(string $from): Stage\Lookup
public function match(): Stage\MatchStage
{
$stage = new Stage\MatchStage($this);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -451,9 +436,8 @@ public function matchExpr(): QueryExpr
public function merge(): Stage\Merge
{
$stage = new Stage\Merge($this, $this->dm);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -465,9 +449,8 @@ public function merge(): Stage\Merge
public function out(string $from): Stage\Out
{
$stage = new Stage\Out($this, $from, $this->dm);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -480,9 +463,8 @@ public function out(string $from): Stage\Out
public function project(): Stage\Project
{
$stage = new Stage\Project($this);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -494,9 +476,8 @@ public function project(): Stage\Project
public function redact(): Stage\Redact
{
$stage = new Stage\Redact($this);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -513,9 +494,8 @@ public function redact(): Stage\Redact
public function replaceRoot($expression = null): Stage\ReplaceRoot
{
$stage = new Stage\ReplaceRoot($this, $this->dm, $this->class, $expression);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -534,9 +514,8 @@ public function replaceRoot($expression = null): Stage\ReplaceRoot
public function replaceWith($expression = null): Stage\ReplaceWith
{
$stage = new Stage\ReplaceWith($this, $this->dm, $this->class, $expression);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -557,9 +536,8 @@ public function rewindable(bool $rewindable = true): self
public function sample(int $size): Stage\Sample
{
$stage = new Stage\Sample($this, $size);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -573,9 +551,8 @@ public function sample(int $size): Stage\Sample
public function set(): Stage\Set
{
$stage = new Stage\Set($this);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -587,9 +564,8 @@ public function set(): Stage\Set
public function skip(int $skip): Stage\Skip
{
$stage = new Stage\Skip($this, $skip);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -610,9 +586,8 @@ public function sort($fieldName, $order = null): Stage\Sort
$fields = is_array($fieldName) ? $fieldName : [$fieldName => $order];
// fixme: move to sort stage
$stage = new Stage\Sort($this, $this->getDocumentPersister()->prepareSort($fields));
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -624,9 +599,8 @@ public function sort($fieldName, $order = null): Stage\Sort
public function sortByCount(string $expression): Stage\SortByCount
{
$stage = new Stage\SortByCount($this, $expression, $this->dm, $this->class);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -639,9 +613,8 @@ public function sortByCount(string $expression): Stage\SortByCount
public function unionWith(string $collection): Stage\UnionWith
{
$stage = new Stage\UnionWith($this, $this->dm, $collection);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -652,9 +625,8 @@ public function unionWith(string $collection): Stage\UnionWith
public function unset(string ...$fields): Stage\UnsetStage
{
$stage = new Stage\UnsetStage($this, $this->getDocumentPersister(), ...$fields);
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
Expand All @@ -668,15 +640,18 @@ public function unwind(string $fieldName): Stage\Unwind
{
// Fixme: move field name translation to stage
$stage = new Stage\Unwind($this, $this->getDocumentPersister()->prepareFieldName($fieldName));
$this->addStage($stage);

return $stage;
return $this->addStage($stage);
}

/**
* Allows adding an arbitrary stage to the pipeline
*
* @return Stage The method returns the stage given as an argument
* @param T $stage
*
* @return T The method returns the stage given as an argument
*
* @template T of Stage
*/
public function addStage(Stage $stage): Stage
{
Expand Down

0 comments on commit e35e5d8

Please sign in to comment.