These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
1 ignored issue
–
show
|
|||
2 | /** |
||
3 | * Hummingbird Anime Client |
||
4 | * |
||
5 | * An API client for Hummingbird to manage anime and manga watch lists |
||
6 | * |
||
7 | * @package HummingbirdAnimeClient |
||
8 | * @author Timothy J. Warren |
||
9 | * @copyright Copyright (c) 2015 - 2016 |
||
10 | * @link https://github.com/timw4mail/HummingBirdAnimeClient |
||
11 | * @license MIT |
||
12 | */ |
||
13 | use Whoops\Handler\PrettyPageHandler; |
||
14 | use Whoops\Handler\JsonResponseHandler; |
||
15 | |||
16 | // Work around the silly timezone error |
||
17 | $timezone = ini_get('date.timezone'); |
||
18 | if ($timezone === '' || $timezone === FALSE) |
||
19 | { |
||
20 | ini_set('date.timezone', 'GMT'); |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * Joins paths together. Variadic to take an |
||
25 | * arbitrary number of arguments |
||
26 | * |
||
27 | * @return string |
||
28 | */ |
||
29 | function _dir() |
||
30 | { |
||
31 | return implode(DIRECTORY_SEPARATOR, func_get_args()); |
||
32 | } |
||
33 | |||
34 | // Define base directories |
||
35 | $APP_DIR = _dir(__DIR__, 'app'); |
||
36 | $SRC_DIR = _dir(__DIR__, 'src'); |
||
37 | $CONF_DIR = _dir($APP_DIR, 'config'); |
||
38 | |||
39 | /** |
||
40 | * Set up autoloaders |
||
41 | * |
||
42 | * @codeCoverageIgnore |
||
43 | * @return void |
||
44 | */ |
||
45 | spl_autoload_register(function($class) use ($SRC_DIR) { |
||
46 | $class_parts = explode('\\', $class); |
||
47 | $ns_path = $SRC_DIR . '/' . implode('/', $class_parts) . ".php"; |
||
48 | |||
49 | if (file_exists($ns_path)) |
||
50 | { |
||
51 | require_once($ns_path); |
||
52 | return; |
||
53 | } |
||
54 | }); |
||
55 | |||
56 | require _dir(__DIR__, '/vendor/autoload.php'); |
||
57 | |||
58 | // ------------------------------------------------------------------------- |
||
59 | // Setup error handling |
||
60 | // ------------------------------------------------------------------------- |
||
61 | $whoops = new \Whoops\Run(); |
||
62 | |||
63 | // Set up default handler for general errors |
||
64 | $defaultHandler = new PrettyPageHandler(); |
||
65 | $whoops->pushHandler($defaultHandler); |
||
66 | |||
67 | // Set up json handler for ajax errors |
||
68 | $jsonHandler = new JsonResponseHandler(); |
||
69 | $jsonHandler->onlyForAjaxRequests(TRUE); |
||
70 | $whoops->pushHandler($jsonHandler); |
||
71 | |||
72 | // Register as the error handler |
||
73 | $whoops->register(); |
||
74 | |||
75 | // ----------------------------------------------------------------------------- |
||
76 | // Dependency Injection setup |
||
77 | // ----------------------------------------------------------------------------- |
||
78 | require _dir($CONF_DIR, 'base_config.php'); // $base_config |
||
79 | require _dir($CONF_DIR, 'config.php'); // $config |
||
80 | $config_array = array_merge($base_config, $config); |
||
81 | $di = require _dir($APP_DIR, 'bootstrap.php'); |
||
82 | |||
83 | // Unset 'constants' |
||
84 | unset($APP_DIR); |
||
85 | unset($SRC_DIR); |
||
86 | unset($CONF_DIR); |
||
87 | |||
88 | $container = $di($config_array); |
||
89 | $container->set('error-handler', $defaultHandler); |
||
90 | |||
91 | // ----------------------------------------------------------------------------- |
||
92 | // Dispatch to the current route |
||
93 | // ----------------------------------------------------------------------------- |
||
94 | $container->get('dispatcher')->__invoke(); |
||
95 | |||
96 | // End of index.php |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.