Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 6... Línea 6...
6
use Aws\Api\Operation;
6
use Aws\Api\Operation;
7
use Aws\Api\Shape;
7
use Aws\Api\Shape;
8
use Aws\Api\StructureShape;
8
use Aws\Api\StructureShape;
9
use Aws\Api\TimestampShape;
9
use Aws\Api\TimestampShape;
10
use Aws\CommandInterface;
10
use Aws\CommandInterface;
11
use Aws\EndpointV2\EndpointProviderV2;
-
 
12
use Aws\EndpointV2\EndpointV2SerializerTrait;
11
use Aws\EndpointV2\EndpointV2SerializerTrait;
-
 
12
use Aws\EndpointV2\Ruleset\RulesetEndpoint;
13
use GuzzleHttp\Psr7;
13
use GuzzleHttp\Psr7;
14
use GuzzleHttp\Psr7\Request;
14
use GuzzleHttp\Psr7\Request;
15
use GuzzleHttp\Psr7\Uri;
15
use GuzzleHttp\Psr7\Uri;
16
use GuzzleHttp\Psr7\UriResolver;
16
use GuzzleHttp\Psr7\UriResolver;
17
use Psr\Http\Message\RequestInterface;
17
use Psr\Http\Message\RequestInterface;
Línea 40... Línea 40...
40
        $this->endpoint = Psr7\Utils::uriFor($endpoint);
40
        $this->endpoint = Psr7\Utils::uriFor($endpoint);
41
    }
41
    }
Línea 42... Línea 42...
42
 
42
 
43
    /**
43
    /**
44
     * @param CommandInterface $command Command to serialize into a request.
-
 
45
     * @param $endpointProvider Provider used for dynamic endpoint resolution.
44
     * @param CommandInterface $command Command to serialize into a request.
46
     * @param $clientArgs Client arguments used for dynamic endpoint resolution.
45
     * @param $clientArgs Client arguments used for dynamic endpoint resolution.
47
     *
46
     *
48
     * @return RequestInterface
47
     * @return RequestInterface
49
     */
48
     */
50
    public function __invoke(
49
    public function __invoke(
51
        CommandInterface $command,
50
        CommandInterface $command,
52
        $endpointProvider = null,
-
 
53
        $clientArgs = null
51
        $endpoint = null
54
    )
52
    )
55
    {
53
    {
56
        $operation = $this->api->getOperation($command->getName());
54
        $operation = $this->api->getOperation($command->getName());
57
        $commandArgs = $command->toArray();
55
        $commandArgs = $command->toArray();
58
        $opts = $this->serialize($operation, $commandArgs);
56
        $opts = $this->serialize($operation, $commandArgs);
Línea 59... Línea 57...
59
        $headers = isset($opts['headers']) ? $opts['headers'] : [];
57
        $headers = isset($opts['headers']) ? $opts['headers'] : [];
60
 
-
 
61
        if ($endpointProvider instanceof EndpointProviderV2) {
-
 
62
            $this->setRequestOptions(
-
 
63
                $endpointProvider,
-
 
64
                $command,
-
 
65
                $operation,
-
 
66
                $commandArgs,
-
 
67
                $clientArgs,
-
 
68
                $headers
58
 
69
            );
59
        if ($endpoint instanceof RulesetEndpoint) {
-
 
60
            $this->setEndpointV2RequestOptions($endpoint, $headers);
70
            $this->endpoint = new Uri($this->endpoint);
61
        }
Línea 71... Línea 62...
71
        }
62
 
72
        $uri = $this->buildEndpoint($operation, $commandArgs, $opts);
63
        $uri = $this->buildEndpoint($operation, $commandArgs, $opts);
73
 
64
 
Línea 203... Línea 194...
203
        }
194
        }
204
    }
195
    }
Línea 205... Línea 196...
205
 
196
 
206
    private function buildEndpoint(Operation $operation, array $args, array $opts)
197
    private function buildEndpoint(Operation $operation, array $args, array $opts)
-
 
198
    {
-
 
199
        $isModifiedModel = $this->api->isModifiedModel();
207
    {
200
        $serviceName = $this->api->getServiceName();
208
        // Create an associative array of variable definitions used in expansions
201
        // Create an associative array of variable definitions used in expansions
Línea 209... Línea 202...
209
        $varDefinitions = $this->getVarDefinitions($operation, $args);
202
        $varDefinitions = $this->getVarDefinitions($operation, $args);
210
 
203
 
Línea 231... Línea 224...
231
           $relative = $this->appendQuery($opts['query'], $relative);
224
           $relative = $this->appendQuery($opts['query'], $relative);
232
        }
225
        }
Línea 233... Línea 226...
233
 
226
 
Línea 234... Línea -...
234
        $path = $this->endpoint->getPath();
-
 
235
 
-
 
236
        //Accounts for trailing '/' in path when custom endpoint
-
 
237
        //is provided to endpointProviderV2
227
        $path = $this->endpoint->getPath();
238
        if ($this->api->isModifiedModel()
-
 
239
            && $this->api->getServiceName() === 's3'
228
 
240
        ) {
229
        if ($isModifiedModel && $serviceName === 's3') {
241
            if (substr($path, -1) === '/' && $relative[0] === '/') {
230
            if (substr($path, -1) === '/' && $relative[0] === '/') {
242
                $path = rtrim($path, '/');
231
                $path = rtrim($path, '/');
-
 
232
            }
-
 
233
            $relative = $path . $relative;
-
 
234
 
-
 
235
            if (strpos($relative, '../') !== false
-
 
236
                || substr($relative, -2) === '..'
-
 
237
            ) {
-
 
238
                if ($relative[0] !== '/') {
-
 
239
                    $relative = '/' . $relative;
-
 
240
                }
-
 
241
 
243
            }
242
                return new Uri($this->endpoint->withPath('') . $relative);
-
 
243
            }
-
 
244
        }
-
 
245
 
-
 
246
        if ((!empty($relative) && $relative !== '/')
-
 
247
            && !$isModifiedModel
-
 
248
            && $serviceName !== 's3'
-
 
249
        ) {
-
 
250
            $this->normalizePath($path);
244
            $relative = $path . $relative;
251
        }
245
        }
252
 
246
        // If endpoint has path, remove leading '/' to preserve URI resolution.
253
        // If endpoint has path, remove leading '/' to preserve URI resolution.
247
        if ($path && $relative[0] === '/') {
254
        if ($path && $relative[0] === '/') {
Línea 248... Línea 255...
248
            $relative = substr($relative, 1);
255
            $relative = substr($relative, 1);
249
        }
256
        }
250
 
-
 
251
        //Append path to endpoint when leading '//...' present
257
 
252
        // as uri cannot be properly resolved
-
 
253
        if ($this->api->isModifiedModel()
258
        //Append path to endpoint when leading '//...'
254
            && strpos($relative, '//') === 0
259
        // present as uri cannot be properly resolved
Línea 255... Línea 260...
255
        ) {
260
        if ($isModifiedModel && strpos($relative, '//') === 0) {
256
            return new Uri($this->endpoint . $relative);
261
            return new Uri($this->endpoint . $relative);
Línea 302... Línea 307...
302
                        : null;
307
                        : null;
303
            }
308
            }
304
        }
309
        }
305
        return $varDefinitions;
310
        return $varDefinitions;
306
    }
311
    }
-
 
312
 
-
 
313
    /**
-
 
314
     * Appends trailing slash to non-empty paths with at least one segment
-
 
315
     * to ensure proper URI resolution
-
 
316
     *
-
 
317
     * @param string $path
-
 
318
     *
-
 
319
     * @return void
-
 
320
     */
-
 
321
    private function normalizePath(string $path): void
-
 
322
    {
-
 
323
        if (!empty($path) && $path !== '/' && substr($path, -1) !== '/') {
-
 
324
            $this->endpoint = $this->endpoint->withPath($path . '/');
-
 
325
        }
-
 
326
    }
307
}
327
}