Issues (45)

src/App.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * This file is part of the Divergence package.
4
 *
5
 * (c) Henry Paradiz <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Divergence;
12
13
use Divergence\Routing\Path;
14
use Divergence\Controllers\Main;
0 ignored issues
show
The type Divergence\Controllers\Main was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Divergence\Responders\Emitter;
16
use GuzzleHttp\Psr7\ServerRequest;
17
use Divergence\Controllers\SiteRequestHandler;
18
19
class App
20
{
21
    public const VERSION = '1.1';
22
    public $ApplicationPath;
23
    public $Config;
24
    public Path $Path;
25
    public \Whoops\Run $whoops;
26
    public static App $App; // instance of this class for reference
27
28 4
    public function __construct($Path)
29
    {
30 4
        static::$App = $this;
31 4
        $this->init($Path);
32
    }
33
34 4
    public function init($Path)
35
    {
36 4
        $this->ApplicationPath = $Path;
37
38 4
        if (php_sapi_name()!=='cli' || defined('PHPUNIT_TESTSUITE')) {
39 4
            $this->Path = new Path($_SERVER['REQUEST_URI']);
40
        }
41
42 4
        $this->Config = $this->config('app');
43
44 3
        $this->registerErrorHandler();
45
    }
46
47 5
    public function config($Label)
48
    {
49 5
        $Config = $this->ApplicationPath . '/config/' . $Label . '.php';
50 5
        if (!file_exists($Config)) {
51 1
            throw new \Exception($Config . ' not found in '.static::class.'::config()');
52
        }
53 4
        return require $Config;
54
    }
55
56
    public function handleRequest()
57
    {
58
        $main = new SiteRequestHandler();
59
        $response = $main->handle(ServerRequest::fromGlobals());
60
        (new Emitter($response))->emit();
61
    }
62
63 3
    public function registerErrorHandler()
64
    {
65
        // only show errors in dev environment
66 3
        if ($this->Config['environment'] == 'dev') {
67 1
            $this->whoops = new \Whoops\Run();
68
69 1
            $Handler = new \Whoops\Handler\PrettyPageHandler();
70 1
            $Handler->setPageTitle("Divergence Error");
71
72 1
            $this->whoops->pushHandler($Handler);
73 1
            $this->whoops->register();
74
        } else {
75 3
            error_reporting(0);
76
        }
77
    }
78
}
79