← All changes
|
includes/sdk/s3/Aws/EndpointV2/Ruleset/RulesetStandardLibrary.php
+8
-2
1.2.13
→
1.4.2
View file →
| @@ -54,8 +54,13 @@ | ||
| 54 | 54 | * @return mixed |
| 55 | 55 | */ |
| 56 | 56 | public function getAttr($from, $path) |
| 57 | 57 | { |
| 58 | + // Handles the case where "[<int|string]" is provided as the top-level path | |
| 59 | + if (\preg_match('/^\\[(\\w+)\\]$/', $path, $matches)) { | |
| 60 | + $index = \is_numeric($matches[1]) ? (int) $matches[1] : $matches[1]; | |
| 61 | + return $from[$index] ?? null; | |
| 62 | + } | |
| 58 | 63 | $parts = \explode('.', $path); |
| 59 | 64 | foreach ($parts as $part) { |
| 60 | 65 | $sliceIdx = \strpos($part, '['); |
| 61 | 66 | if ($sliceIdx !== \false) { |
| @@ -61,10 +66,11 @@ | ||
| 61 | 66 | if ($sliceIdx !== \false) { |
| 62 | 67 | if (\substr($part, -1) !== ']') { |
| 63 | 68 | return null; |
| 64 | 69 | } |
| 65 | - $slice = \intval(\substr($part, $sliceIdx + 1, \strlen($part) - 1)); | |
| 66 | - $from = isset($from[\substr($part, 0, $sliceIdx)][$slice]) ? $from[\substr($part, 0, $sliceIdx)][$slice] : null; | |
| 70 | + $slice = (int) \substr($part, $sliceIdx + 1, \strlen($part) - 1); | |
| 71 | + $fromIndex = \substr($part, 0, $sliceIdx); | |
| 72 | + $from = $from[$fromIndex][$slice] ?? null; | |
| 67 | 73 | } else { |
| 68 | 74 | $from = $from[$part]; |
| 69 | 75 | } |
| 70 | 76 | } |