Create closure of the search
@return \Closure
@throws Exception\InvalidArgument on invalid parameters
431280
public function getSearchClosure()
	{
		$conditions = $this->conditions;
		
		$filter = function (NodeInterface $node) use (&$conditions) {
			
			foreach ($conditions as $condition) {
				$field = $condition[SearchConditionInterface::FIELD_POS];
				$testValue = null;
				
				switch ($field) {
					case SearchConditionInterface::LEFT_FIELD:
						$testValue = $node->getLeftValue();
						break;
					case SearchConditionInterface::RIGHT_FIELD:
						$testValue = $node->getRightValue();
						break;
					case SearchConditionInterface::LEVEL_FIELD:
						$testValue = $node->getLevel();
						break;
					default:
						throw new Exception\InvalidArgument("Field $field is not recognized");
				}
				
				$relation = $condition[SearchConditionInterface::RELATION_POS];
				$value = $condition[SearchConditionInterface::VALUE_POS];
				$result = null;
				
				switch ($relation) {
					case SearchConditionInterface::RELATION_EQUALS:
						$result = ($testValue == $value);
						break;
					case SearchConditionInterface::RELATION_LESS_OR_EQUALS:
						$result = ($testValue <= $value);
						break;
					case SearchConditionInterface::RELATION_GREATER_OR_EQUALS:
						$result = ($testValue >= $value);
						break;
					case SearchConditionInterface::RELATION_LESS:
						$result = ($testValue < $value);
						break;
					case SearchConditionInterface::RELATION_GREATER:
						$result = ($testValue > $value);
						break;
					case SearchConditionInterface::RELATION_NOT_EQUALS:
						$result = ($testValue != $value);
						break;
					default:
						throw new Exception\InvalidArgument("Relation $relation is not recognized");
				}
				
				if ( ! $result) {
					return false;
				}
			}
			return true;
		};

		return $filter;
	}
651206
public function makeEmptyCopy(): self
    {
        $query = $this->constructEmptyCopy();
        $query->setClosureResolver($this->closureResolver);
        return $query;
    }
883073
public function getFilter(): Closure
    {
        $rootDirectory = $this->rootDirectory;
        $includePaths = $this->includePaths;
        $excludePaths = $this->excludePaths;

        return function (SplFileInfo $file) use ($rootDirectory, $includePaths, $excludePaths) {

            if ($file->getExtension() !== 'php') {
                return false;
            }

            $fullPath = $this->getFileFullPath($file);
            // Do not touch files that not under rootDirectory
            if (strpos($fullPath, $rootDirectory) !== 0) {
                return false;
            }

            if (!empty($includePaths)) {
                $found = false;
                foreach ($includePaths as $includePattern) {
                    if (fnmatch("{$includePattern}*", $fullPath, FNM_NOESCAPE)) {
                        $found = true;
                        break;
                    }
                }
                if (!$found) {
                    return false;
                }
            }

            foreach ($excludePaths as $excludePattern) {
                if (fnmatch("{$excludePattern}*", $fullPath, FNM_NOESCAPE)) {
                    return false;
                }
            }

            return true;
        };
    }
262303
public function getIterator()
    {
        if (is_null($i = $this->model ?: $this->dq ?: $this->iter)) {
            throw $this->exception('Please specify data source with setSource or setModel');
        }
        if ($i instanceof Closure) {
            $i = call_user_func($i);
        }

        return $i;
    }
1344399
public function cache()
    {
        $paramCount = func_num_args();

        if (1 === $paramCount) {
            return $this["cache"]->get(func_get_arg(0));
        }

        if (2 === $paramCount) {
            return $this["cache"]->set(func_get_arg(0), func_get_arg(1));
        }

        if (3 === $paramCount) {
            return $this["cache"]->set(func_get_arg(0), func_get_arg(1), func_get_arg(2));
        }

        throw new InvalidArgumentException("App::cache() method expects 1 or 2(3) parameters. {$paramCount} given.");
    }
101058
private function phpErrorHandler(): Closure
    {
        return static function (int $errno, string $errstr, string $errfile, int $errline): bool {
            // Ignore errors that are silenced with '@'
            if (error_reporting() & $errno) {
                throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
            }

            return true;
        };
    }
347735
function getTo(): \Closure {
    return function($value, \Mustache_LambdaHelper $helper) {
      $args = $this->parseArguments($helper->render($value), 'url', ['scheme' => false]);
      return UrlHelper::to($args['url'], $args['scheme']);
    };
  }
150771
public function newNestedInstance(Closure $closure = null)
    {
        $query = $this->newInstance()->nested();

        if ($closure) {
            call_user_func($closure, $query);
        }

        return $query;
    }
366074
protected function getSearchFilter()
    {
        if ($this->searchFilterCache) {
            return $this->searchFilterCache;
        }

        // Check for given FilterClass
        $params = $this->getRequest()->getVar('q');
        if (empty($params['FilterClass'])) {
            return null;
        }

        // Validate classname
        $filterClass = $params['FilterClass'];
        $filterInfo = new ReflectionClass($filterClass);
        if (!$filterInfo->implementsInterface(LeftAndMain_SearchFilter::class)) {
            throw new InvalidArgumentException(sprintf('Invalid filter class passed: %s', $filterClass));
        }

        return $this->searchFilterCache = Injector::inst()->createWithArgs($filterClass, array($params));
    }
165719
public function extend(string $key, Closure $callable)
    {
        if (!isset($this->stack[$key])) {
            throw new InvalidArgumentException(sprintf('Identifier "%s" is not defined.', $key));
        }

        if (!$callable instanceof Closure) {
            throw new InvalidArgumentException(
                sprintf('Identifier "%s" is not Closure Object.', $callable)
            );
        }

        $binding = $this->offsetExists($key) ? $this->stack[$key] : null;

        $extended = function () use ($callable, $binding) {
            if (!is_object($binding)) {
                throw new ContainerException(sprintf('"%s" must be Closure object.', $binding));
            }

            return $callable($binding($this), $this);
        };

        return $this[$key] = $extended;
    }
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 );
	}
1313099
public function addClosure(string $key, Closure $closure): ClosureResolver
    {
        $this->closures[$key] = $closure;

        return $this;
    }
1151273
public static function create(Closure $callback = null)
    {
        if (self::$instance === null) {
            self::$instance = new self();
        }

        if ($callback instanceof Closure) {
            return $callback(self::$instance);
        }

        return self::$instance;
    }
205779
private function phpExceptionHandler(): Closure
    {
        return static function (Throwable $ex): void {
            $base_path = dirname(__DIR__);
            $trace     = $ex->getMessage() . PHP_EOL . $ex->getTraceAsString();
            $trace     = str_replace($base_path, '…', $trace);

            while (ob_get_level() > 0) {
                ob_end_clean();
            }

            echo '<html lang="en"><head><title>Error</title><meta charset="UTF-8"></head><body><pre>' . $trace . '</pre></body></html>';
        };
    }
904176
public static function make(\Closure $callback = null)
    {
        if (is_null(static::$instance)) {
            static::$instance = new static();
        }

        if ($callback instanceof \Closure) {
            return $callback(static::$instance);
        }

        return static::$instance;
    }
1051145
public function reject(\Closure $closure): self
    {
        // init
        $filtered = [];

        foreach ($this->getGenerator() as $key => $value) {
            if (!$closure($value, $key)) {
                $filtered[$key] = $value;
            }
        }

        return static::create(
            $filtered,
            $this->iteratorClass,
            false
        );
    }
896661
protected function _getFindOrCreateQuery($search)
    {
        if (is_callable($search)) {
            $query = $this->find();
            $search($query);
        } elseif (is_array($search)) {
            $query = $this->find()->where($search);
        } elseif ($search instanceof Query) {
            $query = $search;
        } else {
            throw new InvalidArgumentException('Search criteria must be an array, callable or Query');
        }

        return $query;
    }