Skip to content

Commit eb0dce8

Browse files
committed
Runtime: adapt log level to execution context
1 parent 541c737 commit eb0dce8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

bin/compile.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
* the LICENSE file that was distributed with this source code.
1414
*/
1515

16-
error_reporting(E_ERROR & E_USER_ERROR);
16+
// Log all errors when requiring autoloader
17+
error_reporting(E_ALL);
1718

1819
$VERSION = '1.2.3';
1920

@@ -32,6 +33,12 @@
3233

3334
use Yannoff\Component\Console\Application;
3435
use Yannoff\PhpCodeCompiler\Command\Compile;
36+
use Yannoff\PhpCodeCompiler\Phar;
37+
38+
// If the script is executed from the compiled phar, lower error log level
39+
if (Phar::runsInPhar()) {
40+
error_reporting(E_ERROR & E_USER_ERROR);
41+
}
3542

3643
$app = new Application('PHP Code Compiler', $VERSION, (new Compile()));
3744
$app->run();

src/Phar.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,16 @@ public function has(string $file): bool
4949
{
5050
return $this->offsetExists($file);
5151
}
52+
53+
/**
54+
* Check whether the script is run from inside a Phar
55+
*
56+
* @return bool
57+
*/
58+
static public function runsInPhar()
59+
{
60+
@list($protocol, $uri) = explode('://', __DIR__);
61+
62+
return $protocol == 'phar';
63+
}
5264
}

0 commit comments

Comments
 (0)