installed plugin Infinite Uploads version 2.0.8

This commit is contained in:
2025-05-02 12:03:21 +00:00
committed by Gitium
parent 7ca941b591
commit 8fefb19ab4
1179 changed files with 99739 additions and 0 deletions

View File

@ -0,0 +1,55 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Arn;
use UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException;
/**
* @internal
*/
class AccessPointArn extends \UglyRobot\Infinite_Uploads\Aws\Arn\Arn implements \UglyRobot\Infinite_Uploads\Aws\Arn\AccessPointArnInterface
{
use ResourceTypeAndIdTrait;
/**
* AccessPointArn constructor
*
* @param $data
*/
public function __construct($data)
{
parent::__construct($data);
static::validate($this->data);
}
public static function parse($string)
{
$data = parent::parse($string);
$data = self::parseResourceTypeAndId($data);
$data['accesspoint_name'] = $data['resource_id'];
return $data;
}
public function getAccesspointName()
{
return $this->data['accesspoint_name'];
}
/**
* Validation specific to AccessPointArn
*
* @param array $data
*/
protected static function validate(array $data)
{
self::validateRegion($data, 'access point ARN');
self::validateAccountId($data, 'access point ARN');
if ($data['resource_type'] !== 'accesspoint') {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 6th component of an access point ARN" . " represents the resource type and must be 'accesspoint'.");
}
if (empty($data['resource_id'])) {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 7th component of an access point ARN" . " represents the resource ID and must not be empty.");
}
if (strpos($data['resource_id'], ':') !== false) {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The resource ID component of an access" . " point ARN must not contain additional components" . " (delimited by ':').");
}
if (!self::isValidHostLabel($data['resource_id'])) {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The resource ID in an access point ARN" . " must be a valid host label value.");
}
}
}

View File

@ -0,0 +1,11 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Arn;
/**
* @internal
*/
interface AccessPointArnInterface extends ArnInterface
{
public function getAccesspointName();
}

View File

@ -0,0 +1,140 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Arn;
use UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException;
/**
* Amazon Resource Names (ARNs) uniquely identify AWS resources. The Arn class
* parses and stores a generic ARN object representation that can apply to any
* service resource.
*
* @internal
*/
class Arn implements \UglyRobot\Infinite_Uploads\Aws\Arn\ArnInterface
{
protected $data;
protected $string;
public static function parse($string)
{
$data = ['arn' => null, 'partition' => null, 'service' => null, 'region' => null, 'account_id' => null, 'resource' => null];
$length = strlen($string);
$lastDelim = 0;
$numComponents = 0;
for ($i = 0; $i < $length; $i++) {
if ($numComponents < 5 && $string[$i] === ':') {
// Split components between delimiters
$data[key($data)] = substr($string, $lastDelim, $i - $lastDelim);
// Do not include delimiter character itself
$lastDelim = $i + 1;
next($data);
$numComponents++;
}
if ($i === $length - 1) {
// Put the remainder in the last component.
if (in_array($numComponents, [5])) {
$data['resource'] = substr($string, $lastDelim);
} else {
// If there are < 5 components, put remainder in current
// component.
$data[key($data)] = substr($string, $lastDelim);
}
}
}
return $data;
}
public function __construct($data)
{
if (is_array($data)) {
$this->data = $data;
} elseif (is_string($data)) {
$this->data = static::parse($data);
} else {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException('Constructor accepts a string or an' . ' array as an argument.');
}
static::validate($this->data);
}
public function __toString()
{
if (!isset($this->string)) {
$components = [$this->getPrefix(), $this->getPartition(), $this->getService(), $this->getRegion(), $this->getAccountId(), $this->getResource()];
$this->string = implode(':', $components);
}
return $this->string;
}
public function getPrefix()
{
return $this->data['arn'];
}
public function getPartition()
{
return $this->data['partition'];
}
public function getService()
{
return $this->data['service'];
}
public function getRegion()
{
return $this->data['region'];
}
public function getAccountId()
{
return $this->data['account_id'];
}
public function getResource()
{
return $this->data['resource'];
}
public function toArray()
{
return $this->data;
}
/**
* Minimally restrictive generic ARN validation
*
* @param array $data
*/
protected static function validate(array $data)
{
if ($data['arn'] !== 'arn') {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 1st component of an ARN must be" . " 'arn'.");
}
if (empty($data['partition'])) {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 2nd component of an ARN" . " represents the partition and must not be empty.");
}
if (empty($data['service'])) {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 3rd component of an ARN" . " represents the service and must not be empty.");
}
if (empty($data['resource'])) {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 6th component of an ARN" . " represents the resource information and must not be empty." . " Individual service ARNs may include additional delimiters" . " to further qualify resources.");
}
}
protected static function validateAccountId($data, $arnName)
{
if (!self::isValidHostLabel($data['account_id'])) {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 5th component of a {$arnName}" . " is required, represents the account ID, and" . " must be a valid host label.");
}
}
protected static function validateRegion($data, $arnName)
{
if (empty($data['region'])) {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 4th component of a {$arnName}" . " represents the region and must not be empty.");
}
}
/**
* Validates whether a string component is a valid host label
*
* @param $string
* @return bool
*/
protected static function isValidHostLabel($string)
{
if (empty($string) || strlen($string) > 63) {
return false;
}
if ($value = preg_match("/^[a-zA-Z0-9-]+\$/", $string)) {
return true;
}
return false;
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Arn;
/**
* Amazon Resource Names (ARNs) uniquely identify AWS resources. Classes
* implementing ArnInterface parse and store an ARN object representation.
*
* Valid ARN formats include:
*
* arn:partition:service:region:account-id:resource-id
* arn:partition:service:region:account-id:resource-type/resource-id
* arn:partition:service:region:account-id:resource-type:resource-id
*
* Some components may be omitted, depending on the service and resource type.
*
* @internal
*/
interface ArnInterface
{
public static function parse($string);
public function __toString();
public function getPrefix();
public function getPartition();
public function getService();
public function getRegion();
public function getAccountId();
public function getResource();
public function toArray();
}

View File

@ -0,0 +1,58 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Arn;
use UglyRobot\Infinite_Uploads\Aws\Arn\S3\AccessPointArn as S3AccessPointArn;
use UglyRobot\Infinite_Uploads\Aws\Arn\S3\OutpostsBucketArn;
use UglyRobot\Infinite_Uploads\Aws\Arn\S3\RegionalBucketArn;
use UglyRobot\Infinite_Uploads\Aws\Arn\S3\OutpostsAccessPointArn;
/**
* This class provides functionality to parse ARN strings and return a
* corresponding ARN object. ARN-parsing logic may be subject to change in the
* future, so this should not be relied upon for external customer usage.
*
* @internal
*/
class ArnParser
{
/**
* @param $string
* @return bool
*/
public static function isArn($string)
{
return strpos($string, 'arn:') === 0;
}
/**
* Parses a string and returns an instance of ArnInterface. Returns a
* specific type of Arn object if it has a specific class representation
* or a generic Arn object if not.
*
* @param $string
* @return ArnInterface
*/
public static function parse($string)
{
$data = \UglyRobot\Infinite_Uploads\Aws\Arn\Arn::parse($string);
$resource = self::explodeResourceComponent($data['resource']);
if ($resource[0] === 'outpost') {
if (isset($resource[2]) && $resource[2] === 'bucket') {
return new \UglyRobot\Infinite_Uploads\Aws\Arn\S3\OutpostsBucketArn($string);
}
if (isset($resource[2]) && $resource[2] === 'accesspoint') {
return new \UglyRobot\Infinite_Uploads\Aws\Arn\S3\OutpostsAccessPointArn($string);
}
}
if ($resource[0] === 'accesspoint') {
if ($data['service'] === 's3') {
return new \UglyRobot\Infinite_Uploads\Aws\Arn\S3\AccessPointArn($string);
}
return new \UglyRobot\Infinite_Uploads\Aws\Arn\AccessPointArn($string);
}
return new \UglyRobot\Infinite_Uploads\Aws\Arn\Arn($data);
}
private static function explodeResourceComponent($resource)
{
return preg_split("/[\\/:]/", $resource);
}
}

View File

@ -0,0 +1,10 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Arn\Exception;
/**
* Represents a failed attempt to construct an Arn
*/
class InvalidArnException extends \RuntimeException
{
}

View File

@ -0,0 +1,25 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Arn;
/**
* @internal
*/
trait ResourceTypeAndIdTrait
{
public function getResourceType()
{
return $this->data['resource_type'];
}
public function getResourceId()
{
return $this->data['resource_id'];
}
private static function parseResourceTypeAndId(array $data)
{
$resourceData = preg_split("/[\\/:]/", $data['resource'], 2);
$data['resource_type'] = isset($resourceData[0]) ? $resourceData[0] : null;
$data['resource_id'] = isset($resourceData[1]) ? $resourceData[1] : null;
return $data;
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Arn\S3;
use UglyRobot\Infinite_Uploads\Aws\Arn\AccessPointArn as BaseAccessPointArn;
use UglyRobot\Infinite_Uploads\Aws\Arn\AccessPointArnInterface;
use UglyRobot\Infinite_Uploads\Aws\Arn\ArnInterface;
use UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException;
/**
* @internal
*/
class AccessPointArn extends \UglyRobot\Infinite_Uploads\Aws\Arn\AccessPointArn implements \UglyRobot\Infinite_Uploads\Aws\Arn\AccessPointArnInterface
{
/**
* Validation specific to AccessPointArn
*
* @param array $data
*/
protected static function validate(array $data)
{
parent::validate($data);
if ($data['service'] !== 's3') {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 3rd component of an S3 access" . " point ARN represents the region and must be 's3'.");
}
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Arn\S3;
use UglyRobot\Infinite_Uploads\Aws\Arn\ArnInterface;
/**
* @internal
*/
interface BucketArnInterface extends ArnInterface
{
public function getBucketName();
}

View File

@ -0,0 +1,77 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Arn\S3;
use UglyRobot\Infinite_Uploads\Aws\Arn\AccessPointArn as BaseAccessPointArn;
use UglyRobot\Infinite_Uploads\Aws\Arn\AccessPointArnInterface;
use UglyRobot\Infinite_Uploads\Aws\Arn\Arn;
use UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException;
/**
* This class represents an S3 Outposts access point ARN, which is in the
* following format:
*
* arn:{partition}:s3-outposts:{region}:{accountId}:outpost:{outpostId}:accesspoint:{accesspointName}
*
* ':' and '/' can be used interchangeably as delimiters for components after
* the account ID.
*
* @internal
*/
class OutpostsAccessPointArn extends \UglyRobot\Infinite_Uploads\Aws\Arn\AccessPointArn implements \UglyRobot\Infinite_Uploads\Aws\Arn\AccessPointArnInterface, \UglyRobot\Infinite_Uploads\Aws\Arn\S3\OutpostsArnInterface
{
public static function parse($string)
{
$data = parent::parse($string);
return self::parseOutpostData($data);
}
public function getOutpostId()
{
return $this->data['outpost_id'];
}
public function getAccesspointName()
{
return $this->data['accesspoint_name'];
}
private static function parseOutpostData(array $data)
{
$resourceData = preg_split("/[\\/:]/", $data['resource_id']);
$data['outpost_id'] = isset($resourceData[0]) ? $resourceData[0] : null;
$data['accesspoint_type'] = isset($resourceData[1]) ? $resourceData[1] : null;
$data['accesspoint_name'] = isset($resourceData[2]) ? $resourceData[2] : null;
if (isset($resourceData[3])) {
$data['resource_extra'] = implode(':', array_slice($resourceData, 3));
}
return $data;
}
/**
* Validation specific to OutpostsAccessPointArn. Note this uses the base Arn
* class validation instead of the direct parent due to it having slightly
* differing requirements from its parent.
*
* @param array $data
*/
protected static function validate(array $data)
{
\UglyRobot\Infinite_Uploads\Aws\Arn\Arn::validate($data);
if ($data['service'] !== 's3-outposts') {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 3rd component of an S3 Outposts" . " access point ARN represents the service and must be" . " 's3-outposts'.");
}
self::validateRegion($data, 'S3 Outposts access point ARN');
self::validateAccountId($data, 'S3 Outposts access point ARN');
if ($data['resource_type'] !== 'outpost') {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 6th component of an S3 Outposts" . " access point ARN represents the resource type and must be" . " 'outpost'.");
}
if (!self::isValidHostLabel($data['outpost_id'])) {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 7th component of an S3 Outposts" . " access point ARN is required, represents the outpost ID, and" . " must be a valid host label.");
}
if ($data['accesspoint_type'] !== 'accesspoint') {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 8th component of an S3 Outposts" . " access point ARN must be 'accesspoint'");
}
if (!self::isValidHostLabel($data['accesspoint_name'])) {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 9th component of an S3 Outposts" . " access point ARN is required, represents the accesspoint name," . " and must be a valid host label.");
}
if (!empty($data['resource_extra'])) {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("An S3 Outposts access point ARN" . " should only have 9 components, delimited by the characters" . " ':' and '/'. '{$data['resource_extra']}' was found after the" . " 9th component.");
}
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Arn\S3;
use UglyRobot\Infinite_Uploads\Aws\Arn\ArnInterface;
/**
* @internal
*/
interface OutpostsArnInterface extends ArnInterface
{
public function getOutpostId();
}

View File

@ -0,0 +1,71 @@
<?php
namespace UglyRobot\Infinite_Uploads\Aws\Arn\S3;
use UglyRobot\Infinite_Uploads\Aws\Arn\Arn;
use UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException;
use UglyRobot\Infinite_Uploads\Aws\Arn\ResourceTypeAndIdTrait;
/**
* This class represents an S3 Outposts bucket ARN, which is in the
* following format:
*
* @internal
*/
class OutpostsBucketArn extends \UglyRobot\Infinite_Uploads\Aws\Arn\Arn implements \UglyRobot\Infinite_Uploads\Aws\Arn\S3\BucketArnInterface, \UglyRobot\Infinite_Uploads\Aws\Arn\S3\OutpostsArnInterface
{
use ResourceTypeAndIdTrait;
/**
* Parses a string into an associative array of components that represent
* a OutpostsBucketArn
*
* @param $string
* @return array
*/
public static function parse($string)
{
$data = parent::parse($string);
$data = self::parseResourceTypeAndId($data);
return self::parseOutpostData($data);
}
public function getBucketName()
{
return $this->data['bucket_name'];
}
public function getOutpostId()
{
return $this->data['outpost_id'];
}
private static function parseOutpostData(array $data)
{
$resourceData = preg_split("/[\\/:]/", $data['resource_id'], 3);
$data['outpost_id'] = isset($resourceData[0]) ? $resourceData[0] : null;
$data['bucket_label'] = isset($resourceData[1]) ? $resourceData[1] : null;
$data['bucket_name'] = isset($resourceData[2]) ? $resourceData[2] : null;
return $data;
}
/**
*
* @param array $data
*/
protected static function validate(array $data)
{
\UglyRobot\Infinite_Uploads\Aws\Arn\Arn::validate($data);
if ($data['service'] !== 's3-outposts') {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 3rd component of an S3 Outposts" . " bucket ARN represents the service and must be 's3-outposts'.");
}
self::validateRegion($data, 'S3 Outposts bucket ARN');
self::validateAccountId($data, 'S3 Outposts bucket ARN');
if ($data['resource_type'] !== 'outpost') {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 6th component of an S3 Outposts" . " bucket ARN represents the resource type and must be" . " 'outpost'.");
}
if (!self::isValidHostLabel($data['outpost_id'])) {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 7th component of an S3 Outposts" . " bucket ARN is required, represents the outpost ID, and" . " must be a valid host label.");
}
if ($data['bucket_label'] !== 'bucket') {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 8th component of an S3 Outposts" . " bucket ARN must be 'bucket'");
}
if (empty($data['bucket_name'])) {
throw new \UglyRobot\Infinite_Uploads\Aws\Arn\Exception\InvalidArnException("The 9th component of an S3 Outposts" . " bucket ARN represents the bucket name and must not be empty.");
}
}
}