diff --git a/Bootstraps/Symfony.php b/Bootstraps/Symfony.php index 669f6b9..9206170 100644 --- a/Bootstraps/Symfony.php +++ b/Bootstraps/Symfony.php @@ -38,6 +38,7 @@ public function initialize($appenv, $debug) * Create a Symfony application * * @return \AppKernel + * @throws \Exception */ public function getApplication() { @@ -54,7 +55,13 @@ public function getApplication() (new \Symfony\Component\Dotenv\Dotenv())->load(realpath('.env')); } - $class = class_exists('\AppKernel') ? '\AppKernel' : '\App\Kernel'; + $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); diff --git a/README.md b/README.md index 390424b..1b98385 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ HttpKernel adapter for use of Symfony and Laravel frameworks with PHP-PM. See ht composer require php-pm/httpkernel-adapter + 3. Optionally provide the namespace of your Kernel using the `APP_KERNEL_NAMESPACE` environment variable. + Example: `APP_KERNEL_NAMESPACE=Acme\MyProduct\`. This will attempt to use the class `Acme\MyProduct\Kernel` + as the fully qualified class name + > **Note**: For Symfony, make sure your `AppKernel` is autoloaded in your > `composer.json` (shouldn't be an issue for projects created using the Standard > Edition after November 2015):