public function getApplication()
    {
        // include applications autoload
        $appAutoLoader = './app/autoload.php';
        if (file_exists($appAutoLoader)) {
            require $appAutoLoader;
        } else {
            require $this->getVendorDir().'/autoload.php';
        }

        // environment loading as of Symfony 3.3
        if (!getenv('APP_ENV') && class_exists('Symfony\Component\Dotenv\Dotenv') && file_exists(realpath('.env'))) {
            (new \Symfony\Component\Dotenv\Dotenv())->load(realpath('.env'));
        }

        $namespace = getenv('APP_KERNEL_NAMESPACE') ?: '\App\\';
        $fqcn      = $namespace . (getenv('APP_KERNEL_CLASS_NAME') ?: 'Kernel');
        $class     = class_exists($fqcn) ? $fqcn : '\AppKernel';

        if (!class_exists($class)) {
            throw new \Exception("Symfony Kernel class was not found in the configured locations. Given: '$class'");
        }

        //since we need to change some services, we need to manually change some services
        $app = new $class($this->appenv, $this->debug);

        // We need to change some services, before the boot, because they would
        // otherwise be instantiated and passed to other classes which makes it
        // impossible to replace them.

        Utils::bindAndCall(function () use ($app) {
            // init bundles
            $app->initializeBundles();

            // init container
            $app->initializeContainer();
        }, $app);

        Utils::bindAndCall(function () use ($app) {
            foreach ($app->getBundles() as $bundle) {
                $bundle->setContainer($app->container);
                $bundle->boot();
            }

            $app->booted = true;
        }, $app);

        if ($this->debug) {
            Utils::bindAndCall(function () use ($app) {
                $container = $app->container;

                $containerClassName = substr(strrchr(get_class($app->container), "\\"), 1);
                $metaName = $containerClassName . '.php.meta';

                Utils::bindAndCall(function () use ($container) {
                    $container->publicContainerDir = $container->containerDir;
                }, $container);

                if ($container->publicContainerDir === null) {
                    return;
                }

                $metaContent = @file_get_contents($app->container->publicContainerDir . '/../' . $metaName);

                // Cannot read the Metadata, returning
                if ($metaContent === false) {
                    return;
                }

                $containerMetadata = unserialize($metaContent);

                foreach ($containerMetadata as $entry) {
                    if ($entry instanceof FileResource) {
                        register_file($entry->__toString());
                    }
                }
            }, $app);
        }

        if ($trustedProxies = getenv('TRUSTED_PROXIES')) {
            Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
        }

        if ($trustedHosts = getenv('TRUSTED_HOSTS')) {
            Request::setTrustedHosts(explode(',', $trustedHosts));
        }

        return $app;
    }
public function getApplication()
    {
        // include applications autoload
        $appAutoLoader = './app/autoload.php';
        if (file_exists($appAutoLoader)) {
            require $appAutoLoader;
        } else {
            require $this->getVendorDir().'/autoload.php';
        }

        // environment loading as of Symfony 3.3
        if (!getenv('APP_ENV') && class_exists('Symfony\Component\Dotenv\Dotenv') && file_exists(realpath('.env'))) {
            (new \Symfony\Component\Dotenv\Dotenv())->load(realpath('.env'));
        }

        $namespace = getenv('APP_KERNEL_NAMESPACE') ?: '\App\\';
        $fqcn      = $namespace . (getenv('APP_KERNEL_CLASS_NAME') ?: 'Kernel');
        $class     = class_exists($fqcn) ? $fqcn : '\AppKernel';

        if (!class_exists($class)) {
            throw new \Exception("Symfony Kernel class was not found in the configured locations. Given: '$class'");
        }

        //since we need to change some services, we need to manually change some services
        $app = new $class($this->appenv, $this->debug);

        // We need to change some services, before the boot, because they would
        // otherwise be instantiated and passed to other classes which makes it
        // impossible to replace them.

        Utils::bindAndCall(function () use ($app) {
            // init bundles
            $app->initializeBundles();

            // init container
            $app->initializeContainer();
        }, $app);

        Utils::bindAndCall(function () use ($app) {
            foreach ($app->getBundles() as $bundle) {
                $bundle->setContainer($app->container);
                $bundle->boot();
            }

            $app->booted = true;
        }, $app);

        if ($this->debug) {
            Utils::bindAndCall(function () use ($app) {
                $container = $app->container;

                $containerClassName = substr(strrchr(get_class($app->container), "\\"), 1);
                $metaName = $containerClassName . '.php.meta';

                Utils::bindAndCall(function () use ($container) {
                    $container->publicContainerDir = $container->containerDir;
                }, $container);

                if ($container->publicContainerDir === null) {
                    return;
                }

                $metaContent = @file_get_contents($app->container->publicContainerDir . '/../' . $metaName);

                // Cannot read the Metadata, returning
                if ($metaContent === false) {
                    return;
                }

                $containerMetadata = unserialize($metaContent);

                foreach ($containerMetadata as $entry) {
                    if ($entry instanceof FileResource) {
                        register_file($entry->__toString());
                    }
                }
            }, $app);
        }

        if ($trustedProxies = getenv('TRUSTED_PROXIES')) {
            Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
        }

        if ($trustedHosts = getenv('TRUSTED_HOSTS')) {
            Request::setTrustedHosts(explode(',', $trustedHosts));
        }

        return $app;
    }
public function getApplication ( ) { // include applications autoload $ appAutoLoader = './app/autoload.php' ; if ( file_exists ( $ appAutoLoader ) ) { require $ appAutoLoader ; } else { require $ this -> getVendorDir ( ) . '/autoload.php' ; } // environment loading as of Symfony 3.3 if ( ! getenv ( 'APP_ENV' ) && class_exists ( 'Symfony\Component\Dotenv\Dotenv' ) && file_exists ( realpath ( '.env' ) ) ) { ( new \ Symfony \ Component \ Dotenv \ Dotenv ( ) ) -> load ( realpath ( '.env' ) ) ; } $ namespace = getenv ( 'APP_KERNEL_NAMESPACE' ) ? : '\App\\' ; $ fqcn = $ namespace . ( getenv ( 'APP_KERNEL_CLASS_NAME' ) ? : 'Kernel' ) ; $ class = class_exists ( $ fqcn ) ? $ fqcn : '\AppKernel' ; if ( ! class_exists ( $ class ) ) { throw new \ Exception ( "Symfony Kernel class was not found in the configured locations. Given: '$class'" ) ; } //since we need to change some services, we need to manually change some services $ app = new $ class ( $ this -> appenv , $ this -> debug ) ; // We need to change some services, before the boot, because they would // otherwise be instantiated and passed to other classes which makes it // impossible to replace them. Utils :: bindAndCall ( function ( ) use ( $ app ) { // init bundles $ app -> initializeBundles ( ) ; // init container $ app -> initializeContainer ( ) ; } , $ app ) ; Utils :: bindAndCall ( function ( ) use ( $ app ) { foreach ( $ app -> getBundles ( ) as $ bundle ) { $ bundle -> setContainer ( $ app -> container ) ; $ bundle -> boot ( ) ; } $ app -> booted = true ; } , $ app ) ; if ( $ this -> debug ) { Utils :: bindAndCall ( function ( ) use ( $ app ) { $ container = $ app -> container ; $ containerClassName = substr ( strrchr ( get_class ( $ app -> container ) , "\\" ) , 1 ) ; $ metaName = $ containerClassName . '.php.meta' ; Utils :: bindAndCall ( function ( ) use ( $ container ) { $ container -> publicContainerDir = $ container -> containerDir ; } , $ container ) ; if ( $ container -> publicContainerDir === null ) { return ; } $ metaContent = @ file_get_contents ( $ app -> container -> publicContainerDir . '/../' . $ metaName ) ; // Cannot read the Metadata, returning if ( $ metaContent === false ) { return ; } $ containerMetadata = unserialize ( $ metaContent ) ; foreach ( $ containerMetadata as $ entry ) { if ( $ entry instanceof FileResource ) { register_file ( $ entry -> __toString ( ) ) ; } } } , $ app ) ; } if ( $ trustedProxies = getenv ( 'TRUSTED_PROXIES' ) ) { Request :: setTrustedProxies ( explode ( ',' , $ trustedProxies ) , Request :: HEADER_X_FORWARDED_ALL ^ Request :: HEADER_X_FORWARDED_HOST ) ; } if ( $ trustedHosts = getenv ( 'TRUSTED_HOSTS' ) ) { Request :: setTrustedHosts ( explode ( ',' , $ trustedHosts ) ) ; } return $ app ; }
Create a Symfony application

@return \AppKernel
@throws \Exception
Create a Symfony application