src/Bridge/Doctrine/MongoDbOdm/Filter/DateFilter.php
private function addMatch(Builder $aggregationBuilder, string $field, string $operator, string $value, string $nullManagement = null): void
    {
        try {
            $value = new \DateTime($value);
        } catch (\Exception $e) {
            // Silently ignore this filter if it can not be transformed to a \DateTime
            $this->logger->notice('Invalid filter ignored', [
                'exception' => new InvalidArgumentException(sprintf('The field "%s" has a wrong date format. Use one accepted by the \DateTime constructor', $field)),
            ]);

            return;
        }

        $operatorValue = [
            self::PARAMETER_BEFORE => '$lte',
            self::PARAMETER_STRICTLY_BEFORE => '$lt',
            self::PARAMETER_AFTER => '$gte',
            self::PARAMETER_STRICTLY_AFTER => '$gt',
        ];

        if ((self::INCLUDE_NULL_BEFORE === $nullManagement && \in_array($operator, [self::PARAMETER_BEFORE, self::PARAMETER_STRICTLY_BEFORE], true)) ||
            (self::INCLUDE_NULL_AFTER === $nullManagement && \in_array($operator, [self::PARAMETER_AFTER, self::PARAMETER_STRICTLY_AFTER], true)) ||
            (self::INCLUDE_NULL_BEFORE_AND_AFTER === $nullManagement && \in_array($operator, [self::PARAMETER_AFTER, self::PARAMETER_STRICTLY_AFTER, self::PARAMETER_BEFORE, self::PARAMETER_STRICTLY_BEFORE], true))
        ) {
            $aggregationBuilder->match()->addOr(
                $aggregationBuilder->matchExpr()->field($field)->operator($operatorValue[$operator], $value),
                $aggregationBuilder->matchExpr()->field($field)->equals(null)
            );

            return;
        }

        $aggregationBuilder->match()->addAnd($aggregationBuilder->matchExpr()->field($field)->operator($operatorValue[$operator], $value));
    }
private function addMatch(Builder $aggregationBuilder, string $field, string $operator, string $value, string $nullManagement = null): void
    {
        try {
            $value = new \DateTime($value);
        } catch (\Exception $e) {
            // Silently ignore this filter if it can not be transformed to a \DateTime
            $this->logger->notice('Invalid filter ignored', [
                'exception' => new InvalidArgumentException(sprintf('The field "%s" has a wrong date format. Use one accepted by the \DateTime constructor', $field)),
            ]);

            return;
        }

        $operatorValue = [
            self::PARAMETER_BEFORE => '$lte',
            self::PARAMETER_STRICTLY_BEFORE => '$lt',
            self::PARAMETER_AFTER => '$gte',
            self::PARAMETER_STRICTLY_AFTER => '$gt',
        ];

        if ((self::INCLUDE_NULL_BEFORE === $nullManagement && \in_array($operator, [self::PARAMETER_BEFORE, self::PARAMETER_STRICTLY_BEFORE], true)) ||
            (self::INCLUDE_NULL_AFTER === $nullManagement && \in_array($operator, [self::PARAMETER_AFTER, self::PARAMETER_STRICTLY_AFTER], true)) ||
            (self::INCLUDE_NULL_BEFORE_AND_AFTER === $nullManagement && \in_array($operator, [self::PARAMETER_AFTER, self::PARAMETER_STRICTLY_AFTER, self::PARAMETER_BEFORE, self::PARAMETER_STRICTLY_BEFORE], true))
        ) {
            $aggregationBuilder->match()->addOr(
                $aggregationBuilder->matchExpr()->field($field)->operator($operatorValue[$operator], $value),
                $aggregationBuilder->matchExpr()->field($field)->equals(null)
            );

            return;
        }

        $aggregationBuilder->match()->addAnd($aggregationBuilder->matchExpr()->field($field)->operator($operatorValue[$operator], $value));
    }
private function addMatch ( Builder $ aggregationBuilder , string $ field , string $ operator , string $ value , string $ nullManagement = null ) : void { try { $ value = new \ DateTime ( $ value ) ; } catch ( \ Exception $ e ) { // Silently ignore this filter if it can not be transformed to a \DateTime $ this -> logger -> notice ( 'Invalid filter ignored' , [ 'exception' => new InvalidArgumentException ( sprintf ( 'The field "%s" has a wrong date format. Use one accepted by the \DateTime constructor' , $ field ) ) , ] ) ; return ; } $ operatorValue = [ self :: PARAMETER_BEFORE => '$lte' , self :: PARAMETER_STRICTLY_BEFORE => '$lt' , self :: PARAMETER_AFTER => '$gte' , self :: PARAMETER_STRICTLY_AFTER => '$gt' , ] ; if ( ( self :: INCLUDE_NULL_BEFORE === $ nullManagement && \ in_array ( $ operator , [ self :: PARAMETER_BEFORE , self :: PARAMETER_STRICTLY_BEFORE ] , true ) ) || ( self :: INCLUDE_NULL_AFTER === $ nullManagement && \ in_array ( $ operator , [ self :: PARAMETER_AFTER , self :: PARAMETER_STRICTLY_AFTER ] , true ) ) || ( self :: INCLUDE_NULL_BEFORE_AND_AFTER === $ nullManagement && \ in_array ( $ operator , [ self :: PARAMETER_AFTER , self :: PARAMETER_STRICTLY_AFTER , self :: PARAMETER_BEFORE , self :: PARAMETER_STRICTLY_BEFORE ] , true ) ) ) { $ aggregationBuilder -> match ( ) -> addOr ( $ aggregationBuilder -> matchExpr ( ) -> field ( $ field ) -> operator ( $ operatorValue [ $ operator ] , $ value ) , $ aggregationBuilder -> matchExpr ( ) -> field ( $ field ) -> equals ( null ) ) ; return ; } $ aggregationBuilder -> match ( ) -> addAnd ( $ aggregationBuilder -> matchExpr ( ) -> field ( $ field ) -> operator ( $ operatorValue [ $ operator ] , $ value ) ) ; }
Adds the match stage according to the chosen null management.
Adds the match stage according to the chosen null management .