Get a Closure that represents a slice of the application onion.

@return \Closure
2595
protected function carry()
    {
        return function ($stack, $pipe) {
            return function ($passable) use ($stack, $pipe) {
                $method = $this->method;
                if (is_callable($pipe)) {
                    // If the pipe is an instance of a Closure, we will just call it directly but
                    // otherwise we'll resolve the pipes out of the container and call it with
                    // the appropriate method and arguments, returning the results back out.
                    return $pipe($passable, $stack);
                } elseif (is_object($pipe)) {
                    // If the pipe is already an object we'll just make a callable and pass it to
                    // the pipe as-is. There is no need to do any extra parsing and formatting
                    // since the object we're given was already a fully instantiated object.
                    $parameters = [$passable, $stack];
                } else {
                    list($name, $methodFromString, $parameters, $needContainer) = $this->parsePipeData($pipe);
                    if ($methodFromString) {
                        $method = $methodFromString;
                    }

                    if (!$parameters) {
                        $parameters = [];
                    }

                    // If the pipe is a string we will parse the string and resolve the class out
                    // of the dependency injection container. We can then build a callable and
                    // execute the pipe function giving in the parameters that are required.
                    if (is_string($name)) {
                        //$pipe = $this->getContainer()->get($name);
                        $pipe = $this->getPipeStageFromContainer($name);
                    } else {
                        $pipe = $name;
                    }

                    $parameters = array_merge([$passable, $stack], $parameters);
                    //
                    if ($needContainer) {
                        $this->initialize($pipe);
                        $pipeReturn = function ($data, $next) use ($pipe, $method) {
                            if ($method) {
                                $data = $pipe->{$method}($data);
                            } else {
                                $data = $pipe($data);
                            }
                            return $next($data);
                        };
                        return $pipeReturn(...$parameters);
                    }
                }

                $this->initialize($pipe);

                if ($method) {
                    if (method_exists($pipe, $method)) {
                        return $pipe->{$method}(...$parameters);
                    }
                    throw new Exception('Method ' . $method . ' does not exist in stage with class ' . get_class($pipe));
                } else if ($pipe instanceof StageInterface) {
                    return $pipe->execute(...$parameters);
                } else {
                    return $pipe(...$parameters);
                }
            };
        };
    }
1058552
protected function createSliceFunction()
    {
        return new ExpressionFunction(
            'slice',
            function ($array, $start, $length = null, $preserveKeys = false) {
                return sprintf('array_slice(%s, %s, %s, %s)', $array, $start, $length, $preserveKeys);
            },
            function ($arguments, $array, $start, $length = null, $preserveKeys = false) {
                return array_slice($array, $start, $length, $preserveKeys);
            }
        );
    }
1155536
public function handler()
    {
        $handler = $this->pop();

        if (null !== $handler) {
            $this->push($handler);
        }

        return $handler;
    }
1030685
public function getCallbackCode()
    {
        $reflection = new \ReflectionFunction($this->_callback);
        
        // Open file and seek to the first line of the closure
        $file = new \SplFileObject($reflection->getFileName());
        $file->seek($reflection->getStartLine() - 1);

        // Retrieve all of the lines that contain code for the closure
        $code = '';
        while ($file->key() < $reflection->getEndLine())
        {
            $code .= $file->current();
            $file->next();
        }

        $begin = strpos($code, 'function');
        $end = strrpos($code, '}');
        $code = substr($code, $begin, $end - $begin + 1);

        return $code;
    }
299189
public static function rowMapper(): Closure
    {
        return static function (stdClass $row): GedcomRecord {
            return GedcomRecord::getInstance($row->o_id, Tree::findById((int) $row->o_file), $row->o_gedcom);
        };
    }
611778
protected function getHandler()
    {
        $stack = HandlerStack::create();

        foreach ($this->middlewares as $middleware) {
            $stack->push($middleware);
        }

        return $stack;
    }
420243
public function getEdgesIn()
    {
        $that = $this;

        return $this->getEdges()->getEdgesMatch(function (Edge $edge) use ($that) {
            return $edge->hasVertexTarget($that);
        });
    }
796856
public function proceed()
    {
        if (isset($this->advices[$this->current])) {
            $currentInterceptor = $this->advices[$this->current++];

            return $currentInterceptor->invoke($this);
        }

        // Fill the closure only once if it's empty
        if ($this->closureToCall === null) {
            $this->closureToCall    = $this->reflectionMethod->getClosure($this->instance);
            $this->previousInstance = $this->instance;
        }

        // Rebind the closure if instance was changed since last time
        if ($this->previousInstance !== $this->instance) {
            $this->closureToCall    = $this->closureToCall->bindTo($this->instance, $this->reflectionMethod->class);
            $this->previousInstance = $this->instance;
        }

        return ($this->closureToCall)(...$this->arguments);
    }
1026575
final public function get($closure=NULL) {
      $this->connection();
      if ($this->table===NULL) {
         if ( !preg_match('/^ *FROM +\(/', $this->from) ) {
            $this->from = '';
         }
      }
      else {
         if (preg_match('/\./', $this->table) || !$this->schema ) {
            $this->from = str_replace("_table_", $this->table, $this->from);
         }
         else {
            $this->from = str_replace("_table_", $this->schema.'.'.$this->table, $this->from);
         }
      }

      $this->last_sql = $this->sql = $this->select.' '.$this->from.' '.$this->join.' '.$this->where.' '.$this->union.' '.$this->groupBy.' '.$this->having.' '.$this->orderBy.' '.$this->limit.' '.$this->offset;

      if ($closure===FALSE) return $this->sql;

      $this->fetch();

      $this->data = $this->rows;

      $this->reset();

      if ( $this->tableOrig!==NULL ) {
         $this->table = $this->tableOrig;
      }

      if ($closure instanceof \Closure) {
         $this->data = $closure( $this->data, $this );
      }

      return $this->data ?: [];
   }
1225670
public function getApplication()
    {
        $application = $this->application;

        if ($application instanceof Closure) {
            return $application();
        } elseif (is_string($application)) {
            /** @noinspection PhpIncludeInspection */
            return require $application;
        }

        return $application;
    }
119785
protected function accessTokenMiddleware()
    {
        return function (callable $handler) {
            return function (RequestInterface $request, array $options) use ($handler) {
                if ($this->accessToken) {
                    $request = $this->accessToken->applyToRequest($request, $options);
                }

                return $handler($request, $options);
            };
        };
    }
1277450
protected function carry()
    {
        return function ($stack, $pipe) {
            return function ($passable) use ($stack, $pipe) {
                if (is_callable($pipe)) {
                    // If the pipe is an instance of a Closure, we will just call it directly but
                    // otherwise we'll resolve the pipes out of the container and call it with
                    // the appropriate method and arguments, returning the results back out.
                    return $pipe($passable, $stack);
                } elseif (! is_object($pipe)) {
                    list($name, $parameters) = $this->parsePipeString($pipe);

                    // If the pipe is a string we will parse the string and resolve the class out
                    // of the dependency injection container. We can then build a callable and
                    // execute the pipe function giving in the parameters that are required.
                    $pipe = $this->getContainer()->make($name);

                    $parameters = array_merge([$passable, $stack], $parameters);
                } else {
                    // If the pipe is already an object we'll just make a callable and pass it to
                    // the pipe as-is. There is no need to do any extra parsing and formatting
                    // since the object we're given was already a fully instantiated object.
                    $parameters = [$passable, $stack];
                }

                return method_exists($pipe, $this->method)
                                ? $pipe->{$this->method}(...$parameters)
                                : $pipe(...$parameters);
            };
        };
    }
1187099
protected function getSliceWithException()
	{
		return function ( $stack, $pipe )
		{
			return function ( $passable ) use ( $stack, $pipe )
			{
				if ( $pipe instanceof Closure )
				{
					// If the pipe is an instance of a Closure, we will just call it directly but
					// otherwise we'll resolve the pipes out of the container and call it with
					// the appropriate method and arguments, returning the results back out.
					return call_user_func( $pipe, $passable, $stack );
				}
				elseif ( !is_object( $pipe ) )
				{
					list( $name, $parameters ) = $this->parsePipeString( $pipe );

					// If the pipe is a string we will parse the string and resolve the class out
					// of the dependency injection container. We can then build a callable and
					// execute the pipe function giving in the parameters that are required.
					$pipe = UniversalBuilder::resolve( $name );

					if ( is_null( $pipe ) )
						$pipe = UniversalBuilder::buildClass( $name );

					if ( is_null( $pipe ) )
						throw new PipelineException( "Busted pipeline at [" . $name . "]. There is water everywhere and all repairmen have quit because of budget cuts. But I blame the failure to resolve." );

					$parameters = array_merge( [$passable, $stack], $parameters );
				}
				else
				{
					// If the pipe is already an object we'll just make a callable and pass it to
					// the pipe as-is. There is no need to do any extra parsing and formatting
					// since the object we're given was already a fully instantiated object.
					$parameters = [$passable, $stack];
				}

				return call_user_func_array( [$pipe, $this->method], $parameters );
			};
		};
	}
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']);
    };
  }
1325481
protected function getCodeFromFile()
    {
        $file = $this->getFile();

        $code = '';

        // Next, we will just loop through the lines of the file until we get to the end
        // of the Closure. Then, we will return the complete contents of this Closure
        // so it can be serialized with these variables and stored for later usage.
        while ($file->key() < $this->reflection->getEndLine()) {
            $code .= $file->current();
            $file->next();
        }

        preg_match('/function\s*\(/', $code, $matches, PREG_OFFSET_CAPTURE);
        $begin = isset($matches[0][1]) ? $matches[0][1] : 0;

        return substr($code, $begin, strrpos($code, '}') - $begin + 1);
    }
1179483
public function getName()
    {
        if ($this->isClosure()) {
            return '{closure}';
        }
        if (isset($this->node->namespacedName)) {
            return $this->node->namespacedName;
        }
        return $this->node->name;
    }
676221
function last(callable $closure = null) {
        if($closure === null) {
            if(empty($this->data)) {
                return null;
            }
            
            $keys = \array_keys($this->data);
            return $this->data[$keys[(\count($keys) - 1)]];
        }
        
        $data = null;
        foreach($this->data as $key => $val) {
            $feed = $closure($val, $key);
            if($feed) {
                $data = $val;
            }
        }
        
        return $data;
    }