-
-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define psalm types for most pipeline stages
- Loading branch information
Showing
31 changed files
with
1,174 additions
and
347 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/AbstractReplace.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\ODM\MongoDB\Aggregation\Stage; | ||
|
||
use Doctrine\ODM\MongoDB\Aggregation\Builder; | ||
use Doctrine\ODM\MongoDB\Aggregation\Expr; | ||
use Doctrine\ODM\MongoDB\DocumentManager; | ||
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; | ||
use Doctrine\ODM\MongoDB\Persisters\DocumentPersister; | ||
use Doctrine\ODM\MongoDB\Types\Type; | ||
|
||
use function array_map; | ||
use function is_array; | ||
use function is_string; | ||
use function substr; | ||
|
||
abstract class AbstractReplace extends Operator | ||
{ | ||
/** @var string|mixed[]|Expr|null */ | ||
protected $expression; | ||
protected DocumentManager $dm; | ||
protected ClassMetadata $class; | ||
|
||
/** @param string|mixed[]|Expr|null $expression */ | ||
final public function __construct(Builder $builder, DocumentManager $documentManager, ClassMetadata $class, $expression = null) | ||
{ | ||
Operator::__construct($builder); | ||
|
||
$this->dm = $documentManager; | ||
$this->class = $class; | ||
$this->expression = $expression; | ||
} | ||
|
||
private function getDocumentPersister(): DocumentPersister | ||
{ | ||
return $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name); | ||
} | ||
|
||
/** @return array|string */ | ||
protected function getReplaceExpression() | ||
{ | ||
return $this->expression !== null ? $this->convertExpression($this->expression) : $this->expr->getExpression(); | ||
} | ||
|
||
/** | ||
* @param mixed[]|string|mixed $expression | ||
* | ||
* @return mixed[]|string|mixed | ||
*/ | ||
private function convertExpression($expression) | ||
{ | ||
if (is_array($expression)) { | ||
return array_map([$this, 'convertExpression'], $expression); | ||
} | ||
|
||
if (is_string($expression) && substr($expression, 0, 1) === '$') { | ||
return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1)); | ||
} | ||
|
||
return Type::convertPHPToDatabaseValue(Expr::convertExpression($expression)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.