From ce4e927a0093b4298a9a789d75d40a73818bdbb7 Mon Sep 17 00:00:00 2001 From: Chris Thomas Date: Thu, 9 Aug 2018 15:27:15 +0200 Subject: [PATCH 1/6] fix the problem with the custom namespaces for the symfony kernel --- Bootstraps/Symfony.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Bootstraps/Symfony.php b/Bootstraps/Symfony.php index 669f6b9..b3a0fa5 100644 --- a/Bootstraps/Symfony.php +++ b/Bootstraps/Symfony.php @@ -54,7 +54,9 @@ 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'; //since we need to change some services, we need to manually change some services $app = new $class($this->appenv, $this->debug); From 0a08d0721c14f4100a82c4b162eaee9150012416 Mon Sep 17 00:00:00 2001 From: Christopher Thomas Date: Mon, 13 Aug 2018 14:06:52 +0200 Subject: [PATCH 2/6] fix the problem with the custom namespaces for the symfony kernel --- Bootstraps/Symfony.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Bootstraps/Symfony.php b/Bootstraps/Symfony.php index b3a0fa5..4f3457a 100644 --- a/Bootstraps/Symfony.php +++ b/Bootstraps/Symfony.php @@ -54,9 +54,9 @@ public function getApplication() (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'; + $namespace = getenv('APP_KERNEL_NAMESPACE') ?: '\App\\'; + $fqcn = $namespace . (getenv('APP_KERNEL_CLASS_NAME') ?: 'Kernel'); + $class = class_exists($fqcn) ? $fqcn : '\AppKernel'; //since we need to change some services, we need to manually change some services $app = new $class($this->appenv, $this->debug); From 8e8e18e597b1e0c0b08d7a7eb7eb9f3794d1ad35 Mon Sep 17 00:00:00 2001 From: Christopher Thomas Date: Mon, 13 Aug 2018 14:07:54 +0200 Subject: [PATCH 3/6] fix the problem with the custom namespaces for the symfony kernel --- Bootstraps/Symfony.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Bootstraps/Symfony.php b/Bootstraps/Symfony.php index 4f3457a..78c8562 100644 --- a/Bootstraps/Symfony.php +++ b/Bootstraps/Symfony.php @@ -54,9 +54,9 @@ public function getApplication() (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'; + $namespace = getenv('APP_KERNEL_NAMESPACE') ?: '\App\\'; + $fqcn = $namespace . (getenv('APP_KERNEL_CLASS_NAME') ?: 'Kernel'); + $class = class_exists($fqcn) ? $fqcn : '\AppKernel'; //since we need to change some services, we need to manually change some services $app = new $class($this->appenv, $this->debug); From 6449e1fe35465852b2fcf0a7524456828fcda45f Mon Sep 17 00:00:00 2001 From: Christopher Thomas Date: Mon, 13 Aug 2018 18:21:10 +0200 Subject: [PATCH 4/6] Updated Readme and added an exception thrown if the class is not found, so it prevents silent errors --- Bootstraps/Symfony.php | 5 +++++ README.md | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/Bootstraps/Symfony.php b/Bootstraps/Symfony.php index 78c8562..426944a 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() { @@ -58,6 +59,10 @@ public function getApplication() $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): From d0b1f574e6c81f60efcd7b95e584f18634bf5e34 Mon Sep 17 00:00:00 2001 From: Christopher Thomas Date: Mon, 13 Aug 2018 18:31:13 +0200 Subject: [PATCH 5/6] fix code formatting --- Bootstraps/Symfony.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bootstraps/Symfony.php b/Bootstraps/Symfony.php index 426944a..d2819aa 100644 --- a/Bootstraps/Symfony.php +++ b/Bootstraps/Symfony.php @@ -59,7 +59,7 @@ public function getApplication() $fqcn = $namespace . (getenv('APP_KERNEL_CLASS_NAME') ?: 'Kernel'); $class = class_exists($fqcn) ? $fqcn : '\AppKernel'; - if(!class_exists($class)){ + if (!class_exists($class)) { throw new \Exception("Symfony Kernel class was not found in the configured locations. Given: '$class'"); } From 8f3e609a9acb569e3027c46cfe5e40c56ce09787 Mon Sep 17 00:00:00 2001 From: Christopher Thomas Date: Mon, 13 Aug 2018 18:37:41 +0200 Subject: [PATCH 6/6] fix code formatting --- Bootstraps/Symfony.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bootstraps/Symfony.php b/Bootstraps/Symfony.php index d2819aa..9206170 100644 --- a/Bootstraps/Symfony.php +++ b/Bootstraps/Symfony.php @@ -60,7 +60,7 @@ public function getApplication() $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'"); + 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