Add custom function

@param string $method
@param Closure $closure
@return mixed
979911
public static function bind(string $method, Closure $closure)
  {
    $trace = debug_backtrace()[1];

    if (
      $trace['class'] == 'Modulus\Framework\Upstart\Prototype' &&
      $trace['function'] == 'bind' &&
      count($trace['args']) == 3
    ) {
      if (!array_key_exists($method, Self::$functions)) {
        return Self::$functions[$method] = [$method => $closure];
      }

      throw new CannotAddMethodException;
    }

    throw new CannotCallMethodException('Call to ' . self::class . '::bind() is not allowed');
  }
1202831
public static function prop(string $property, Closure $closure)
  {
    $trace = debug_backtrace()[1];

    if (
      $trace['class'] == 'Modulus\Framework\Upstart\Prototype' &&
      $trace['function'] == 'prop' &&
      count($trace['args']) == 3
    ) {
      if (!array_key_exists($property, Self::$properties)) {
        return Self::$properties[$property] = [$property => $closure];
      }

      throw new CannotAddPropertyException;
    }

    throw new CannotCallMethodException('Call to ' . self::class . '::prop() is not allowed');
  }
902673
protected static function getOrInit($id, Closure $closure)
  {
    if (!self::has($id)) {
      self::set($id, $closure());
    }

    return self::get($id);
  }
630446
public function map(Closure $func)
    {
        $this->guardAgainstInvalidGivenType();
        $elements = $this->collection->map($func)->toArray();
        $newCollection = $this->create();
        foreach ($elements as $key => $element) {
            try {
                $newCollection->set($key, $element);
            } catch (InvalidArgumentException $e) {
                // do nothing, because the mapped item is not instance of type
            }
        }

        return $newCollection;
    }
1362520
public function provideOpenLinkAttributes($context, Closure $closure)
    {
        $closure->bindTo($this);
        $this->extend($this->getContextExtendName($context), $closure);
        return $this;
    }
586611
public function daemonize(Closure $closure = null)
    {
        $processId = $this->fork();

        if ($processId) {
            if (false === is_null($closure)) {
                $process = new Process($processId, $this->master);
                call_user_func($closure, $process);
            }

            return $this->terminateProcess($this->master);
        }

        $this->posix->setsid(); // Child leads the session

        return new Process($this->posix->getpid());
    }
283709
public function byClosure(Closure $closure)
    {
        $this->controller = new Controller();
        if ($this->hasContainer() && method_exists($this->controller, 'raikiri'))
            $this->controller->setContainer($this->raikiri());

        $this->action = $closure->bindTo($this->controller);
    }
248693
public function call(Closure $callback = null, $caller = null)
    {
        if ($callback instanceof Closure) {
            // Make dependency injection possible
            $parameters = $this->resolveMethodDependencies(
                [$caller], new ReflectionFunction($callback)
            );
            call_user_func_array($callback, $parameters);
        }

        return $caller;
    }
610027
public function extend($binding, \Closure $closure)
    {
        $rawObject = $this->getRaw($binding);

        if (is_null($rawObject)) {
            throw new \InvalidArgumentException(sprintf('Cannot extend %s because it has not yet been bound.', $binding));
        }

        $this->bind($binding, function ($container) use ($closure, $rawObject) {
            return $closure($container, $rawObject($container));
        });
    }
1354602
public static function getOrSet($key, \Closure $closure)
    {
        $key = Cache::key($key);
        if (!isset(self::$cache[$key])) {
            self::$cache[$key] = $closure();
        }
        return self::$cache[$key];
    }
1300126
protected function cacheCallback($class, $method, $args, Closure $closure)
    {
        $repositoryId = $this->getRepositoryId();
        $lifetime     = $this->getCacheLifetime();
        $hash         = $this->generateCacheHash($args);
        $cacheKey     = $class.'@'.$method.'.'.$hash;

        // Switch cache driver on runtime
        if ($driver = $this->getCacheDriver()) {
            $this->getContainer('cache')->setDefaultDriver($driver);
        }

        // We need cache tags, check if default driver supports it
        if (method_exists($this->getContainer('cache')->getStore(), 'tags')) {
            $result = $lifetime === -1
                ? $this->getContainer('cache')->tags($repositoryId)->rememberForever($cacheKey, $closure)
                : $this->getContainer('cache')->tags($repositoryId)->remember($cacheKey, $lifetime, $closure);

            // We're done, let's clean up!
            $this->resetRepository();

            return $result;
        }

        // Default cache driver doesn't support tags, let's do it manually
        $this->storeCacheKeys($class, $method, $hash);

        $result = $lifetime === -1
            ? $this->getContainer('cache')->rememberForever($cacheKey, $closure)
            : $this->getContainer('cache')->remember($cacheKey, $lifetime, $closure);

        // We're done, let's clean up!
        $this->resetCachedRepository();

        return $result;
    }
83799
public function setMethod($method)
    {
        $this->method = $method;
        curl_setopt($this->curlHandler, CURLOPT_CUSTOMREQUEST, $method);
        return $this;
    }
748281
public function andFilter(Closure $closure)
    {
        $query = $this->newNestedInstance($closure);

        $filter = $this->grammar->compileAnd($query->getQuery());

        return $this->rawFilter($filter);
    }
603452
public function closure(Closure $closure, array $params = [])
    {
        $reflection = new \ReflectionFunction($closure);
        $resolved = $this->resolve($reflection->getParameters(), $params);
        return call_user_func_array($closure, $resolved);
    }
225558
public function create(\Closure $closure)
    {
        ob_start();
        echo '/*GENERATED AT '.date('Y-m-d H:i:s').'*/';
        $closure();
        $content = ob_get_clean();

        // trim empty spaces and strip only script/style tags.
        $content = trim(preg_replace('/<\/?' . $this->getTypeTag() . '(.|\s)*?>/', '', $content));

        $dirs = explode(DIRECTORY_SEPARATOR, $this->filepath);

        array_pop($dirs);

        $dirs = implode(DIRECTORY_SEPARATOR, $dirs);

        if(!is_dir($dirs))
            mkdir($dirs, '755', true);

        // keep replacing those content
        $this->persist($content);

        return $this;
    }
647163
public function getFilterCallback(Closure $closure)
  {
    $filter = function(&$item) use ($closure){
      $closure($item);
      return true;
    };
    return $filter;
  }
414653
public function tweakApplication(Closure $closure): void
    {
        $closure($this->app);

        static::$server->stash([
            'class' => static::class,
            'tweakApplication' => serialize(SerializableClosure::from($closure)),
        ]);
    }