swaggest /
api-compat
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Swaggest\ApiCompat; |
||
| 4 | |||
| 5 | |||
| 6 | use Swaggest\JsonDiff\JsonPointer; |
||
| 7 | |||
| 8 | class Path |
||
| 9 | { |
||
| 10 | 2 | public static function fitsPattern($path, $pattern) |
|
| 11 | { |
||
| 12 | 2 | $path = explode('/', $path); |
|
| 13 | 2 | $pattern = explode('/', $pattern); |
|
| 14 | |||
| 15 | 2 | foreach ($path as $i => $item) { |
|
| 16 | 2 | if (!isset($pattern[$i])) { |
|
| 17 | 2 | return false; |
|
| 18 | } |
||
| 19 | 2 | $pitem = $pattern[$i]; |
|
| 20 | 2 | if ($pitem === '...') { |
|
| 21 | 2 | return true; |
|
| 22 | } |
||
| 23 | 2 | if (($pitem === '*') || $pitem === $item) { |
|
| 24 | 2 | continue; |
|
| 25 | } else { |
||
| 26 | 2 | return false; |
|
| 27 | } |
||
| 28 | } |
||
| 29 | 2 | if (count($pattern) > count($path)) { |
|
| 30 | 2 | return false; |
|
| 31 | } |
||
| 32 | 2 | return true; |
|
| 33 | } |
||
| 34 | |||
| 35 | 1 | public static function quoteUrldecode($path) |
|
| 36 | { |
||
| 37 | 1 | $path = JsonPointer::splitPath($path); |
|
| 38 | 1 | foreach ($path as &$item) { |
|
| 39 | 1 | if ($item !== $u = urlencode($item)) { |
|
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 40 | 1 | $item = "'" . $item . "'"; |
|
| 41 | } |
||
| 42 | } |
||
| 43 | 1 | return '#/' . implode('/', $path); |
|
| 44 | } |
||
| 45 | } |