123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- <?php
- /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
- abstract class AcsRequest
- {
- /**
- * @var string
- */
- protected $version;
- /**
- * @var string
- */
- protected $product;
- /**
- * @var string
- */
- protected $actionName;
- /**
- * @var string
- */
- protected $regionId;
- /**
- * @var string
- */
- protected $acceptFormat;
- /**
- * @var string
- */
- protected $method;
- /**
- * @var string
- */
- protected $requestScheme = 'http';
- /**
- * @var string
- */
- protected $content;
- /**
- * @var array
- */
- protected $queryParameters = array();
- /**
- * @var array
- */
- protected $headers = array();
- /**
- * @var null|string
- */
- protected $locationServiceCode;
- /**
- * @var null|string
- */
- protected $locationEndpointType;
- /**
- * @var array The original parameters of the request object.
- */
- protected $requestParameters = array();
- /**
- * @var string
- */
- protected $stringToBeSigned = '';
- /**
- * AcsRequest constructor.
- *
- * @param string $product
- * @param string $version
- * @param string $actionName
- * @param string|null $locationServiceCode
- * @param string $locationEndpointType
- */
- public function __construct($product,
- $version,
- $actionName,
- $locationServiceCode = null,
- $locationEndpointType = 'openAPI')
- {
- $this->headers['x-sdk-client'] = 'php/2.0.0';
- $this->product = $product;
- $this->version = $version;
- $this->actionName = $actionName;
- $this->locationServiceCode = $locationServiceCode;
- $this->locationEndpointType = $locationEndpointType;
- }
- /**
- * @param $iSigner
- * @param $credential
- * @param $domain
- *
- * @return mixed
- */
- abstract public function composeUrl($iSigner, $credential, $domain);
- /**
- * @return string
- */
- public function getVersion()
- {
- return $this->version;
- }
- /**
- * @param $version
- */
- public function setVersion($version)
- {
- $this->version = $version;
- }
- /**
- * @return string
- */
- public function getProduct()
- {
- return $this->product;
- }
- /**
- * @param string $product
- */
- public function setProduct($product)
- {
- $this->product = $product;
- }
- /**
- * @return string
- */
- public function getActionName()
- {
- return $this->actionName;
- }
- /**
- * @param string $actionName
- */
- public function setActionName($actionName)
- {
- $this->actionName = $actionName;
- }
- /**
- * @return string
- */
- public function getAcceptFormat()
- {
- return $this->acceptFormat;
- }
- /**
- * @param string $acceptFormat
- */
- public function setAcceptFormat($acceptFormat)
- {
- $this->acceptFormat = $acceptFormat;
- }
- /**
- * @return array
- */
- public function getQueryParameters()
- {
- return $this->queryParameters;
- }
- /**
- * @return array
- */
- public function getHeaders()
- {
- return $this->headers;
- }
- /**
- * @return string
- */
- public function getMethod()
- {
- return $this->method;
- }
- /**
- * @param string $method
- */
- public function setMethod($method)
- {
- $this->method = $method;
- }
- /**
- * @return string
- */
- public function getProtocol()
- {
- return $this->requestScheme;
- }
- /**
- * @param string $protocol
- */
- public function setProtocol($protocol)
- {
- $this->requestScheme = $protocol;
- }
- /**
- * @return string
- */
- public function getRegionId()
- {
- return $this->regionId;
- }
- /**
- * @param string $region
- */
- public function setRegionId($region)
- {
- $this->regionId = $region;
- }
- /**
- * @return string
- */
- public function getContent()
- {
- return $this->content;
- }
- /**
- * @param string $content
- */
- public function setContent($content)
- {
- $this->content = $content;
- }
- /**
- * @param string $headerKey
- * @param mixed $headerValue
- */
- public function addHeader($headerKey, $headerValue)
- {
- $this->headers[$headerKey] = $headerValue;
- }
- /**
- * @return null|string
- */
- public function getLocationServiceCode()
- {
- return $this->locationServiceCode;
- }
- /**
- * @return null|string
- */
- public function getLocationEndpointType()
- {
- return $this->locationEndpointType;
- }
- /**
- * Magic method for get parameters.
- *
- * @param string $name
- * @param mixed $arguments
- *
- * @return $this
- */
- public function __call($name, $arguments)
- {
- if (\strpos($name, 'get', 0) !== false) {
- $parameterName = $this->propertyNameByMethodName($name);
- return isset($this->requestParameters[$parameterName])
- ? $this->requestParameters[$parameterName]
- : null;
- }
- return $this;
- }
- /**
- * @param string $methodName
- *
- * @return string
- */
- protected function propertyNameByMethodName($methodName)
- {
- return \mb_strcut($methodName, 3);
- }
- /**
- * @return string
- */
- public function stringToBeSigned()
- {
- return $this->stringToBeSigned;
- }
- }
|