Browse Source

Merge branch 'master' of github.com:mevdschee/php-crud-api

Maurits van der Schee 4 years ago
parent
commit
282daac1ad

+ 8
- 1
Dockerfile View File

@@ -1,7 +1,14 @@
1 1
 FROM php:apache
2 2
 
3 3
 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
+
5 12
 RUN a2enmod rewrite
6 13
 
7 14
 COPY api.php /var/www/html/api.php

+ 6
- 4
README.md View File

@@ -614,10 +614,10 @@ You can tune the middleware behavior using middleware specific configuration par
614 614
 - "firewall.reverseProxy": Set to "true" when a reverse proxy is used ("")
615 615
 - "firewall.allowedIpAddresses": List of IP addresses that are allowed to connect ("")
616 616
 - "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")
618 618
 - "cors.allowMethods": The methods allowed in the CORS request ("OPTIONS, GET, PUT, POST, DELETE, PATCH")
619 619
 - "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")
621 621
 - "cors.maxAge": The time that the CORS grant is valid in seconds ("1728000")
622 622
 - "xsrf.excludeMethods": The methods that do not require XSRF protection ("OPTIONS,GET")
623 623
 - "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:
1334 1334
 
1335 1335
 [https://hub.docker.com/r/mevdschee/php-crud-api](https://hub.docker.com/r/mevdschee/php-crud-api)
1336 1336
 
1337
+It will be automatically build on every release. The "latest" tag points to the last release.
1338
+
1337 1339
 ### Docker compose
1338 1340
 
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:
1340 1342
 
1341 1343
     sudo apt install docker-compose
1342 1344
     docker-compose build
@@ -1348,4 +1350,4 @@ Test the script (running in the container) by opening the following URL:
1348 1350
 
1349 1351
     http://localhost:8080/records/posts/1
1350 1352
 
1351
-Enjoy!
1353
+Enjoy!

+ 3
- 3
api.php View File

@@ -7399,7 +7399,7 @@ namespace Tqdev\PhpCrudApi\Middleware {
7399 7399
                 $response = $this->responder->error(ErrorCode::ORIGIN_FORBIDDEN, $origin);
7400 7400
             } elseif ($method == 'OPTIONS') {
7401 7401
                 $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');
7403 7403
                 if ($allowHeaders) {
7404 7404
                     $response = $response->withHeader('Access-Control-Allow-Headers', $allowHeaders);
7405 7405
                 }
@@ -7415,7 +7415,7 @@ namespace Tqdev\PhpCrudApi\Middleware {
7415 7415
                 if ($maxAge) {
7416 7416
                     $response = $response->withHeader('Access-Control-Max-Age', $maxAge);
7417 7417
                 }
7418
-                $exposeHeaders = $this->getProperty('exposeHeaders', '');
7418
+                $exposeHeaders = $this->getProperty('exposeHeaders', 'X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File');
7419 7419
                 if ($exposeHeaders) {
7420 7420
                     $response = $response->withHeader('Access-Control-Expose-Headers', $exposeHeaders);
7421 7421
                 }
@@ -7954,7 +7954,7 @@ namespace Tqdev\PhpCrudApi\Middleware {
7954 7954
         private function getPairs($handler, string $operation, string $tableName): array
7955 7955
         {
7956 7956
             $result = array();
7957
-            $pairs = call_user_func($handler, $operation, $tableName);
7957
+            $pairs = call_user_func($handler, $operation, $tableName) ?: [];
7958 7958
             $table = $this->reflection->getTable($tableName);
7959 7959
             foreach ($pairs as $k => $v) {
7960 7960
                 if ($table->hasColumn($k)) {

+ 2
- 2
src/Tqdev/PhpCrudApi/Middleware/CorsMiddleware.php View File

@@ -34,7 +34,7 @@ class CorsMiddleware extends Middleware
34 34
             $response = $this->responder->error(ErrorCode::ORIGIN_FORBIDDEN, $origin);
35 35
         } elseif ($method == 'OPTIONS') {
36 36
             $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');
38 38
             if ($allowHeaders) {
39 39
                 $response = $response->withHeader('Access-Control-Allow-Headers', $allowHeaders);
40 40
             }
@@ -50,7 +50,7 @@ class CorsMiddleware extends Middleware
50 50
             if ($maxAge) {
51 51
                 $response = $response->withHeader('Access-Control-Max-Age', $maxAge);
52 52
             }
53
-            $exposeHeaders = $this->getProperty('exposeHeaders', '');
53
+            $exposeHeaders = $this->getProperty('exposeHeaders', 'X-Debug-Info, X-Exception-Name, X-Exception-Message, X-Exception-File');
54 54
             if ($exposeHeaders) {
55 55
                 $response = $response->withHeader('Access-Control-Expose-Headers', $exposeHeaders);
56 56
             }

+ 1
- 1
src/Tqdev/PhpCrudApi/Middleware/MultiTenancyMiddleware.php View File

@@ -38,7 +38,7 @@ class MultiTenancyMiddleware extends Middleware
38 38
     private function getPairs($handler, string $operation, string $tableName): array
39 39
     {
40 40
         $result = array();
41
-        $pairs = call_user_func($handler, $operation, $tableName);
41
+        $pairs = call_user_func($handler, $operation, $tableName) ?: [];
42 42
         $table = $this->reflection->getTable($tableName);
43 43
         foreach ($pairs as $k => $v) {
44 44
             if ($table->hasColumn($k)) {

Loading…
Cancel
Save