Issues (1270)

bootstrap.php (1 issue)

1
<?php
2
3
declare(strict_types=1);
4
5
use RssApp\Bootstrap;
6
use RssApp\Controller;
7
use RssApp\RequestBootstrap;
8
use Spiral\Debug;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Debug. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
9
10
define("BASEPATH", dirname(__FILE__));
11
define("DS", DIRECTORY_SEPARATOR);
12
13
require_once BASEPATH.DS.'external'.DS.'autoload.php';
14
15
define("APPLICATION_ENV", getenv("APPLICATION_ENV") ?? 'dev');
16
17
$dumper = new Debug\Dumper();
18
$dumper->setRenderer(Debug\Dumper::ERROR_LOG, new Debug\Renderer\ConsoleRenderer());
19
function dump($msg) {
20
    global $dumper;
21
    $dumper->dump($msg, Debug\Dumper::ERROR_LOG);
22
}
23
24
try {
25
    Bootstrap::initialize();
26
} catch (Exception $e) {
27
    dump("Problem with application bootstrap: ".$e->getMessage());
28
}
29
30
$relay = new Spiral\Goridge\StreamRelay(STDIN, STDOUT);
31
$psr7  = new Spiral\RoadRunner\PSR7Client(new Spiral\RoadRunner\Worker($relay));
32
while ($req = $psr7->acceptRequest()) {
33
    try {
34
        RequestBootstrap::initialize();
35
        $resp = Controller::handle();
36
        $psr7->respond($resp);
37
    } catch (Throwable $e) {
38
        $psr7->getWorker()->error((string) $e);
39
    }
40
}
41