123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace OSS\Model;
- use OSS\Core\OssException;
- /**
- * Class CorsRule
- * @package OSS\Model
- * @link http://help.aliyun.com/document_detail/oss/api-reference/cors/PutBucketcors.html
- */
- class CorsRule
- {
- /**
- * Add an allowedOrigin rule
- *
- * @param string $allowedOrigin
- */
- public function addAllowedOrigin($allowedOrigin)
- {
- if (!empty($allowedOrigin)) {
- $this->allowedOrigins[] = $allowedOrigin;
- }
- }
- /**
- * Add an allowedMethod rule
- *
- * @param string $allowedMethod
- */
- public function addAllowedMethod($allowedMethod)
- {
- if (!empty($allowedMethod)) {
- $this->allowedMethods[] = $allowedMethod;
- }
- }
- /**
- * Add an allowedHeader rule
- *
- * @param string $allowedHeader
- */
- public function addAllowedHeader($allowedHeader)
- {
- if (!empty($allowedHeader)) {
- $this->allowedHeaders[] = $allowedHeader;
- }
- }
- /**
- * Add an exposeHeader rule
- *
- * @param string $exposeHeader
- */
- public function addExposeHeader($exposeHeader)
- {
- if (!empty($exposeHeader)) {
- $this->exposeHeaders[] = $exposeHeader;
- }
- }
- /**
- * @return int
- */
- public function getMaxAgeSeconds()
- {
- return $this->maxAgeSeconds;
- }
- /**
- * @param int $maxAgeSeconds
- */
- public function setMaxAgeSeconds($maxAgeSeconds)
- {
- $this->maxAgeSeconds = $maxAgeSeconds;
- }
- /**
- * Get the AllowedHeaders list
- *
- * @return string[]
- */
- public function getAllowedHeaders()
- {
- return $this->allowedHeaders;
- }
- /**
- * Get the AllowedOrigins list
- *
- * @return string[]
- */
- public function getAllowedOrigins()
- {
- return $this->allowedOrigins;
- }
- /**
- * Get the AllowedMethods list
- *
- * @return string[]
- */
- public function getAllowedMethods()
- {
- return $this->allowedMethods;
- }
- /**
- * Get the ExposeHeaders list
- *
- * @return string[]
- */
- public function getExposeHeaders()
- {
- return $this->exposeHeaders;
- }
- /**
- * Serialize all the rules into the xml represented by parameter $xmlRule
- *
- * @param \SimpleXMLElement $xmlRule
- * @throws OssException
- */
- public function appendToXml(&$xmlRule)
- {
- if (!isset($this->maxAgeSeconds)) {
- throw new OssException("maxAgeSeconds is not set in the Rule");
- }
- foreach ($this->allowedOrigins as $allowedOrigin) {
- $xmlRule->addChild(CorsConfig::OSS_CORS_ALLOWED_ORIGIN, $allowedOrigin);
- }
- foreach ($this->allowedMethods as $allowedMethod) {
- $xmlRule->addChild(CorsConfig::OSS_CORS_ALLOWED_METHOD, $allowedMethod);
- }
- foreach ($this->allowedHeaders as $allowedHeader) {
- $xmlRule->addChild(CorsConfig::OSS_CORS_ALLOWED_HEADER, $allowedHeader);
- }
- foreach ($this->exposeHeaders as $exposeHeader) {
- $xmlRule->addChild(CorsConfig::OSS_CORS_EXPOSE_HEADER, $exposeHeader);
- }
- $xmlRule->addChild(CorsConfig::OSS_CORS_MAX_AGE_SECONDS, strval($this->maxAgeSeconds));
- }
- private $allowedHeaders = array();
- private $allowedOrigins = array();
- private $allowedMethods = array();
- private $exposeHeaders = array();
- private $maxAgeSeconds = null;
- }
|