application.services.php
1 month ago
command.bus.php
2 years ago
container.php
6 months ago
domain.event.bus.php
1 year ago
domain.services.php
1 year ago
infrastructure.services.php
4 months ago
infrastructure.user.php
1 year ago
repositories.php
6 months ago
request.php
6 months ago
container.php
119 lines
| 1 | <?php |
| 2 | |
| 3 | use AmeliaBooking\Domain\Services\Settings\SettingsService; |
| 4 | use AmeliaBooking\Infrastructure\Common\Container; |
| 5 | use AmeliaBooking\Infrastructure\Connection; |
| 6 | |
| 7 | // Handle the 404 API calls |
| 8 | $entries['notFoundHandler'] = function () { |
| 9 | return function ($request, \Slim\Http\Response $response) { |
| 10 | return $response->withStatus(404); |
| 11 | }; |
| 12 | }; |
| 13 | |
| 14 | // Handle the Method Not Allowed API calls |
| 15 | $entries['notAllowedHandler'] = function () { |
| 16 | return function ($request, \Slim\Http\Response $response) { |
| 17 | return $response->withStatus(405); |
| 18 | }; |
| 19 | }; |
| 20 | |
| 21 | // Handle the errors |
| 22 | $entries['errorHandler'] = function (Container $c) { |
| 23 | return function ($request, \Slim\Http\Response $response, $exception) { |
| 24 | /** @var Exception $exception */ |
| 25 | |
| 26 | switch (get_class($exception)) { |
| 27 | case \AmeliaBooking\Application\Common\Exceptions\AccessDeniedException::class: |
| 28 | $status = \AmeliaBooking\Application\Controller\Controller::STATUS_FORBIDDEN; |
| 29 | break; |
| 30 | default: |
| 31 | $status = \AmeliaBooking\Application\Controller\Controller::STATUS_INTERNAL_SERVER_ERROR; |
| 32 | } |
| 33 | |
| 34 | $responseMessage = ['message' => $exception->getMessage()]; |
| 35 | |
| 36 | if (method_exists($request, 'getParam') && $request->getParam('showAmeliaSqlExceptions')) { |
| 37 | $responseMessage['exception'] = $exception->getPrevious() ? $exception->getPrevious()->getMessage() : ''; |
| 38 | } |
| 39 | |
| 40 | return $response->withStatus($status) |
| 41 | ->withHeader('Content-Type', 'text/html') |
| 42 | ->write(json_encode($responseMessage)); |
| 43 | }; |
| 44 | }; |
| 45 | |
| 46 | |
| 47 | // Disabled for now for easier debug |
| 48 | //// Handle PHP errors |
| 49 | //$entries['phpErrorHandler'] = function (Container $c) { |
| 50 | // return function ($request, \Slim\Http\Response $response, $exception) use ($c) { |
| 51 | // /** @var Exception $exception */ |
| 52 | // |
| 53 | // return $response->withStatus(500) |
| 54 | // ->withHeader('Content-Type', 'text/html') |
| 55 | // ->write($exception->getMessage()); |
| 56 | // }; |
| 57 | //}; |
| 58 | |
| 59 | ########################################################################## |
| 60 | ########################################################################## |
| 61 | # App common |
| 62 | ########################################################################## |
| 63 | ########################################################################## |
| 64 | $entries['app.connection'] = function () { |
| 65 | global $wpdb; |
| 66 | |
| 67 | return new Connection($wpdb); |
| 68 | }; |
| 69 | |
| 70 | |
| 71 | ################ |
| 72 | # Repositories # |
| 73 | ################ |
| 74 | require 'repositories.php'; |
| 75 | |
| 76 | ############################ |
| 77 | # Currently logged in user # |
| 78 | ############################ |
| 79 | require 'infrastructure.user.php'; |
| 80 | |
| 81 | ################### |
| 82 | # Domain Services # |
| 83 | ################### |
| 84 | require 'domain.services.php'; |
| 85 | |
| 86 | ######################## |
| 87 | # Application Services # |
| 88 | ######################## |
| 89 | require 'application.services.php'; |
| 90 | |
| 91 | ######################## |
| 92 | # Infrastructure Services # |
| 93 | ######################## |
| 94 | require 'infrastructure.services.php'; |
| 95 | |
| 96 | ############### |
| 97 | # Command bus # |
| 98 | ############### |
| 99 | require 'command.bus.php'; |
| 100 | |
| 101 | #################### |
| 102 | # Domain event bus # |
| 103 | #################### |
| 104 | require 'domain.event.bus.php'; |
| 105 | |
| 106 | $entries['settings'] = [ |
| 107 | // Slim Settings |
| 108 | 'determineRouteBeforeAppMiddleware' => true, |
| 109 | 'displayErrorDetails' => true, |
| 110 | 'addContentLengthHeader' => false, //added due to error on dev server (check the cause) |
| 111 | ]; |
| 112 | |
| 113 | ###################### |
| 114 | # Request overriding # |
| 115 | ###################### |
| 116 | require 'request.php'; |
| 117 | |
| 118 | return new Container($entries); |
| 119 |