Builds up the legacy kernel and encapsulates it inside a closure, allowing lazy loading.

@param \ezpKernelHandler|\Closure A kernel handler instance or a closure returning a kernel handler instance

@return \Closure
350933
public function buildLegacyKernel($legacyKernelHandler)
    {
        $legacyRootDir = $this->legacyRootDir;
        $webrootDir = $this->webrootDir;
        $eventDispatcher = $this->eventDispatcher;
        $logger = $this->logger;
        $that = $this;

        return static function () use ($legacyKernelHandler, $legacyRootDir, $webrootDir, $eventDispatcher, $logger, $that) {
            if (LegacyKernel::hasInstance()) {
                return LegacyKernel::instance();
            }

            if ($legacyKernelHandler instanceof \Closure) {
                $legacyKernelHandler = $legacyKernelHandler();
            }
            $legacyKernel = new LegacyKernel($legacyKernelHandler, $legacyRootDir, $webrootDir, $logger);

            if ($that->getBuildEventsEnabled()) {
                $eventDispatcher->dispatch(
                    LegacyEvents::POST_BUILD_LEGACY_KERNEL,
                    new PostBuildKernelEvent($legacyKernel, $legacyKernelHandler)
                );
            }

            return $legacyKernel;
        };
    }
641187
public function getKernel()
    {

        // Time?
        if (!empty($this->settings['timer'])) {
            $t = new Timer('Kernel');
        }

        // File containing info
        $file = '/proc/version';

        // Make sure we can use it
        if (!is_file($file) || !is_readable($file)) {
            Errors::add('Linfo Core', '/proc/version not found');

            return 'Unknown';
        }

        // Get it
        $contents = Common::getContents($file);

        // Parse it
        if (preg_match('/^Linux version (\S+).+$/', $contents, $match) != 1) {
            Errors::add('Linfo Core', 'Error parsing /proc/version');

            return 'Unknown';
        }

        // Return it
        return $match[1];
    }
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);
            };
        };
    }
883887
public function context()
    {
        $this->logger->debug('kernel.context: generate Context instance');

        $request = Request::globals();
        $response = new Response;
        return new Context($request, $response);
    }
275754
public function controllerWrapper($closure)
    {
        $dependentService = $this->container->dependentService;
        return function (...$args) use ($closure, $dependentService) {
            return $dependentService->call($closure, $args);
        };
    }
517241
public function getServer(): Server
    {
        if ($this->serverHostname instanceof \Closure) {
            $server = call_user_func($this->serverHostname);
        } else {
            if ($this->isOnCluster()) {
                /*
                 * If no server provided, will take random server from cluster
                 */
                if (is_null($this->serverHostname)) {
                    $server = $this->serverProvider->getRandomServerFromCluster($this->getClusterName());
                    $this->serverHostname = $server->getHost();
                } else {
                    $server = $this->serverProvider->getServerFromCluster(
                        $this->getClusterName(),
                        $this->serverHostname
                    );
                }
            } else {
                /*
                 * If no server provided, will take random server from cluster
                 */
                if (is_null($this->serverHostname)) {
                    $server = $this->serverProvider->getRandomServer();
                    $this->serverHostname = $server->getHost();
                } else {
                    $server = $this->serverProvider->getServer($this->serverHostname);
                }
            }
        }
        
        return $server;
    }
310101
protected function getDefaultApplication(IKernel $kernel = NULL) {
		if($kernel === NULL) {
			return new Application($this->getDefaultKernel(), $this->injector, new Router(""));
		}

		return new Application($kernel, $this->injector, new Router(""));
	}
1258064
function initializer()
    {
        if ($this->initializer)
            return $this->initializer;

        // ..

        $initializer = new InitializerAggregate($this);

        # attach defaults:
        $initializer->addCallable(function($instance, $self) {
            if ($instance instanceof iServicesAware)
                // Inject Service Container Inside
                $instance->setServices($self);
        }, 10000);

        return $this->initializer = $initializer;
    }
1109535
public function getHandler()
    {
        if (!$this->handler) {
            return $this->getDefaultHandler();
        }

        if (is_callable($this->handler)) {
            $this->handler = call_user_func($this->handler);
        }

        return $this->handler;
    }
738682
static public function getEngine()
    {
        // Get instance if already created.
        $instanceName = "eZSearchPlugin_" . $GLOBALS["eZCurrentAccess"]["name"];
        if ( isset( $GLOBALS[$instanceName] ) )
        {
            return $GLOBALS[$instanceName];
        }

        $ini = eZINI::instance();

        $searchEngineString = 'ezsearch';
        if ( $ini->hasVariable( 'SearchSettings', 'SearchEngine' ) == true )
        {
            $searchEngineString = $ini->variable( 'SearchSettings', 'SearchEngine' );
        }

        $directoryList = array();
        if ( $ini->hasVariable( 'SearchSettings', 'ExtensionDirectories' ) )
        {
            $extensionDirectories = $ini->variable( 'SearchSettings', 'ExtensionDirectories' );
            if ( is_array( $extensionDirectories ) )
            {
                $directoryList = eZExtension::expandedPathList( $extensionDirectories, 'search/plugins' );
            }
        }

        $kernelDir = array( 'kernel/search/plugins' );
        $directoryList = array_merge( $kernelDir, $directoryList );

        foreach( $directoryList as $directory )
        {
            $searchEngineFile = implode( '/', array( $directory, strtolower( $searchEngineString ), strtolower( $searchEngineString ) ) ) . '.php';

            if ( file_exists( $searchEngineFile ) )
            {
                eZDebugSetting::writeDebug( 'kernel-search-ezsearch', 'Loading search engine from ' . $searchEngineFile, 'eZSearch::getEngine' );

                include_once( $searchEngineFile );
                $GLOBALS[$instanceName] = new $searchEngineString();
                return $GLOBALS[$instanceName];
            }
        }

        eZDebug::writeDebug( 'Unable to find the search engine:' . $searchEngineString, 'eZSearch' );
        eZDebug::writeDebug( 'Tried paths: ' . implode( ', ', $directoryList ), 'eZSearch' );
        return false;
    }
74140
public function getContainer() {
    // kernel will only boot if necessary
    $this->kernel->boot();

    // boot bundles if necessary
    if (!$this->bundlesBooted) {
      foreach ($this->kernel->getBundles() as $bundle) {
        $bundle->boot();
      }
      $this->bundlesBooted = true;
    }

    return $this->kernel->getContainer();
  }
1306432
private function _kernel()
    {
        if (CommonFunctions::executeProgram('uname', '-s', $os, PSI_DEBUG) && ($os!="")) {
            if (CommonFunctions::executeProgram('uname', '-r', $version, PSI_DEBUG) && ($version!="")) {
                $os.=' '.$version;
            }
            if (CommonFunctions::executeProgram('uname', '-v', $subversion, PSI_DEBUG) && ($subversion!="")) {
                $os.=' ('.$subversion.')';
            }
            if (CommonFunctions::executeProgram('uname', '-i', $platform, PSI_DEBUG) && ($platform!="")) {
                $os.=' '.$platform;
            }
            $this->sys->setKernel($os);
        }
    }
948022
private function _kernel()
    {
        if (CommonFunctions::executeProgram('uname', '-rvm', $ret)) {
            foreach ($this->readdmesg() as $line) {
                if (preg_match('/kernel: MINIX (\d+\.\d+\.\d+)\. \((.+)\)/', $line, $ar_buf)) {
                    $branch = $ar_buf[2];
                    break;
                }
            }
            if (isset($branch))
               $this->sys->setKernel($ret.' ('.$branch.')');
            else
               $this->sys->setKernel($ret);
        }
    }
688964
public function getPaginator()
	{
		if ($this->paginator instanceof Closure)
		{
			$this->paginator = call_user_func($this->paginator);
		}

		return $this->paginator;
	}
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;
    }
1254397
protected function getKernal()
    {
        if (!$this->kernel) {
            $this->kernel = file_get_contents($this->kernel_filename);
        }

        return $this->kernel;
    }
944786
protected function runLegacyKernelCallback($callback)
    {
        $this->persistenceCacheClearer->switchOff();
        $this->httpCacheClearer->switchOff();

        // Initialize legacy kernel if not already done
        if ($this->legacyKernel instanceof Closure) {
            $legacyKernelClosure = $this->legacyKernel;
            $this->legacyKernel = $legacyKernelClosure();
        }

        $return = $this->legacyKernel->runCallback(
            $callback,
            false,
            false
        );

        $this->persistenceCacheClearer->switchOn();
        $this->httpCacheClearer->switchOn();

        return $return;
    }