Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into fix/dead-code
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Dec 11, 2023
2 parents 102666d + 937e0ee commit 0f475f5
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bin/box
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ if (false === in_array(PHP_SAPI, ['cli', 'phpdbg', 'embed', 'micro'], true)) {
throw new RuntimeException('Unable to find the Composer autoloader.');
})();

register_aliases();
register_error_handler();
Bootstrap::registerAliases();
Bootstrap::registerErrorHandler();

$io = IO::createDefault();
OutputFormatterConfigurator::configure($io);
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
<directory>src/</directory>
</include>
<exclude>
<file>src/bootstrap.php</file>
<file>src/consts.php</file>
<file>src/Bootstrap.php</file>
<file>src/functions.php</file>
<file>src/Console/Command/Build.php</file>
<file>src/Console/Command/ChangeableWorkingDirectory.php</file>
Expand Down
50 changes: 50 additions & 0 deletions src/Bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

/*
* This file is part of the box project.
*
* (c) Kevin Herrera <[email protected]>
* Théo Fidry <[email protected]>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/

namespace KevinGH\Box;

use ErrorException;
use Isolated\Symfony\Component\Finder\Finder as IsolatedFinder;
use Symfony\Component\Finder\Finder as SymfonyFinder;
use function class_alias;
use function class_exists;
use function error_reporting;
use function set_error_handler;

final class Bootstrap
{
use NotInstantiable;

/**
* @private
*/
public static function registerAliases(): void
{
// Exposes the finder used by PHP-Scoper PHAR to allow its usage in the configuration file.
if (false === class_exists(IsolatedFinder::class)) {
class_alias(SymfonyFinder::class, IsolatedFinder::class);
}
}

public static function registerErrorHandler(): void
{
set_error_handler(
static function (int $code, string $message, string $file = '', int $line = -1): void {
if (error_reporting() & $code) {
throw new ErrorException($message, 0, $code, $file, $line);
}
},
);
}
}

0 comments on commit 0f475f5

Please sign in to comment.