Performs the closure function.  If it returns false, throws a SocketException using the provided resource.

@param resource $resource Socket Resource
@param callable $closure  A function that takes 1 parameter (a socket resource)

@throws SocketException
487661
protected static function exceptionOnFalse($resource, callable $closure)
    {
        $result = $closure($resource);

        if ($result === false) {
            throw new SocketException($resource);
        }

        return $result;
    }
943326
function some(callable $closure) {
        foreach($this->data as $key => $val) {
            if($closure($val, $key)) {
                return true;
            }
        }
        
        return false;
    }
42819
protected function bindClosureToInstance($closure, $instance)
    {
        if ($closure instanceof \Closure) {
            $closure = $closure->bind($closure, $instance, get_class($instance));
        }

        return $closure;
    }
1250096
protected function prepareDestination(Closure $callback)
    {
        return function ($passable) use ($callback)
        {
            try {
                return call_user_func($callback, $passable);
            }
            catch (Exception $e) {
                return $this->handleException($passable, $e);
            }
            catch (Throwable $e) {
                return $this->handleException($passable, new FatalThrowableError($e));
            }
        };
    }
459955
public function runCallback(\Closure $callback)
    {
        // Check if a legacy stack callback is already running.
        if ($this->runningCallback) {
            throw new RuntimeException('Started recursive callback in legacy kernel.');
        }

        // Set the callback as running.
        $this->runningCallback = true;

        // Change current directory to the legacy stack.
        $platformHome = getcwd();
        // @todo Must get innomatic_legacy path from configuration.
        chdir($platformHome . '/innomatic_legacy');

        try {
            // Start the legacy Root Container and the legacy autoloader.
            require_once getcwd().'/innomatic/core/classes/innomatic/core/RootContainer.php';
            $rootContainer = \Innomatic\Core\RootContainer::instance('\Innomatic\Core\RootContainer');

            // Add the Symfony service container
            $rootContainer->setServiceContainer($this->container);

            // Start the legacy Innomatic Container.
            $innomatic = \Innomatic\Core\InnomaticContainer::instance('\Innomatic\Core\InnomaticContainer');

            // Set the Innomatic interface type to console.
            $innomatic->setInterface(\Innomatic\Core\InnomaticContainer::INTERFACE_CONSOLE);
            $home = \Innomatic\Core\RootContainer::instance('\Innomatic\Core\RootContainer')
                ->getHome()
                . 'innomatic/';

            // Start Innomatic.
            $innomatic->bootstrap($home, $home . 'core/conf/innomatic.ini');
            
            // Run the callback in the legacy core.
            $result = $innomatic->runCallback($callback);
        } catch (Exception $e) {
            // Go back to the new platform home.
            chdir($platformHome);
        
            // Clean the callback running state.
            $this->runningCallback = false;
            throw $e;
        }

        // Go back to the new platform home.
        chdir($platformHome);

        // Clean the callback running state.
        $this->runningCallback = false;

        return $result;
    }
350394
public function extract(Collection $resources, Closure $callback)
    {
        foreach ($resources as $resource) {
            $callback($resource, [$this->inflector->singularize($this->getVariableName()) => $resource]);
        }
    }
1254557
public function setConnectionResource($resource): void
    {
        if ($this->itemConverter instanceof ConnectionAware) {
            $this->itemConverter->setConnectionResource($resource);
        }
    }
619075
public function nonblockingExecuteOnce(\Closure $task)
    {
        if (! $this->nonblockingLock()) {
            return;

        }
        $error = null;
        try {
            call_user_func($task);

        } catch (\Exception $e) {
            $error = $e;

        }
        $this->unlock();
        if (! is_null($error)) {
            throw $error;

        }
    }
903383
public function listen(Closure $callback)
    {
        if (! isset($this->dispatcher)) {
            throw new RuntimeException('Events dispatcher has not been set.');
        }

        $this->dispatcher->listen(MessageLogged::class, $callback);
    }
749457
public function once(Closure $closure)
    {
        $hash = spl_object_hash((object) $closure);

        if ( ! isset ($this->called[$hash]))
        {
            $closure();

            $this->called[$hash] = true;
        }
    }
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>';
        };
    }
942082
public function resolveCallable(?string $name, callable $closure, ?array $parameters = null)
    {
        $definitions = isset($name) && $this->container->isDefined($name)
            ? $this->container->getDefiniition($name) : null;

        $callable = $this->getCallable($closure);
        $parameters = $parameters ?? $this->resolveParameters($callable->getParameters() ?? null, $definitions);

        return $callable->invokeArgs($parameters);
    }
669798
public function runCallback( \Closure $callback, $postReinitialize = true )
    {
        $this->requestInit();

        try
        {
            $return = $callback();
        }
        catch ( Exception $e )
        {
            $this->shutdown( $postReinitialize );
            throw $e;
        }

        $this->shutdown( $postReinitialize );

        return $return;
    }
533630
public function protect(\Closure $closure)
    {
        try {
            $result = null;
            $circuitOpenException = null;

            if ($this->isClosed($this->circuit) || $this->isHalfOpen($this->circuit)) {
                $result = $closure();
                $this->success($this->circuit);
            } elseif ($this->isOpen($this->circuit)) {
                $circuitOpenException = new CircuitOpenException();
            }
        } catch (\Exception $e) {
            if (!in_array(get_class($e), $this->config['allowed_exceptions'])) {
                $this->failure($this->circuit);
            }

            if (!$this->config['ignore_exceptions']) {
                if (!in_array(get_class($e), $this->config['exclude_exceptions'])) {
                    $result = $e;
                }
            }
        }

        // Throw circuit exception when it is opened
        if (null !== $circuitOpenException) {
            throw $circuitOpenException;
        }

        //Throw closure exception
        if ($result instanceof \Exception) {
            throw $result;
        }

        return $result;
    }
586345
protected function _spin($closure)
    {
        $timeout = $this->timeout();
        if ($timeout <= 0) {
            $closure();
        } else {
            Code::spin($closure, $timeout);
        }
    }
889726
public function extendBlock($blockName, Closure $closure)
    {
        $blockName  = ucfirst(strtolower($blockName));
        $methodName = camel_case("block_{$blockName}");

        return $this->bindElementClosure($methodName, $closure);
    }
258078
public function execute(\Closure $callback = null)
    {
        $stacks = $this->buildStacks();

        foreach ($stacks as $requests) {
            foreach ($requests as $request) {
                $status = curl_multi_add_handle($this->handle, $request->getHandle());
                if ($status !== CURLM_OK) {
                    throw new \Exception(sprintf(
                        'Unable to add request to cURL multi handle (code #%u)',
                        $status
                    ));
                }
            }

            $this->dispatch();

            foreach ($requests as $request) {
                $request->setRawResponse(curl_multi_getcontent($request->getHandle()));
                curl_multi_remove_handle($this->handle, $request->getHandle());

                if ($callback !== null) {
                    $callback($request->getResponse());
                }
            }
        }
    }