diff --git a/composer.json b/composer.json index 5dbea0a..44326ed 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "monolog/monolog": "~1.17", "slim/php-view": "^2.1", "alquran/api-client": "dev-master", - "alquran/tools": "dev-master" + "alquran/tools": "dev-master", + "vesica/slim-middlewares": "1.0" }, "autoload": { "psr-0": {"": "src/"} diff --git a/composer.lock b/composer.lock index 5fb3d02..0f8b400 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4f20b49ab178b34cebf05c32f1463767", + "content-hash": "729b901eba699e4b1e421759176b0fae", "packages": [ { "name": "alquran/api-client", @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/islamic-network/alquran-api-client-php.git", - "reference": "32479cde21cfef10784aecc5b476292d96ce874b" + "reference": "f155320f0de58cc1be880380b87ce01c936757ac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/islamic-network/alquran-api-client-php/zipball/32479cde21cfef10784aecc5b476292d96ce874b", - "reference": "32479cde21cfef10784aecc5b476292d96ce874b", + "url": "https://api.github.com/repos/islamic-network/alquran-api-client-php/zipball/f155320f0de58cc1be880380b87ce01c936757ac", + "reference": "f155320f0de58cc1be880380b87ce01c936757ac", "shasum": "" }, "require": { @@ -40,10 +40,10 @@ ], "description": "AlQuran.cloud REST API Client", "support": { - "source": "https://github.com/meezaan/alquran-api-client-php/tree/master", - "issues": "https://github.com/meezaan/alquran-api-client-php/issues" + "source": "https://github.com/islamic-network/alquran-api-client-php/tree/master", + "issues": "https://github.com/islamic-network/alquran-api-client-php/issues" }, - "time": "2017-05-05 15:45:37" + "time": "2019-01-23T09:54:05+00:00" }, { "name": "alquran/tools", @@ -51,12 +51,12 @@ "source": { "type": "git", "url": "https://github.com/islamic-network/alquran-tools.git", - "reference": "bd83c1a6a96bd1c1806d2ac5602ec8e12a0f8471" + "reference": "df80ba6a3fe9770c6cd354f583d766eecf8653d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/islamic-network/alquran-tools/zipball/bd83c1a6a96bd1c1806d2ac5602ec8e12a0f8471", - "reference": "bd83c1a6a96bd1c1806d2ac5602ec8e12a0f8471", + "url": "https://api.github.com/repos/islamic-network/alquran-tools/zipball/df80ba6a3fe9770c6cd354f583d766eecf8653d8", + "reference": "df80ba6a3fe9770c6cd354f583d766eecf8653d8", "shasum": "" }, "type": "library", @@ -73,7 +73,7 @@ } ], "description": "Various tools to parse and process Quran Text", - "time": "2017-07-10 11:54:37" + "time": "2019-01-23T10:01:36+00:00" }, { "name": "container-interop/container-interop", @@ -108,16 +108,16 @@ }, { "name": "guzzlehttp/guzzle", - "version": "6.3.0", + "version": "6.3.3", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699" + "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/f4db5a78a5ea468d4831de7f0bf9d9415e348699", - "reference": "f4db5a78a5ea468d4831de7f0bf9d9415e348699", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", + "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", "shasum": "" }, "require": { @@ -127,7 +127,7 @@ }, "require-dev": { "ext-curl": "*", - "phpunit/phpunit": "^4.0 || ^5.0", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", "psr/log": "^1.0" }, "suggest": { @@ -136,7 +136,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "6.2-dev" + "dev-master": "6.3-dev" } }, "autoload": { @@ -169,7 +169,7 @@ "rest", "web service" ], - "time": "2017-06-22T18:50:49+00:00" + "time": "2018-04-22T15:46:56+00:00" }, { "name": "guzzlehttp/promises", @@ -224,32 +224,33 @@ }, { "name": "guzzlehttp/psr7", - "version": "1.4.2", + "version": "1.5.2", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c" + "reference": "9f83dded91781a01c63574e387eaa769be769115" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/f5b8a8512e2b58b0071a7280e39f14f72e05d87c", - "reference": "f5b8a8512e2b58b0071a7280e39f14f72e05d87c", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/9f83dded91781a01c63574e387eaa769be769115", + "reference": "9f83dded91781a01c63574e387eaa769be769115", "shasum": "" }, "require": { "php": ">=5.4.0", - "psr/http-message": "~1.0" + "psr/http-message": "~1.0", + "ralouphie/getallheaders": "^2.0.5" }, "provide": { "psr/http-message-implementation": "1.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "1.5-dev" } }, "autoload": { @@ -279,26 +280,27 @@ "keywords": [ "http", "message", + "psr-7", "request", "response", "stream", "uri", "url" ], - "time": "2017-03-20T17:10:46+00:00" + "time": "2018-12-04T20:46:45+00:00" }, { "name": "monolog/monolog", - "version": "1.23.0", + "version": "1.24.0", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4" + "reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/fd8c787753b3a2ad11bc60c063cff1358a32a3b4", - "reference": "fd8c787753b3a2ad11bc60c063cff1358a32a3b4", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266", + "reference": "bfc9ebb28f97e7a24c45bdc3f0ff482e47bb0266", "shasum": "" }, "require": { @@ -363,25 +365,28 @@ "logging", "psr-3" ], - "time": "2017-06-19T01:22:40+00:00" + "time": "2018-11-05T09:00:11+00:00" }, { "name": "nikic/fast-route", - "version": "v1.2.0", + "version": "v1.3.0", "source": { "type": "git", "url": "https://github.com/nikic/FastRoute.git", - "reference": "b5f95749071c82a8e0f58586987627054400cdf6" + "reference": "181d480e08d9476e61381e04a71b34dc0432e812" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/FastRoute/zipball/b5f95749071c82a8e0f58586987627054400cdf6", - "reference": "b5f95749071c82a8e0f58586987627054400cdf6", + "url": "https://api.github.com/repos/nikic/FastRoute/zipball/181d480e08d9476e61381e04a71b34dc0432e812", + "reference": "181d480e08d9476e61381e04a71b34dc0432e812", "shasum": "" }, "require": { "php": ">=5.4.0" }, + "require-dev": { + "phpunit/phpunit": "^4.8.35|~5.7" + }, "type": "library", "autoload": { "psr-4": { @@ -406,20 +411,20 @@ "router", "routing" ], - "time": "2017-01-19T11:35:12+00:00" + "time": "2018-02-13T20:26:39+00:00" }, { "name": "pimple/pimple", - "version": "v3.1.0", + "version": "v3.2.3", "source": { "type": "git", "url": "https://github.com/silexphp/Pimple.git", - "reference": "279b56046fb368deacf77e2f8f3bdcea45cc367a" + "reference": "9e403941ef9d65d20cba7d54e29fe906db42cf32" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/silexphp/Pimple/zipball/279b56046fb368deacf77e2f8f3bdcea45cc367a", - "reference": "279b56046fb368deacf77e2f8f3bdcea45cc367a", + "url": "https://api.github.com/repos/silexphp/Pimple/zipball/9e403941ef9d65d20cba7d54e29fe906db42cf32", + "reference": "9e403941ef9d65d20cba7d54e29fe906db42cf32", "shasum": "" }, "require": { @@ -432,7 +437,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "3.1.x-dev" + "dev-master": "3.2.x-dev" } }, "autoload": { @@ -456,7 +461,7 @@ "container", "dependency injection" ], - "time": "2017-07-03T14:06:46+00:00" + "time": "2018-01-21T07:42:36+00:00" }, { "name": "psr/container", @@ -559,16 +564,16 @@ }, { "name": "psr/log", - "version": "1.0.2", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/php-fig/log.git", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d" + "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/log/zipball/4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", - "reference": "4ebe3a8bf773a19edfe0a84b6585ba3d401b724d", + "url": "https://api.github.com/repos/php-fig/log/zipball/6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", + "reference": "6c001f1daafa3a3ac1d8ff69ee4db8e799a654dd", "shasum": "" }, "require": { @@ -602,20 +607,60 @@ "psr", "psr-3" ], - "time": "2016-10-10T12:19:37+00:00" + "time": "2018-11-20T15:27:04+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "2.0.5", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/5601c8a83fbba7ef674a7369456d12f1e0d0eafa", + "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "require-dev": { + "phpunit/phpunit": "~3.7.0", + "satooshi/php-coveralls": ">=1.0" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "time": "2016-02-11T07:05:27+00:00" }, { "name": "slim/php-view", - "version": "2.2.0", + "version": "2.2.1", "source": { "type": "git", "url": "https://github.com/slimphp/PHP-View.git", - "reference": "122ed121a8d9cf91a94020814d2a3ee6c836754f" + "reference": "a13ada9d7962ca1b48799c0d9ffbca4c33245aed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slimphp/PHP-View/zipball/122ed121a8d9cf91a94020814d2a3ee6c836754f", - "reference": "122ed121a8d9cf91a94020814d2a3ee6c836754f", + "url": "https://api.github.com/repos/slimphp/PHP-View/zipball/a13ada9d7962ca1b48799c0d9ffbca4c33245aed", + "reference": "a13ada9d7962ca1b48799c0d9ffbca4c33245aed", "shasum": "" }, "require": { @@ -651,20 +696,20 @@ "template", "view" ], - "time": "2016-10-11T07:43:08+00:00" + "time": "2019-04-15T20:43:28+00:00" }, { "name": "slim/slim", - "version": "3.8.1", + "version": "3.12.1", "source": { "type": "git", "url": "https://github.com/slimphp/Slim.git", - "reference": "5385302707530b2bccee1769613ad769859b826d" + "reference": "eaee12ef8d0750db62b8c548016d82fb33addb6b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slimphp/Slim/zipball/5385302707530b2bccee1769613ad769859b826d", - "reference": "5385302707530b2bccee1769613ad769859b826d", + "url": "https://api.github.com/repos/slimphp/Slim/zipball/eaee12ef8d0750db62b8c548016d82fb33addb6b", + "reference": "eaee12ef8d0750db62b8c548016d82fb33addb6b", "shasum": "" }, "require": { @@ -722,7 +767,37 @@ "micro", "router" ], - "time": "2017-03-19T17:55:20+00:00" + "time": "2019-04-16T16:47:29+00:00" + }, + { + "name": "vesica/slim-middlewares", + "version": "1.0", + "source": { + "type": "git", + "url": "https://github.com/vesica/slim-middleware.git", + "reference": "8e0d323b9a75e7afbeca40524c637504c02a7fa8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/vesica/slim-middleware/zipball/8e0d323b9a75e7afbeca40524c637504c02a7fa8", + "reference": "8e0d323b9a75e7afbeca40524c637504c02a7fa8", + "shasum": "" + }, + "require": { + "psr/http-message": "^1.0" + }, + "require-dev": { + "phpunit/phpunit": "^7.5.3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Vesica\\Slim\\Middleware\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "description": "A library to write to and read from AWS Kinesis", + "time": "2019-04-20T15:27:09+00:00" } ], "packages-dev": [], diff --git a/config/dependencies.php b/config/dependencies.php index 8b15810..37c7c99 100644 --- a/config/dependencies.php +++ b/config/dependencies.php @@ -3,6 +3,7 @@ use Monolog\Handler\StreamHandler; use Slim\Http\Request; use Slim\Http\Response; +use Vesica\Slim\Middleware\Headers\Validate as HeaderValidationMiddleware; $container = $app->getContainer(); @@ -53,22 +54,12 @@ }; /** Invoke Middleware for Load Balancer Checks */ -$app->add(function (Request $request, Response $response, $next) { - $lbMode = (bool) getenv('LOAD_BALANCER_MODE'); - if ($lbMode) { - // Validate Key - if (isset($request->getHeader('X-LOAD-BALANCER')[0]) && $request->getHeader('X-LOAD-BALANCER')[0] === getenv('LOAD_BALANCER_KEY')) { - $response = $next($request, $response); - - return $response; - } - - throw new \Exception('Invalid Load Balancer Key.', 403); - } - - $response = $next($request, $response); - - return $response; -}); +$app->add(new HeaderValidationMiddleware( + (bool) getenv('LOAD_BALANCER_MODE'), + 'X-LOAD-BALANCER', + getenv('LOAD_BALANCER_KEY'), + 'Invalid Load Balancer Key.' + ) +);