PluginProbe ʕ •ᴥ•ʔ
Transferito: WP Migration / trunk
Transferito: WP Migration vtrunk
trunk 11.4.0 12.0.0 13.1.0 14.0.0 14.0.11 14.0.7 14.1.0 14.1.1 14.1.2 14.1.3 14.1.4
transferito / vendor / aws / aws-sdk-php / src / functions.php
transferito / vendor / aws / aws-sdk-php / src Last commit date
ACMPCA 10 months ago ARCZonalShift 10 months ago AccessAnalyzer 10 months ago Account 10 months ago Acm 10 months ago AlexaForBusiness 10 months ago Amplify 10 months ago AmplifyBackend 10 months ago AmplifyUIBuilder 10 months ago Api 10 months ago ApiGateway 10 months ago ApiGatewayManagementApi 10 months ago ApiGatewayV2 10 months ago AppConfig 10 months ago AppConfigData 10 months ago AppFabric 10 months ago AppIntegrationsService 10 months ago AppMesh 10 months ago AppRegistry 10 months ago AppRunner 10 months ago AppSync 10 months ago Appflow 10 months ago ApplicationAutoScaling 10 months ago ApplicationCostProfiler 10 months ago ApplicationDiscoveryService 10 months ago ApplicationInsights 10 months ago Appstream 10 months ago Arn 10 months ago Athena 10 months ago AuditManager 10 months ago AugmentedAIRuntime 10 months ago AutoScaling 10 months ago AutoScalingPlans 10 months ago B2bi 10 months ago BCMDataExports 10 months ago Backup 10 months ago BackupGateway 10 months ago BackupStorage 10 months ago Batch 10 months ago Bedrock 10 months ago BedrockAgent 10 months ago BedrockAgentRuntime 10 months ago BedrockRuntime 10 months ago BillingConductor 10 months ago Braket 10 months ago Budgets 10 months ago Chime 10 months ago ChimeSDKIdentity 10 months ago ChimeSDKMediaPipelines 10 months ago ChimeSDKMeetings 10 months ago ChimeSDKMessaging 10 months ago ChimeSDKVoice 10 months ago CleanRooms 10 months ago CleanRoomsML 10 months ago ClientSideMonitoring 10 months ago Cloud9 10 months ago CloudControlApi 10 months ago CloudDirectory 10 months ago CloudFormation 10 months ago CloudFront 10 months ago CloudFrontKeyValueStore 10 months ago CloudHSMV2 10 months ago CloudHsm 10 months ago CloudSearch 10 months ago CloudSearchDomain 10 months ago CloudTrail 10 months ago CloudTrailData 10 months ago CloudWatch 10 months ago CloudWatchEvents 10 months ago CloudWatchEvidently 10 months ago CloudWatchLogs 10 months ago CloudWatchRUM 10 months ago CodeArtifact 10 months ago CodeBuild 10 months ago CodeCatalyst 10 months ago CodeCommit 10 months ago CodeDeploy 10 months ago CodeGuruProfiler 10 months ago CodeGuruReviewer 10 months ago CodeGuruSecurity 10 months ago CodePipeline 10 months ago CodeStar 10 months ago CodeStarNotifications 10 months ago CodeStarconnections 10 months ago CognitoIdentity 10 months ago CognitoIdentityProvider 10 months ago CognitoSync 10 months ago Comprehend 10 months ago ComprehendMedical 10 months ago ComputeOptimizer 10 months ago ConfigService 10 months ago Configuration 10 months ago Connect 10 months ago ConnectCampaignService 10 months ago ConnectCases 10 months ago ConnectContactLens 10 months ago ConnectParticipant 10 months ago ConnectWisdomService 10 months ago ControlTower 10 months ago CostExplorer 10 months ago CostOptimizationHub 10 months ago CostandUsageReportService 10 months ago Credentials 10 months ago Crypto 10 months ago CustomerProfiles 10 months ago DAX 10 months ago DLM 10 months ago DataExchange 10 months ago DataPipeline 10 months ago DataSync 10 months ago DataZone 10 months ago DatabaseMigrationService 10 months ago DefaultsMode 10 months ago Detective 10 months ago DevOpsGuru 10 months ago DeviceFarm 10 months ago DirectConnect 10 months ago DirectoryService 10 months ago DocDB 10 months ago DocDBElastic 10 months ago DynamoDb 10 months ago DynamoDbStreams 10 months ago EBS 10 months ago EC2InstanceConnect 10 months ago ECRPublic 10 months ago EKS 10 months ago EKSAuth 10 months ago EMRContainers 10 months ago EMRServerless 10 months ago Ec2 10 months ago Ecr 10 months ago Ecs 10 months ago Efs 10 months ago ElastiCache 10 months ago ElasticBeanstalk 10 months ago ElasticInference 10 months ago ElasticLoadBalancing 10 months ago ElasticLoadBalancingV2 10 months ago ElasticTranscoder 10 months ago ElasticsearchService 10 months ago Emr 10 months ago Endpoint 10 months ago EndpointDiscovery 10 months ago EndpointV2 10 months ago EntityResolution 10 months ago EventBridge 10 months ago Exception 10 months ago FIS 10 months ago FMS 10 months ago FSx 10 months ago FinSpaceData 10 months ago Firehose 10 months ago ForecastQueryService 10 months ago ForecastService 10 months ago FraudDetector 10 months ago FreeTier 10 months ago GameLift 10 months ago Glacier 10 months ago GlobalAccelerator 10 months ago Glue 10 months ago GlueDataBrew 10 months ago Greengrass 10 months ago GreengrassV2 10 months ago GroundStation 10 months ago GuardDuty 10 months ago Handler 10 months ago Health 10 months ago HealthLake 10 months ago Honeycode 10 months ago IVS 10 months ago IVSRealTime 10 months ago Iam 10 months ago Identity 10 months ago IdentityStore 10 months ago ImportExport 10 months ago Inspector 10 months ago Inspector2 10 months ago InspectorScan 10 months ago InternetMonitor 10 months ago IoT1ClickDevicesService 10 months ago IoT1ClickProjects 10 months ago IoTAnalytics 10 months ago IoTDeviceAdvisor 10 months ago IoTEvents 10 months ago IoTEventsData 10 months ago IoTFleetHub 10 months ago IoTFleetWise 10 months ago IoTJobsDataPlane 10 months ago IoTRoboRunner 10 months ago IoTSecureTunneling 10 months ago IoTSiteWise 10 months ago IoTThingsGraph 10 months ago IoTTwinMaker 10 months ago IoTWireless 10 months ago Iot 10 months ago IotDataPlane 10 months ago Kafka 10 months ago KafkaConnect 10 months ago KendraRanking 10 months ago Keyspaces 10 months ago Kinesis 10 months ago KinesisAnalytics 10 months ago KinesisAnalyticsV2 10 months ago KinesisVideo 10 months ago KinesisVideoArchivedMedia 10 months ago KinesisVideoMedia 10 months ago KinesisVideoSignalingChannels 10 months ago KinesisVideoWebRTCStorage 10 months ago Kms 10 months ago LakeFormation 10 months ago Lambda 10 months ago LaunchWizard 10 months ago LexModelBuildingService 10 months ago LexModelsV2 10 months ago LexRuntimeService 10 months ago LexRuntimeV2 10 months ago LicenseManager 10 months ago LicenseManagerLinuxSubscriptions 10 months ago LicenseManagerUserSubscriptions 10 months ago Lightsail 10 months ago LocationService 10 months ago LookoutEquipment 10 months ago LookoutMetrics 10 months ago LookoutforVision 10 months ago MQ 10 months ago MTurk 10 months ago MWAA 10 months ago MachineLearning 10 months ago Macie2 10 months ago MainframeModernization 10 months ago ManagedBlockchain 10 months ago ManagedBlockchainQuery 10 months ago ManagedGrafana 10 months ago MarketplaceAgreement 10 months ago MarketplaceCatalog 10 months ago MarketplaceCommerceAnalytics 10 months ago MarketplaceDeployment 10 months ago MarketplaceEntitlementService 10 months ago MarketplaceMetering 10 months ago MediaConnect 10 months ago MediaConvert 10 months ago MediaLive 10 months ago MediaPackage 10 months ago MediaPackageV2 10 months ago MediaPackageVod 10 months ago MediaStore 10 months ago MediaStoreData 10 months ago MediaTailor 10 months ago MedicalImaging 10 months ago MemoryDB 10 months ago MigrationHub 10 months ago MigrationHubConfig 10 months ago MigrationHubOrchestrator 10 months ago MigrationHubRefactorSpaces 10 months ago MigrationHubStrategyRecommendations 10 months ago Mobile 10 months ago Multipart 10 months ago Neptune 10 months ago Neptunedata 10 months ago NetworkFirewall 10 months ago NetworkManager 10 months ago NimbleStudio 10 months ago OAM 10 months ago OSIS 10 months ago Omics 10 months ago OpenSearchServerless 10 months ago OpenSearchService 10 months ago OpsWorks 10 months ago OpsWorksCM 10 months ago Organizations 10 months ago Outposts 10 months ago PI 10 months ago Panorama 10 months ago PaymentCryptography 10 months ago PaymentCryptographyData 10 months ago PcaConnectorAd 10 months ago Personalize 10 months ago PersonalizeEvents 10 months ago PersonalizeRuntime 10 months ago Pinpoint 10 months ago PinpointEmail 10 months ago PinpointSMSVoice 10 months ago PinpointSMSVoiceV2 10 months ago Pipes 10 months ago Polly 10 months ago Pricing 10 months ago PrivateNetworks 10 months ago PrometheusService 10 months ago Proton 10 months ago QBusiness 10 months ago QConnect 10 months ago QLDB 10 months ago QLDBSession 10 months ago QuickSight 10 months ago RAM 10 months ago RDSDataService 10 months ago Rds 10 months ago RecycleBin 10 months ago Redshift 10 months ago RedshiftDataAPIService 10 months ago RedshiftServerless 10 months ago Rekognition 10 months ago Repostspace 10 months ago ResilienceHub 10 months ago ResourceExplorer2 10 months ago ResourceGroups 10 months ago ResourceGroupsTaggingAPI 10 months ago Retry 10 months ago RoboMaker 10 months ago RolesAnywhere 10 months ago Route53 10 months ago Route53Domains 10 months ago Route53RecoveryCluster 10 months ago Route53RecoveryControlConfig 10 months ago Route53RecoveryReadiness 10 months ago Route53Resolver 10 months ago S3 10 months ago S3Control 10 months ago S3Outposts 10 months ago SSMContacts 10 months ago SSMIncidents 10 months ago SSO 10 months ago SSOAdmin 10 months ago SSOOIDC 10 months ago SageMaker 10 months ago SageMakerFeatureStoreRuntime 10 months ago SageMakerGeospatial 10 months ago SageMakerMetrics 10 months ago SageMakerRuntime 10 months ago SagemakerEdgeManager 10 months ago SavingsPlans 10 months ago Scheduler 10 months ago Schemas 10 months ago Script 10 months ago SecretsManager 10 months ago SecurityHub 10 months ago SecurityLake 10 months ago ServerlessApplicationRepository 10 months ago ServiceCatalog 10 months ago ServiceDiscovery 10 months ago ServiceQuotas 10 months ago Ses 10 months ago SesV2 10 months ago Sfn 10 months ago Shield 10 months ago Signature 10 months ago SimSpaceWeaver 10 months ago Sms 10 months ago SnowBall 10 months ago SnowDeviceManagement 10 months ago Sns 10 months ago Sqs 10 months ago Ssm 10 months ago SsmSap 10 months ago StorageGateway 10 months ago Sts 10 months ago Support 10 months ago SupportApp 10 months ago Swf 10 months ago Synthetics 10 months ago Textract 10 months ago TimestreamQuery 10 months ago TimestreamWrite 10 months ago Tnb 10 months ago Token 10 months ago TranscribeService 10 months ago Transfer 10 months ago Translate 10 months ago TrustedAdvisor 10 months ago VPCLattice 10 months ago VerifiedPermissions 10 months ago VoiceID 10 months ago WAFV2 10 months ago Waf 10 months ago WafRegional 10 months ago WellArchitected 10 months ago WorkDocs 10 months ago WorkLink 10 months ago WorkMail 10 months ago WorkMailMessageFlow 10 months ago WorkSpaces 10 months ago WorkSpacesThinClient 10 months ago WorkSpacesWeb 10 months ago XRay 10 months ago data 10 months ago drs 10 months ago finspace 10 months ago imagebuilder 10 months ago ivschat 10 months ago kendra 10 months ago mgn 10 months ago signer 10 months ago AbstractConfigurationProvider.php 10 months ago AwsClient.php 10 months ago AwsClientInterface.php 10 months ago AwsClientTrait.php 10 months ago CacheInterface.php 10 months ago ClientResolver.php 10 months ago Command.php 10 months ago CommandInterface.php 10 months ago CommandPool.php 10 months ago ConfigurationProviderInterface.php 10 months ago DoctrineCacheAdapter.php 10 months ago EndpointParameterMiddleware.php 10 months ago HandlerList.php 10 months ago HasDataTrait.php 10 months ago HasMonitoringEventsTrait.php 10 months ago HashInterface.php 10 months ago HashingStream.php 10 months ago History.php 10 months ago IdempotencyTokenMiddleware.php 10 months ago InputValidationMiddleware.php 10 months ago JsonCompiler.php 10 months ago LruArrayCache.php 10 months ago Middleware.php 10 months ago MockHandler.php 10 months ago MonitoringEventsInterface.php 10 months ago MultiRegionClient.php 10 months ago PhpHash.php 10 months ago PresignUrlMiddleware.php 10 months ago Psr16CacheAdapter.php 10 months ago PsrCacheAdapter.php 10 months ago QueryCompatibleInputMiddleware.php 10 months ago RequestCompressionMiddleware.php 10 months ago ResponseContainerInterface.php 10 months ago Result.php 10 months ago ResultInterface.php 10 months ago ResultPaginator.php 10 months ago RetryMiddleware.php 10 months ago RetryMiddlewareV2.php 10 months ago Sdk.php 10 months ago StreamRequestPayloadMiddleware.php 10 months ago TraceMiddleware.php 10 months ago Waiter.php 10 months ago WrappedHttpHandler.php 10 months ago functions.php 10 months ago
functions.php
606 lines
1 <?php
2 namespace Aws;
3
4 use GuzzleHttp\Client;
5 use Psr\Http\Message\RequestInterface;
6 use GuzzleHttp\ClientInterface;
7 use GuzzleHttp\Promise\FulfilledPromise;
8
9 //-----------------------------------------------------------------------------
10 // Functional functions
11 //-----------------------------------------------------------------------------
12
13 /**
14 * Returns a function that always returns the same value;
15 *
16 * @param mixed $value Value to return.
17 *
18 * @return callable
19 */
20 function constantly($value)
21 {
22 return function () use ($value) { return $value; };
23 }
24
25 /**
26 * Filters values that do not satisfy the predicate function $pred.
27 *
28 * @param mixed $iterable Iterable sequence of data.
29 * @param callable $pred Function that accepts a value and returns true/false
30 *
31 * @return \Generator
32 */
33 function filter($iterable, callable $pred)
34 {
35 foreach ($iterable as $value) {
36 if ($pred($value)) {
37 yield $value;
38 }
39 }
40 }
41
42 /**
43 * Applies a map function $f to each value in a collection.
44 *
45 * @param mixed $iterable Iterable sequence of data.
46 * @param callable $f Map function to apply.
47 *
48 * @return \Generator
49 */
50 function map($iterable, callable $f)
51 {
52 foreach ($iterable as $value) {
53 yield $f($value);
54 }
55 }
56
57 /**
58 * Creates a generator that iterates over a sequence, then iterates over each
59 * value in the sequence and yields the application of the map function to each
60 * value.
61 *
62 * @param mixed $iterable Iterable sequence of data.
63 * @param callable $f Map function to apply.
64 *
65 * @return \Generator
66 */
67 function flatmap($iterable, callable $f)
68 {
69 foreach (map($iterable, $f) as $outer) {
70 foreach ($outer as $inner) {
71 yield $inner;
72 }
73 }
74 }
75
76 /**
77 * Partitions the input sequence into partitions of the specified size.
78 *
79 * @param mixed $iterable Iterable sequence of data.
80 * @param int $size Size to make each partition (except possibly the last chunk)
81 *
82 * @return \Generator
83 */
84 function partition($iterable, $size)
85 {
86 $buffer = [];
87 foreach ($iterable as $value) {
88 $buffer[] = $value;
89 if (count($buffer) === $size) {
90 yield $buffer;
91 $buffer = [];
92 }
93 }
94
95 if ($buffer) {
96 yield $buffer;
97 }
98 }
99
100 /**
101 * Returns a function that invokes the provided variadic functions one
102 * after the other until one of the functions returns a non-null value.
103 * The return function will call each passed function with any arguments it
104 * is provided.
105 *
106 * $a = function ($x, $y) { return null; };
107 * $b = function ($x, $y) { return $x + $y; };
108 * $fn = \Aws\or_chain($a, $b);
109 * echo $fn(1, 2); // 3
110 *
111 * @return callable
112 */
113 function or_chain()
114 {
115 $fns = func_get_args();
116 return function () use ($fns) {
117 $args = func_get_args();
118 foreach ($fns as $fn) {
119 $result = $args ? call_user_func_array($fn, $args) : $fn();
120 if ($result) {
121 return $result;
122 }
123 }
124 return null;
125 };
126 }
127
128 //-----------------------------------------------------------------------------
129 // JSON compiler and loading functions
130 //-----------------------------------------------------------------------------
131
132 /**
133 * Loads a compiled JSON file from a PHP file.
134 *
135 * If the JSON file has not been cached to disk as a PHP file, it will be loaded
136 * from the JSON source file and returned.
137 *
138 * @param string $path Path to the JSON file on disk
139 *
140 * @return mixed Returns the JSON decoded data. Note that JSON objects are
141 * decoded as associative arrays.
142 */
143 function load_compiled_json($path)
144 {
145 static $compiledList = [];
146
147 $compiledFilepath = "{$path}.php";
148
149 if (!isset($compiledList[$compiledFilepath])) {
150 if (is_readable($compiledFilepath)) {
151 $compiledList[$compiledFilepath] = include($compiledFilepath);
152 }
153 }
154
155 if (isset($compiledList[$compiledFilepath])) {
156 return $compiledList[$compiledFilepath];
157 }
158
159 if (!file_exists($path)) {
160 throw new \InvalidArgumentException(
161 sprintf("File not found: %s", $path)
162 );
163 }
164
165 return json_decode(file_get_contents($path), true);
166 }
167
168 /**
169 * No-op
170 */
171 function clear_compiled_json()
172 {
173 // pass
174 }
175
176 //-----------------------------------------------------------------------------
177 // Directory iterator functions.
178 //-----------------------------------------------------------------------------
179
180 /**
181 * Iterates over the files in a directory and works with custom wrappers.
182 *
183 * @param string $path Path to open (e.g., "s3://foo/bar").
184 * @param resource $context Stream wrapper context.
185 *
186 * @return \Generator Yields relative filename strings.
187 */
188 function dir_iterator($path, $context = null)
189 {
190 $dh = $context ? opendir($path, $context) : opendir($path);
191 if (!$dh) {
192 throw new \InvalidArgumentException('File not found: ' . $path);
193 }
194 while (($file = readdir($dh)) !== false) {
195 yield $file;
196 }
197 closedir($dh);
198 }
199
200 /**
201 * Returns a recursive directory iterator that yields absolute filenames.
202 *
203 * This iterator is not broken like PHP's built-in DirectoryIterator (which
204 * will read the first file from a stream wrapper, then rewind, then read
205 * it again).
206 *
207 * @param string $path Path to traverse (e.g., s3://bucket/key, /tmp)
208 * @param resource $context Stream context options.
209 *
210 * @return \Generator Yields absolute filenames.
211 */
212 function recursive_dir_iterator($path, $context = null)
213 {
214 $invalid = ['.' => true, '..' => true];
215 $pathLen = strlen($path) + 1;
216 $iterator = dir_iterator($path, $context);
217 $queue = [];
218 do {
219 while ($iterator->valid()) {
220 $file = $iterator->current();
221 $iterator->next();
222 if (isset($invalid[basename($file)])) {
223 continue;
224 }
225 $fullPath = "{$path}/{$file}";
226 yield $fullPath;
227 if (is_dir($fullPath)) {
228 $queue[] = $iterator;
229 $iterator = map(
230 dir_iterator($fullPath, $context),
231 function ($file) use ($fullPath, $pathLen) {
232 return substr("{$fullPath}/{$file}", $pathLen);
233 }
234 );
235 continue;
236 }
237 }
238 $iterator = array_pop($queue);
239 } while ($iterator);
240 }
241
242 //-----------------------------------------------------------------------------
243 // Misc. functions.
244 //-----------------------------------------------------------------------------
245
246 /**
247 * Debug function used to describe the provided value type and class.
248 *
249 * @param mixed $input
250 *
251 * @return string Returns a string containing the type of the variable and
252 * if a class is provided, the class name.
253 */
254 function describe_type($input)
255 {
256 switch (gettype($input)) {
257 case 'object':
258 return 'object(' . get_class($input) . ')';
259 case 'array':
260 return 'array(' . count($input) . ')';
261 default:
262 ob_start();
263 var_dump($input);
264 // normalize float vs double
265 return str_replace('double(', 'float(', rtrim(ob_get_clean()));
266 }
267 }
268
269 /**
270 * Creates a default HTTP handler based on the available clients.
271 *
272 * @return callable
273 */
274 function default_http_handler()
275 {
276 $version = guzzle_major_version();
277 // If Guzzle 6 or 7 installed
278 if ($version === 6 || $version === 7) {
279 return new \Aws\Handler\GuzzleV6\GuzzleHandler();
280 }
281
282 // If Guzzle 5 installed
283 if ($version === 5) {
284 return new \Aws\Handler\GuzzleV5\GuzzleHandler();
285 }
286
287 throw new \RuntimeException('Unknown Guzzle version: ' . $version);
288 }
289
290 /**
291 * Gets the default user agent string depending on the Guzzle version
292 *
293 * @return string
294 */
295 function default_user_agent()
296 {
297 $version = guzzle_major_version();
298 // If Guzzle 6 or 7 installed
299 if ($version === 6 || $version === 7) {
300 return \GuzzleHttp\default_user_agent();
301 }
302
303 // If Guzzle 5 installed
304 if ($version === 5) {
305 return \GuzzleHttp\Client::getDefaultUserAgent();
306 }
307
308 throw new \RuntimeException('Unknown Guzzle version: ' . $version);
309 }
310
311 /**
312 * Get the major version of guzzle that is installed.
313 *
314 * @internal This function is internal and should not be used outside aws/aws-sdk-php.
315 * @return int
316 * @throws \RuntimeException
317 */
318 function guzzle_major_version()
319 {
320 static $cache = null;
321 if (null !== $cache) {
322 return $cache;
323 }
324
325 if (defined('\GuzzleHttp\ClientInterface::VERSION')) {
326 $version = (string) ClientInterface::VERSION;
327 if ($version[0] === '6') {
328 return $cache = 6;
329 }
330 if ($version[0] === '5') {
331 return $cache = 5;
332 }
333 } elseif (defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')) {
334 return $cache = ClientInterface::MAJOR_VERSION;
335 }
336
337 throw new \RuntimeException('Unable to determine what Guzzle version is installed.');
338 }
339
340 /**
341 * Serialize a request for a command but do not send it.
342 *
343 * Returns a promise that is fulfilled with the serialized request.
344 *
345 * @param CommandInterface $command Command to serialize.
346 *
347 * @return RequestInterface
348 * @throws \RuntimeException
349 */
350 function serialize(CommandInterface $command)
351 {
352 $request = null;
353 $handlerList = $command->getHandlerList();
354
355 // Return a mock result.
356 $handlerList->setHandler(
357 function (CommandInterface $_, RequestInterface $r) use (&$request) {
358 $request = $r;
359 return new FulfilledPromise(new Result([]));
360 }
361 );
362
363 call_user_func($handlerList->resolve(), $command)->wait();
364 if (!$request instanceof RequestInterface) {
365 throw new \RuntimeException(
366 'Calling handler did not serialize request'
367 );
368 }
369
370 return $request;
371 }
372
373 /**
374 * Retrieves data for a service from the SDK's service manifest file.
375 *
376 * Manifest data is stored statically, so it does not need to be loaded more
377 * than once per process. The JSON data is also cached in opcache.
378 *
379 * @param string $service Case-insensitive namespace or endpoint prefix of the
380 * service for which you are retrieving manifest data.
381 *
382 * @return array
383 * @throws \InvalidArgumentException if the service is not supported.
384 */
385 function manifest($service = null)
386 {
387 // Load the manifest and create aliases for lowercased namespaces
388 static $manifest = [];
389 static $aliases = [];
390 if (empty($manifest)) {
391 $manifest = load_compiled_json(__DIR__ . '/data/manifest.json');
392 foreach ($manifest as $endpoint => $info) {
393 $alias = strtolower($info['namespace']);
394 if ($alias !== $endpoint) {
395 $aliases[$alias] = $endpoint;
396 }
397 }
398 }
399
400 // If no service specified, then return the whole manifest.
401 if ($service === null) {
402 return $manifest;
403 }
404
405 // Look up the service's info in the manifest data.
406 $service = strtolower($service);
407 if (isset($manifest[$service])) {
408 return $manifest[$service] + ['endpoint' => $service];
409 }
410
411 if (isset($aliases[$service])) {
412 return manifest($aliases[$service]);
413 }
414
415 throw new \InvalidArgumentException(
416 "The service \"{$service}\" is not provided by the AWS SDK for PHP."
417 );
418 }
419
420 /**
421 * Checks if supplied parameter is a valid hostname
422 *
423 * @param string $hostname
424 * @return bool
425 */
426 function is_valid_hostname($hostname)
427 {
428 return (
429 preg_match("/^([a-z\d](-*[a-z\d])*)(\.([a-z\d](-*[a-z\d])*))*\.?$/i", $hostname)
430 && preg_match("/^.{1,253}$/", $hostname)
431 && preg_match("/^[^\.]{1,63}(\.[^\.]{0,63})*$/", $hostname)
432 );
433 }
434
435 /**
436 * Checks if supplied parameter is a valid host label
437 *
438 * @param $label
439 * @return bool
440 */
441 function is_valid_hostlabel($label)
442 {
443 return preg_match("/^(?!-)[a-zA-Z0-9-]{1,63}(?<!-)$/", $label);
444 }
445
446 /**
447 * Ignores '#' full line comments, which parse_ini_file no longer does
448 * in PHP 7+.
449 *
450 * @param $filename
451 * @param bool $process_sections
452 * @param int $scanner_mode
453 * @return array|bool
454 */
455 function parse_ini_file(
456 $filename,
457 $process_sections = false,
458 $scanner_mode = INI_SCANNER_NORMAL)
459 {
460 return parse_ini_string(
461 preg_replace('/^#.*\\n/m', "", file_get_contents($filename)),
462 $process_sections,
463 $scanner_mode
464 );
465 }
466
467 /**
468 * Outputs boolean value of input for a select range of possible values,
469 * null otherwise
470 *
471 * @param $input
472 * @return bool|null
473 */
474 function boolean_value($input)
475 {
476 if (is_bool($input)) {
477 return $input;
478 }
479
480 if ($input === 0) {
481 return false;
482 }
483
484 if ($input === 1) {
485 return true;
486 }
487
488 if (is_string($input)) {
489 switch (strtolower($input)) {
490 case "true":
491 case "on":
492 case "1":
493 return true;
494 break;
495
496 case "false":
497 case "off":
498 case "0":
499 return false;
500 break;
501 }
502 }
503 return null;
504 }
505
506 /**
507 * Parses ini sections with subsections (i.e. the service section)
508 *
509 * @param $filename
510 * @param $filename
511 * @return array
512 */
513 function parse_ini_section_with_subsections($filename, $section_name) {
514 $config = [];
515 $stream = fopen($filename, 'r');
516
517 if (!$stream) {
518 return $config;
519 }
520
521 $current_subsection = '';
522
523 while (!feof($stream)) {
524 $line = trim(fgets($stream));
525
526 if (empty($line) || in_array($line[0], [';', '#'])) {
527 continue;
528 }
529
530 if (preg_match('/^\[.*\]$/', $line)
531 && trim($line, '[]') === $section_name)
532 {
533 while (!feof($stream)) {
534 $line = trim(fgets($stream));
535
536 if (empty($line) || in_array($line[0], [';', '#'])) {
537 continue;
538 }
539
540 if (preg_match('/^\[.*\]$/', $line)
541 && trim($line, '[]') === $section_name)
542 {
543 continue;
544 } elseif (strpos($line, '[') === 0) {
545 break;
546 }
547
548 if (strpos($line, ' = ') !== false) {
549 list($key, $value) = explode(' = ', $line, 2);
550 if (empty($current_subsection)) {
551 $config[$key] = $value;
552 } else {
553 $config[$current_subsection][$key] = $value;
554 }
555 } else {
556 $current_subsection = trim(str_replace('=', '', $line));
557 $config[$current_subsection] = [];
558 }
559 }
560 }
561 }
562
563 fclose($stream);
564 return $config;
565 }
566
567 /**
568 * Checks if an input is a valid epoch time
569 *
570 * @param $input
571 * @return bool
572 */
573 function is_valid_epoch($input)
574 {
575 if (is_string($input) || is_numeric($input)) {
576 if (is_string($input) && !preg_match("/^-?[0-9]+\.?[0-9]*$/", $input)) {
577 return false;
578 }
579 return true;
580 }
581 return false;
582 }
583
584 /**
585 * Checks if an input is a fips pseudo region
586 *
587 * @param $region
588 * @return bool
589 */
590 function is_fips_pseudo_region($region)
591 {
592 return strpos($region, 'fips-') !== false || strpos($region, '-fips') !== false;
593 }
594
595 /**
596 * Returns a region without a fips label
597 *
598 * @param $region
599 * @return string
600 */
601 function strip_fips_pseudo_regions($region)
602 {
603 return str_replace(['fips-', '-fips'], ['', ''], $region);
604 }
605
606