Skip to content

Commit 56c80c0

Browse files
committed
Merge branch 'master' of github.com:mevdschee/php-crud-api
2 parents 7903b64 + 28026d6 commit 56c80c0

File tree

87 files changed

+493
-5340
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+493
-5340
lines changed

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
composer.phar
2-
composer.lock
3-
.git
2+
vendor/

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,18 @@ The following features are supported:
119119

120120
## Compilation
121121

122+
You can install all dependencies of this project using the following command:
123+
124+
php install.php
125+
122126
You can compile all files into a single "`api.php`" file using:
123127

124128
php build.php
125129

130+
NB: The install script will patch the dependencies in the vendor directory for PHP 7.0 compatibility.
131+
132+
### Development
133+
126134
You can access the non-compiled code at the URL:
127135

128136
http://localhost:8080/src/records/posts/1
@@ -137,7 +145,7 @@ You can update all dependencies of this project using the following command:
137145

138146
This script will install and run [Composer](https://getcomposer.org/) to update the dependencies.
139147

140-
NB: The update script will also patch the dependencies in the vendor directory for PHP 7.0 compatibility.
148+
NB: The update script will patch the dependencies in the vendor directory for PHP 7.0 compatibility.
141149

142150
## TreeQL, a pragmatic GraphQL
143151

api.php

+14-7
Original file line numberDiff line numberDiff line change
@@ -1498,6 +1498,11 @@ public function createRequest(string $method, $uri): RequestInterface
14981498

14991499
public function createResponse(int $code = 200, string $reasonPhrase = ''): ResponseInterface
15001500
{
1501+
if (2 > \func_num_args()) {
1502+
// This will make the Response class to use a custom reasonPhrase
1503+
$reasonPhrase = null;
1504+
}
1505+
15011506
return new Response($code, [], null, '1.1', $reasonPhrase);
15021507
}
15031508

@@ -1951,7 +1956,7 @@ public function __construct(int $status = 200, array $headers = [], $body = null
19511956
if (null === $reason && isset(self::PHRASES[$this->statusCode])) {
19521957
$this->reasonPhrase = self::PHRASES[$status];
19531958
} else {
1954-
$this->reasonPhrase = $reason;
1959+
$this->reasonPhrase = $reason ?? '';
19551960
}
19561961

19571962
$this->protocol = $version;
@@ -2226,7 +2231,7 @@ public static function create($body = ''): StreamInterface
22262231
$new = new self();
22272232
$new->stream = $body;
22282233
$meta = \stream_get_meta_data($new->stream);
2229-
$new->seekable = $meta['seekable'];
2234+
$new->seekable = $meta['seekable'] && 0 === \fseek($new->stream, 0, \SEEK_CUR);
22302235
$new->readable = isset(self::READ_WRITE_HASH['read'][$meta['mode']]);
22312236
$new->writable = isset(self::READ_WRITE_HASH['write'][$meta['mode']]);
22322237
$new->uri = $new->getMetadata('uri');
@@ -2854,8 +2859,8 @@ private function filterPort($port) /*:?int*/
28542859
}
28552860

28562861
$port = (int) $port;
2857-
if (1 > $port || 0xffff < $port) {
2858-
throw new \InvalidArgumentException(\sprintf('Invalid port: %d. Must be between 1 and 65535', $port));
2862+
if (0 > $port || 0xffff < $port) {
2863+
throw new \InvalidArgumentException(\sprintf('Invalid port: %d. Must be between 0 and 65535', $port));
28592864
}
28602865

28612866
return self::isNonStandardPort($this->scheme, $port) ? $port : null;
@@ -10130,7 +10135,7 @@ private function addParsedBody(ServerRequestInterface $request): ServerRequestIn
1013010135
{
1013110136
$parsedBody = $request->getParsedBody();
1013210137
if ($parsedBody) {
10133-
$request = $this->applySlim3Hack($request);
10138+
$request = $this->applySlimHack($request);
1013410139
} else {
1013510140
$body = $request->getBody();
1013610141
if ($body->isReadable()) {
@@ -10150,9 +10155,10 @@ private function addParsedBody(ServerRequestInterface $request): ServerRequestIn
1015010155
return $request;
1015110156
}
1015210157

10153-
private function applySlim3Hack(ServerRequestInterface $request): ServerRequestInterface
10158+
private function applySlimHack(ServerRequestInterface $request): ServerRequestInterface
1015410159
{
10155-
if (get_class($request) == 'Slim\Http\Request') {
10160+
$class = get_class($request);
10161+
if (substr($class, 0, 9) == 'Slim\Http') {
1015610162
$parsedBody = $request->getParsedBody();
1015710163
$contents = json_encode($parsedBody);
1015810164
$parsedBody = $this->parseBody($contents);
@@ -10622,6 +10628,7 @@ public static function toString(ResponseInterface $response): string
1062210628
'username' => 'php-crud-api',
1062310629
'password' => 'php-crud-api',
1062410630
'database' => 'php-crud-api',
10631+
'controllers' => 'records,columns'
1062510632
]);
1062610633
$request = RequestFactory::fromGlobals();
1062710634
$api = new Api($config);

build.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
// combine src and vendor directories into a single file
4+
35
function removeIgnored(string $dir, array &$entries, array $ignore)
46
{
57
foreach ($entries as $i => $entry) {
@@ -34,8 +36,8 @@ function runDir(string $base, string $dir, array &$lines, array $ignore): int
3436
$data = preg_replace('/\s*<\?php\s+/s', '', $data, 1);
3537
$data = preg_replace('/^.*?(vendor\/autoload|declare\s*\(\s*strict_types\s*=\s*1).*?$/m', '', $data);
3638
array_push($lines, "// file: $dir/$entry");
37-
if (!preg_match('/^\s*(namespace[^;]*);/', $data)){
38-
$data = "namespace;\n".$data;
39+
if (!preg_match('/^\s*(namespace[^;]*);/', $data)) {
40+
$data = "namespace;\n" . $data;
3941
}
4042
foreach (explode("\n", trim($data)) as $line) {
4143
if ($line) {

0 commit comments

Comments
 (0)