Skip to content

Commit 282daac

Browse files
committed
Merge branch 'master' of github.com:mevdschee/php-crud-api
2 parents f392314 + 5c783b3 commit 282daac

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

Dockerfile

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
FROM php:apache
22

33
RUN docker-php-ext-install pdo pdo_mysql
4-
4+
5+
RUN apt-get update; \
6+
apt-get install -y libpq5 libpq-dev; \
7+
docker-php-ext-install pdo pdo_pgsql; \
8+
apt-get autoremove --purge -y libpq-dev; \
9+
apt-get clean ; \
10+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
11+
512
RUN a2enmod rewrite
613

714
COPY api.php /var/www/html/api.php

README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,10 @@ You can tune the middleware behavior using middleware specific configuration par
614614
- "firewall.reverseProxy": Set to "true" when a reverse proxy is used ("")
615615
- "firewall.allowedIpAddresses": List of IP addresses that are allowed to connect ("")
616616
- "cors.allowedOrigins": The origins allowed in the CORS headers ("*")
617-
- "cors.allowHeaders": The headers allowed in the CORS request ("Content-Type, X-XSRF-TOKEN")
617+
- "cors.allowHeaders": The headers allowed in the CORS request ("Content-Type, X-XSRF-TOKEN, X-Authorization, X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File")
618618
- "cors.allowMethods": The methods allowed in the CORS request ("OPTIONS, GET, PUT, POST, DELETE, PATCH")
619619
- "cors.allowCredentials": To allow credentials in the CORS request ("true")
620-
- "cors.exposeHeaders": Whitelist headers that browsers are allowed to access ("")
620+
- "cors.exposeHeaders": Whitelist headers that browsers are allowed to access ("X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File")
621621
- "cors.maxAge": The time that the CORS grant is valid in seconds ("1728000")
622622
- "xsrf.excludeMethods": The methods that do not require XSRF protection ("OPTIONS,GET")
623623
- "xsrf.cookieName": The name of the XSRF protection cookie ("XSRF-TOKEN")
@@ -1334,9 +1334,11 @@ There is a `Dockerfile` in the repository that is used to build an image at:
13341334

13351335
[https://hub.docker.com/r/mevdschee/php-crud-api](https://hub.docker.com/r/mevdschee/php-crud-api)
13361336

1337+
It will be automatically build on every release. The "latest" tag points to the last release.
1338+
13371339
### Docker compose
13381340

1339-
This repository also contains a `docker-compose.yml` file that can be installed/built/ran using:
1341+
This repository also contains a `docker-compose.yml` file that you can install/build/run using:
13401342

13411343
sudo apt install docker-compose
13421344
docker-compose build
@@ -1348,4 +1350,4 @@ Test the script (running in the container) by opening the following URL:
13481350

13491351
http://localhost:8080/records/posts/1
13501352

1351-
Enjoy!
1353+
Enjoy!

api.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -7399,7 +7399,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
73997399
$response = $this->responder->error(ErrorCode::ORIGIN_FORBIDDEN, $origin);
74007400
} elseif ($method == 'OPTIONS') {
74017401
$response = ResponseFactory::fromStatus(ResponseFactory::OK);
7402-
$allowHeaders = $this->getProperty('allowHeaders', 'Content-Type, X-XSRF-TOKEN, X-Authorization');
7402+
$allowHeaders = $this->getProperty('allowHeaders', 'Content-Type, X-XSRF-TOKEN, X-Authorization, X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File');
74037403
if ($allowHeaders) {
74047404
$response = $response->withHeader('Access-Control-Allow-Headers', $allowHeaders);
74057405
}
@@ -7415,7 +7415,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
74157415
if ($maxAge) {
74167416
$response = $response->withHeader('Access-Control-Max-Age', $maxAge);
74177417
}
7418-
$exposeHeaders = $this->getProperty('exposeHeaders', '');
7418+
$exposeHeaders = $this->getProperty('exposeHeaders', 'X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File');
74197419
if ($exposeHeaders) {
74207420
$response = $response->withHeader('Access-Control-Expose-Headers', $exposeHeaders);
74217421
}
@@ -7954,7 +7954,7 @@ private function getCondition(string $tableName, array $pairs): Condition
79547954
private function getPairs($handler, string $operation, string $tableName): array
79557955
{
79567956
$result = array();
7957-
$pairs = call_user_func($handler, $operation, $tableName);
7957+
$pairs = call_user_func($handler, $operation, $tableName) ?: [];
79587958
$table = $this->reflection->getTable($tableName);
79597959
foreach ($pairs as $k => $v) {
79607960
if ($table->hasColumn($k)) {

src/Tqdev/PhpCrudApi/Middleware/CorsMiddleware.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
3434
$response = $this->responder->error(ErrorCode::ORIGIN_FORBIDDEN, $origin);
3535
} elseif ($method == 'OPTIONS') {
3636
$response = ResponseFactory::fromStatus(ResponseFactory::OK);
37-
$allowHeaders = $this->getProperty('allowHeaders', 'Content-Type, X-XSRF-TOKEN, X-Authorization');
37+
$allowHeaders = $this->getProperty('allowHeaders', 'Content-Type, X-XSRF-TOKEN, X-Authorization, X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File');
3838
if ($allowHeaders) {
3939
$response = $response->withHeader('Access-Control-Allow-Headers', $allowHeaders);
4040
}
@@ -50,7 +50,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
5050
if ($maxAge) {
5151
$response = $response->withHeader('Access-Control-Max-Age', $maxAge);
5252
}
53-
$exposeHeaders = $this->getProperty('exposeHeaders', '');
53+
$exposeHeaders = $this->getProperty('exposeHeaders', 'X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File');
5454
if ($exposeHeaders) {
5555
$response = $response->withHeader('Access-Control-Expose-Headers', $exposeHeaders);
5656
}

src/Tqdev/PhpCrudApi/Middleware/MultiTenancyMiddleware.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private function getCondition(string $tableName, array $pairs): Condition
3838
private function getPairs($handler, string $operation, string $tableName): array
3939
{
4040
$result = array();
41-
$pairs = call_user_func($handler, $operation, $tableName);
41+
$pairs = call_user_func($handler, $operation, $tableName) ?: [];
4242
$table = $this->reflection->getTable($tableName);
4343
foreach ($pairs as $k => $v) {
4444
if ($table->hasColumn($k)) {

0 commit comments

Comments
 (0)