Sokil\Mongo\Operator::pull PHP Method

pull() public method

The $pull operator removes from an existing array all instances of a value or values that match a specified query.
public pull ( integer | string | Expression | callable $expression, mixed | Expression | callable $value = null ) : Operator
$expression integer | string | Expression | callable
$value mixed | Expression | callable
return Operator
    public function pull($expression, $value = null)
    {
        // field-value pulling
        if ($value) {
            // expression
            if (is_callable($value)) {
                $configurator = $value;
                $value = new Expression();
                call_user_func($configurator, $value);
            }
            if ($value instanceof Expression) {
                $value = $value->toArray();
            }
            $this->operators['$pull'][$expression] = $value;
            return $this;
        }
        // expression
        if (is_callable($expression)) {
            $configurator = $expression;
            $expression = new Expression();
            call_user_func($configurator, $expression);
        }
        if ($expression instanceof Expression) {
            $expression = $expression->toArray();
        } elseif (!is_array($expression)) {
            throw new \InvalidArgumentException('Expression must be field name, callable or Expression object');
        }
        if (!isset($this->operators['$pull'])) {
            // no $pull operator found
            $this->operators['$pull'] = $expression;
        } else {
            // $pull operator found
            $this->operators['$pull'] = array_merge($this->operators['$pull'], $expression);
        }
        return $this;
    }