Takes a Closure object, decorates it with a SerializableClosure object,
then performs the serialization.

@param \Closure    $closure Closure to serialize.
@param string|null $type

@return string Serialized closure.
@throws \RuntimeException
356064
public static function serialize(\Closure $closure, string $type = null): string
    {
        self::$serializeType = $type;

        $serialized = Serialize::encode(new SerializableClosure($closure), $type);

        if ($serialized === null) {
            throw new \RuntimeException('The closure could not be serialized.');
        }

        return $serialized;
    }
220163
public function sort(Closure $closure)
    {
        $sorted = clone $this;

        $sorted->models = Objects::sort($sorted->models, $closure);

        return $sorted;
    }
51799
public function foldrWithKeys(callable $closure, $initial)
    {
        return $this
            ->reverse()
            ->foldlWithKeys(
                function ($acc, $key, $x) use ($closure) {
                    return $closure($key, $x, $acc);
                },
                $initial
            );
    }
890885
public static function object(\Closure $callback) {
		$obj = new Object;
		$callback->__invoke($obj);
		return json_encode($obj);
	}
93230
public static function from(Closure $closure)
    {
        if (static::$context === null) {
            $instance = new static($closure);
        } elseif (isset(static::$context->scope[$closure])) {
            $instance = static::$context->scope[$closure];
        } else {
            $instance = new static($closure);
            static::$context->scope[$closure] = $instance;
        }

        return $instance;
    }
1277387
public function send($closure = null) {

		if(gettype($closure) == 'object') {
			call_user_func($closure, $this);
		}

		//Renders the optional viewmodels and assign the mail variables to them
		foreach($this -> viewmodels as $type => $view) {

			if(null !== $view) {

				$viewmodel = new ViewModel($view, false);
				$viewmodel -> assign($this -> variables);

				$this -> message[$type] = $viewmodel -> render();
			}
		}

		$to 	 = $this -> formatTo();
		$headers = $this -> formatHeaders();
		$message = $this -> formatMessage();

		@mail($to, $this -> subject, $message, $headers);

		if(null === error_get_last()) {
			$this -> send = true;			
		}

		return $this;
	}
176406
protected function createCallback(string $method): \Closure
    {
        return \Closure::bind(static function (...$args) use ($method) {
            return self::$method(...$args);
        }, null, $this->type);
    }
997403
public function rule(\Closure $closure = null)
    {
        if (null !== $closure) {
            $this->rules[] = $closure;

            return $this;
        }

        return $this->rules[] = new ExprBuilder($this->node);
    }
1239031
function sortCustomKey(callable $closure) {
        $args = $this->baseStorageArgs;
        $args[] = parent::sortCustomKey($closure)->all();
        
        return (new static(...$args));
    }
1309271
public function tryRepeating(\Closure $closure, $time = null)
    {
        if (null === $time) {
            $time = $this->timeout;
        }

        $last = null;
        $count = 0;
        do {
            $count++;
            try {
                return $closure($this->getBrowser());
            } catch (\Exception $e) {
                $last = $e;
            }

            $wait = min(1000, $time);
            $time -= $wait;
            usleep($wait*1000);
        } while ($time > 0);

        throw new \RuntimeException(sprintf('Repeatedly failed, %s time: %s', $count, $last->getMessage()), 0, $last);

    }
746358
public function getFactory(string $type): Closure
    {
        assert(isset($this->closures[$type]));
        return $this->closures[$type];
    }
601863
public function resolve($closure)
    {
        if (is_array($closure)) {
            $reflection = new \ReflectionMethod($closure[0], $closure[1]);
        } else {
            $reflection = new \ReflectionFunction($closure);
        }

        $arguments = $reflection->getParameters();

        $arguments = array_map(function ($argument) {
            return isset($this->bindMaps[$argument->name]) ? $this->bindMaps[$argument->name] : null;
        }, $arguments);

        return @call_user_func_array($closure, $arguments);
    }
392590
public function extend($abstract, Closure $closure)
    {
        $abstract = $this->getAlias($abstract);

        if (isset($this->instances[$abstract])) {
            $this->instances[$abstract] = $closure($this->instances[$abstract], $this);

            $this->rebound($abstract);
        } else {
            $this->extenders[$abstract][] = $closure;

            if ($this->resolved($abstract)) {
                $this->rebound($abstract);
            }
        }
    }
908392
private function addClosure(Closure $closure, int $providerType): void
    {
        $type = self::validateClosure($closure);
        if (isset($this->providerType[$type])) {
            throw new DuplicateSupportedTypeException;
        }

        $this->providerType[$type] = $providerType;
        $this->closures[$type] = $closure;
    }
42819
protected function bindClosureToInstance($closure, $instance)
    {
        if ($closure instanceof \Closure) {
            $closure = $closure->bind($closure, $instance, get_class($instance));
        }

        return $closure;
    }
268377
public function ifTrue(\Closure $closure = null)
    {
        if (null === $closure) {
            $closure = function ($v) { return true === $v; };
        }

        $this->ifPart = $closure;

        return $this;
    }
392290
public function it($example, \Closure $closure = null)
    {
        if ($closure === null) {
            $that = $this;
            $closure = function() use ($that) { $that->pending(); };
        }
        $example = new Example($example, $closure);
        $example->setParent($this->__stack->top());
        $this->__stack->top()->add($example);
        return $example;
    }