Skip to content

Commit

Permalink
Add autoloader.php
Browse files Browse the repository at this point in the history
  • Loading branch information
terrylinooo committed Jul 4, 2020
1 parent f2eb442 commit 28f4d5c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
47 changes: 47 additions & 0 deletions autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php
/*
* This file is part of the Shieldon package.
*
* (c) Terry L. <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

/**
* Register to PSR-4 autoloader.
*
* @return void
*/
function psr_http_register()
{
spl_autoload_register('psr_http_autoload', true, false);
}

/**
* PSR-4 autoloader.
*
* @param string $className
*
* @return void
*/
function psr_http_autoload($className)
{
$prefix = 'Shieldon\\';
$dir = __DIR__ . '/src';

if (0 === strpos($className, $prefix . 'Psr')) {
$parts = explode('\\', substr($className, strlen($prefix)));
$filepath = $dir . '/' . implode('/', $parts) . '.php';

echo $filepath . '<br >';

if (is_file($filepath)) {
require $filepath;
}
}
}

psr_http_register();
6 changes: 5 additions & 1 deletion src/Psr17/Utils/SuperGlobal.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ public static function mockCliEnvironment(array $server = []): void
'SERVER_PROTOCOL' => 'HTTP/1.1',
];

$_SERVER = array_merge($defaultServerParams, $server);
if (defined('NO_MOCK_ENV')) {
$defaultServerParams = [];
}

$_SERVER = array_merge($defaultServerParams, $_SERVER, $server);
}

// @codeCoverageIgnoreEnd
Expand Down

0 comments on commit 28f4d5c

Please sign in to comment.