PHP 5.3 can't use $this in closures
543693
private function initHelpers() {
		/**
		 * @param string $haystack
		 * @param string $needle
		 * @return bool
		 */
		$this->helpers['startsWith'] = function ($haystack, $needle) {
			$needleLen = strlen($needle);
			return substr($haystack, 0, $needleLen) == $needle;
		};
		
		/**
		 * @param string $haystack
		 * @param string $needle
		 * @return bool
		 */
		$this->helpers['endsWith'] = function ($haystack, $needle) {
			$haystackLen = strlen($haystack);
			$needleLen = strlen($needle);
			return substr($haystack, $haystackLen - $needleLen, $needleLen) == $needle;
		};
	}
301918
public function cliRegister() : Closure
  {
    return function($exception, $inspector, $run) {
      Output::error($exception);
      die($exception . PHP_EOL);
      exit;
    };
  }
937953
public function set($key, $value = null)
    {
        if (func_num_args() === 1) {
            $key === '{}' && $key = json_decode('{}');
            $this->results = $key;
            return;
        }

        if ($value instanceof Closure) {
            $factory = $this->getFactory();
            $value($factory);
            $this->results[$key] = $factory->getResults();
            return $this;
        }

        $value === '{}' && $value = json_decode('{}');
        $this->results[$key] = $value;

        return $this;
    }
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;
    }
1249136
public function header(Closure $closure = null)
    {
        if (!$closure) {
            return $this->header;
        }

        $this->header = $closure;

        return $this;
    }
96659
private static function getDeclareErrorAdvice(): Closure
    {
        static $adviceMethod;
        if (!$adviceMethod) {
            $adviceMethod = function ($object, $reflectorName, $message, $level = E_USER_NOTICE) {
                $class   = is_string($object) ? $object : get_class($object);
                $message = vsprintf('[AOP Declare Error]: %s has an error: "%s"', [
                    $class . '->' . $reflectorName,
                    $message
                ]);
                trigger_error($message, $level);
            };
        }

        return $adviceMethod;
    }
792273
private static function _execute($array, callable $callback, callable $handler, $data = null, $bind = false)
    {
        $resultValue = array();
        foreach ($array as $key => $item) {
            if (is_object($item)) {
                $item = clone $item;
                if ($callback instanceof \Closure and $bind) {
                    $callback = \Closure::bind($callback, $item);
                }
            }
            $result = call_user_func_array($callback, array($key, &$item, $data));
            if (call_user_func_array($handler, array(&$resultValue, $key, $item, $result)) === false) {
                break;
            }
        }
        return $resultValue;
    }
563474
public function event(Closure $event)
    {
        if (null !== $response = $event()) {
            $this->resolveEventResponse($response);
        }

        return $this;
    }
852403
public function orWhere(\Closure $closure = null) {
        $this->query->push(['OR']);
        if($closure !== null) $closure($this);

        return $this;
    }
652550
protected function carry(): Closure
    {
        return function ($stack, $pipe) {
            return function ($passable) use ($stack, $pipe) {
                if ($this->always !== null) {
                    $passable = ($this->always)($passable, $pipe);
                }
                $slice = parent::carry();

                $callable = $slice($stack, $pipe);

                return $callable($passable);
            };
        };
    }
797909
protected function call_closure( $closure, array $parameters = [] ) {
		if ( $closure instanceof Closure ) {
			$rc      = new ReflectionFunction( $closure );
			$args    = $rc->getParameters();
		} else if ( $closure instanceof ReflectionClass ) {
			$rc = $closure;

			if ( $constructor = $rc->getConstructor() ) {
				$args = $constructor->getParameters();
			} else {
				$args = [];
			}

			$closure = function () use ( $rc ) {
				return $rc->newInstanceArgs( func_get_args() );
			};
		}

		if ( $closure instanceof Closure === false ) {
			return $closure;
		}

		$args    = is_array( $args ) ? $args : [];
		$params  = $parameters;
		$classes = [
			$this->get_class_prefix( get_class( $this ) ),
			get_class( $this ),
			get_parent_class( $this )
		];

		foreach ( (array) $args as $index => $arg ) {
			if ( $arg->getClass() === null ) {
				continue;
			}

			if ( in_array( $arg->getClass()->name, $classes, true ) ) {
				$parameters[$index] = $this;
			} else if ( $this->bound( $arg->getClass()->name ) ) {
				$parameters[$index] = $this->make( $arg->getClass()->name );
			}
		}

		if ( ! empty( $args ) && empty( $parameters ) ) {
			$parameters[0] = $this;
		}

		if ( count( $args ) > count( $parameters ) ) {
			$parameters = array_merge( $parameters, $params );
		}

		return $this->call_closure( call_user_func_array( $closure, $parameters ), $parameters );
	}
1045590
public static function getOrSet($key, \Closure $closure, int $ttl = null, array $tags = [])
    {
        $item = self::getCacheService()->user()->getItem(self::key($key));
        if ($item->isHit()) {
            return $item->get();
        }

        $result = $closure();
        $item->set($result);
        if ($ttl) {
            $item->expiresAfter($ttl);
        }
        if ($tags && $item instanceof CacheItem) {
            $item->tag($tags);
        }
        self::getCacheService()->user()->save($item);
        return $result;
    }
750076
public function setCallback($callback)
    {
        // If the provided $value is not a closure, make it one now for easy resolution.
        if (!is_callable($callback)) {
            $callback = function () use ($callback) {
                return $callback;
            };
        }

        if ($this->protected) {
            return $this;
        }

        $this->callback = $callback;

        return $this;
    }
905023
private function withReadPreference($object, \Closure $closure)
    {
        if ( ! isset($this->query['readPreference'])) {
            return $closure();
        }

        $prevReadPref = $object->getReadPreference();
        $object->setReadPreference($this->query['readPreference'], $this->query['readPreferenceTags']);

        try {
            return $closure();
        } finally {
            $prevTags = ! empty($prevReadPref['tagsets']) ? $prevReadPref['tagsets'] : [];
            $object->setReadPreference($prevReadPref['type'], $prevTags);
        }
    }
308430
public function uiRegister() : Closure
  {
    return function($exception, $inspector, $run) {
      $appHandler = new \App\Exceptions\Handler();

      if ($exception instanceof Exception) {
        return $appHandler->render(
          $this->getRequest() ?? new Request(array_merge($_POST, $_FILES)),
          $exception
        );
      }

      Events::trigger('internal.error', [$exception]);
    };
  }
284555
public function orHaving($column, Closure $value = null): self
    {
        $this->have->orHaving($column, $value);
        return $this;
    }
147626
public function at(\Closure $closure): self
    {
        $arrayy = clone $this;

        foreach ($arrayy->getGenerator() as $key => $value) {
            $closure($value, $key);
        }

        return static::create(
            $arrayy->toArray(),
            $this->iteratorClass,
            false
        );
    }