Skip to content

Commit

Permalink
Read KERNEL_DIR and KERNEL_CLASS from phpunit.xml.dist for bin/console (
Browse files Browse the repository at this point in the history
#182)

* Read KERNEL_DIR and KERNEL_CLASS from phpunit.xml.dist for bin/console

* Fix condition
  • Loading branch information
covex-nn authored and ElectricMaxxx committed Jun 28, 2018
1 parent 5ed313d commit 13dbdbc
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions bootstrap/kernel_bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,18 @@
}

$xml = new \SimpleXMLElement(file_get_contents($phpUnitFile));
$kernelDir = $xml->php[0]->server[0]['value'];

$kernelFile = $rootDir.'/'.$kernelDir.'/AppKernel.php';
$envDir = $xml->xpath("//php/server[@name='KERNEL_DIR']");
if (!count($envDir)) {
throw new \Exception(
'Kernel path must be set via <server name"KERNEL_DIR" value="..."/>'
);
}
$envClass = $xml->xpath("//php/env[@name='KERNEL_CLASS']");

$kernelClass = count($envClass) ? (string) $envClass[0]['value'] : 'AppKernel';
$kernelNs = explode('\\', $kernelClass);
$kernelFile = $rootDir.'/'.$envDir[0]['value'].'/'.array_pop($kernelNs).'.php';

if (!file_exists($kernelFile)) {
throw new \Exception(sprintf(
Expand All @@ -38,4 +47,4 @@

require_once $kernelFile;

return new AppKernel($env, true);
return new $kernelClass($env, true);

0 comments on commit 13dbdbc

Please sign in to comment.