Maurits van der Schee 5年前
コミット
c488a344a6

+ 2167
- 613
api.php
ファイル差分が大きすぎるため省略します
ファイルの表示


+ 25
- 8
build.php ファイルの表示

@@ -1,17 +1,35 @@
1 1
 <?php
2 2
 
3
-function runDir(String $base, String $dir, array &$lines): int
3
+function prioritySort(string $dir, array $entries, array $priority): array
4
+{
5
+    $result = array();
6
+    foreach ($priority as $file) {
7
+        if (dirname($file) == $dir) {
8
+            if (in_array(basename($file), $entries)) {
9
+                array_push($result, basename($file));
10
+            }
11
+        }
12
+    }
13
+    $entries = array_diff($entries, $result);
14
+    sort($entries);
15
+    foreach ($entries as $entry) {
16
+        array_push($result, $entry);
17
+    }
18
+    return $result;
19
+}
20
+
21
+function runDir(string $base, string $dir, array &$lines, array $priority): int
4 22
 {
5 23
     $count = 0;
6 24
     $entries = scandir($dir);
7
-    sort($entries);
25
+    $entries = prioritySort($dir, $entries, $priority);
8 26
     foreach ($entries as $entry) {
9 27
         if ($entry === '.' || $entry === '..') {
10 28
             continue;
11 29
         }
12 30
         $filename = "$base/$dir/$entry";
13 31
         if (is_dir($filename)) {
14
-            $count += runDir($base, "$dir/$entry", $lines);
32
+            $count += runDir($base, "$dir/$entry", $lines, $priority);
15 33
         }
16 34
     }
17 35
     foreach ($entries as $entry) {
@@ -21,6 +39,7 @@ function runDir(String $base, String $dir, array &$lines): int
21 39
                 continue;
22 40
             }
23 41
             $data = file_get_contents($filename);
42
+            $data = preg_replace('|/\*\*.*?\*/|s', '', $data);
24 43
             array_push($lines, "// file: $dir/$entry");
25 44
             foreach (explode("\n", $data) as $line) {
26 45
                 if (!preg_match('/^<\?php|^namespace |^use |spl_autoload_register|declare\s*\(\s*strict_types\s*=\s*1|^\s*\/\//', $line)) {
@@ -51,14 +70,12 @@ EOF;
51 70
     }
52 71
 }
53 72
 
54
-function run(String $base, String $dir, String $filename)
73
+function run(string $base, string $dir, string $filename, array $priority)
55 74
 {
56 75
     $lines = [];
57 76
     $start = microtime(true);
58 77
     addHeader($lines);
59
-    $count = runDir($base, 'src/Psr', $lines);
60
-    $count += runDir($base, 'src/Nyholm', $lines);
61
-    $count += runDir($base, 'src/Tqdev', $lines);
78
+    $count = runDir($base, 'src', $lines, $priority);
62 79
     $data = implode("\n", $lines);
63 80
     $data = preg_replace('/\n\s*\n\s*\n/', "\n\n", $data);
64 81
     file_put_contents('tmp_' . $filename, $data);
@@ -71,4 +88,4 @@ function run(String $base, String $dir, String $filename)
71 88
     echo sprintf("%d files combined in %d ms into '%s'\n", $count, $time, $filename);
72 89
 }
73 90
 
74
-run(__DIR__, 'src', 'api.php');
91
+run(__DIR__, 'src', 'api.php', ['src/Psr']);

+ 0
- 40
src/Nyholm/Psr7/Factory/HttplugFactory.php ファイルの表示

@@ -1,40 +0,0 @@
1
-<?php
2
-
3
-declare(strict_types=1);
4
-
5
-namespace Nyholm\Psr7\Factory;
6
-
7
-use Http\Message\{MessageFactory, StreamFactory, UriFactory};
8
-use Nyholm\Psr7\{Request, Response, Stream, Uri};
9
-use Psr\Http\Message\UriInterface;
10
-
11
-/**
12
- * @author Tobias Nyholm <tobias.nyholm@gmail.com>
13
- * @author Martijn van der Ven <martijn@vanderven.se>
14
- */
15
-final class HttplugFactory implements MessageFactory, StreamFactory, UriFactory
16
-{
17
-    public function createRequest($method, $uri, array $headers = [], $body = null, $protocolVersion = '1.1')
18
-    {
19
-        return new Request($method, $uri, $headers, $body, $protocolVersion);
20
-    }
21
-
22
-    public function createResponse($statusCode = 200, $reasonPhrase = null, array $headers = [], $body = null, $version = '1.1')
23
-    {
24
-        return new Response((int) $statusCode, $headers, $body, $version, $reasonPhrase);
25
-    }
26
-
27
-    public function createStream($body = null)
28
-    {
29
-        return Stream::create($body ?? '');
30
-    }
31
-
32
-    public function createUri($uri = ''): UriInterface
33
-    {
34
-        if ($uri instanceof UriInterface) {
35
-            return $uri;
36
-        }
37
-
38
-        return new Uri($uri);
39
-    }
40
-}

+ 3
- 5
src/Nyholm/Psr7/Request.php ファイルの表示

@@ -1,12 +1,10 @@
1 1
 <?php
2 2
 
3
-declare (strict_types = 1);
3
+declare(strict_types=1);
4 4
 
5 5
 namespace Nyholm\Psr7;
6 6
 
7
-use Psr\Http\Message\RequestInterface;
8
-use Psr\Http\Message\StreamInterface;
9
-use Psr\Http\Message\UriInterface;
7
+use Psr\Http\Message\{RequestInterface, StreamInterface, UriInterface};
10 8
 
11 9
 /**
12 10
  * @author Tobias Nyholm <tobias.nyholm@gmail.com>
@@ -27,7 +25,7 @@ final class Request implements RequestInterface
27 25
     public function __construct(string $method, $uri, array $headers = [], $body = null, string $version = '1.1')
28 26
     {
29 27
         if (!($uri instanceof UriInterface)) {
30
-            $uri = new Uri((string) $uri);
28
+            $uri = new Uri($uri);
31 29
         }
32 30
 
33 31
         $this->method = $method;

+ 1
- 1
src/Nyholm/Psr7/ServerRequest.php ファイルの表示

@@ -50,7 +50,7 @@ final class ServerRequest implements ServerRequestInterface
50 50
         $this->serverParams = $serverParams;
51 51
 
52 52
         if (!($uri instanceof UriInterface)) {
53
-            $uri = new Uri((string) $uri);
53
+            $uri = new Uri($uri);
54 54
         }
55 55
 
56 56
         $this->method = $method;

+ 2
- 1
src/Tqdev/PhpCrudApi/Api.php ファイルの表示

@@ -29,6 +29,7 @@ use Tqdev\PhpCrudApi\Middleware\XsrfMiddleware;
29 29
 use Tqdev\PhpCrudApi\OpenApi\OpenApiService;
30 30
 use Tqdev\PhpCrudApi\Record\ErrorCode;
31 31
 use Tqdev\PhpCrudApi\Record\RecordService;
32
+use Tqdev\PhpCrudApi\ResponseUtils;
32 33
 
33 34
 class Api
34 35
 {
@@ -125,7 +126,7 @@ class Api
125 126
         } catch (\Throwable $e) {
126 127
             $response = $this->responder->error(ErrorCode::ERROR_NOT_FOUND, $e->getMessage());
127 128
             if ($this->debug) {
128
-                $response->addExceptionHeaders($e);
129
+                $response = ResponseUtils::addExceptionHeaders($response, $e);
129 130
             }
130 131
         }
131 132
         return $response;

+ 2
- 1
src/Tqdev/PhpCrudApi/Middleware/Router/SimpleRouter.php ファイルの表示

@@ -8,6 +8,7 @@ use Tqdev\PhpCrudApi\Controller\Responder;
8 8
 use Tqdev\PhpCrudApi\Middleware\Base\Middleware;
9 9
 use Tqdev\PhpCrudApi\Record\ErrorCode;
10 10
 use Tqdev\PhpCrudApi\Record\PathTree;
11
+use Tqdev\PhpCrudApi\ResponseUtils;
11 12
 
12 13
 class SimpleRouter implements Router
13 14
 {
@@ -106,7 +107,7 @@ class SimpleRouter implements Router
106 107
                 $response = $this->responder->error(ErrorCode::DATA_INTEGRITY_VIOLATION, '');
107 108
             }
108 109
             if ($this->debug) {
109
-                $response->addExceptionHeaders($e);
110
+                $response = ResponseUtils::addExceptionHeaders($response, $e);
110 111
             }
111 112
         }
112 113
         return $response;

+ 1
- 0
src/clone.sh ファイルの表示

@@ -12,6 +12,7 @@ git clone git@github.com:Nyholm/psr7.git
12 12
 mkdir -p Nyholm/Psr7
13 13
 cp -R psr7/src/* Nyholm/Psr7
14 14
 rm -Rf psr7
15
+rm Nyholm/Psr7/Factory/HttplugFactory.php
15 16
 
16 17
 git clone git@github.com:Nyholm/psr7-server.git
17 18
 mkdir -p Nyholm/Psr7Server

+ 4
- 4
test.php ファイルの表示

@@ -9,7 +9,7 @@ spl_autoload_register(function ($class) {
9 9
     include str_replace('\\', '/', "src\\$class.php");
10 10
 });
11 11
 
12
-function runDir(Config $config, String $dir, array $matches, String $category): array
12
+function runDir(Config $config, string $dir, array $matches, string $category): array
13 13
 {
14 14
     $success = 0;
15 15
     $total = 0;
@@ -40,7 +40,7 @@ function runDir(Config $config, String $dir, array $matches, String $category):
40 40
     return compact('total', 'success', 'failed');
41 41
 }
42 42
 
43
-function runTest(Config $config, String $file, String $category): int
43
+function runTest(Config $config, string $file, string $category): int
44 44
 {
45 45
     $title = ucwords(str_replace('_', ' ', $category)) . '/';
46 46
     $title .= ucwords(str_replace('_', ' ', substr(basename($file), 0, -4)));
@@ -78,7 +78,7 @@ function runTest(Config $config, String $file, String $category): int
78 78
     return $success;
79 79
 }
80 80
 
81
-function loadFixture(String $dir, Config $config)
81
+function loadFixture(string $dir, Config $config)
82 82
 {
83 83
     $driver = $config->getDriver();
84 84
     $filename = "$dir/fixtures/blog_$driver.sql";
@@ -113,7 +113,7 @@ function loadFixture(String $dir, Config $config)
113 113
     }
114 114
 }
115 115
 
116
-function run(array $drivers, String $dir, array $matches)
116
+function run(array $drivers, string $dir, array $matches)
117 117
 {
118 118
     foreach ($drivers as $driver) {
119 119
         if (isset($matches[0])) {

+ 0
- 8854
tmp_api.php
ファイル差分が大きすぎるため省略します
ファイルの表示


読み込み中…
キャンセル
保存