Обновление клиента (apps, 3rdparty, install)
This commit is contained in:
+70
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* LICENSE: The MIT License (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* https://github.com/azure/azure-storage-php/LICENSE
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal\Serialization;
|
||||
|
||||
/**
|
||||
* The serialization interface.
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
interface ISerializer
|
||||
{
|
||||
/**
|
||||
* Serialize an object into a XML.
|
||||
*
|
||||
* @param Object $targetObject The target object to be serialized.
|
||||
* @param string $rootName The name of the root.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function objectSerialize($targetObject, $rootName);
|
||||
|
||||
/**
|
||||
* Serializes given array. The array indices must be string to use them as
|
||||
* as element name.
|
||||
*
|
||||
* @param array $array The object to serialize represented in array.
|
||||
* @param array $properties The used properties in the serialization process.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function serialize(array $array, array $properties = null);
|
||||
|
||||
|
||||
/**
|
||||
* Unserializes given serialized string.
|
||||
*
|
||||
* @param string $serialized The serialized object in string representation.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function unserialize($serialized);
|
||||
}
|
||||
Vendored
+96
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* LICENSE: The MIT License (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* https://github.com/azure/azure-storage-php/LICENSE
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal\Serialization;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\Internal\Validate;
|
||||
|
||||
/**
|
||||
* Perform JSON serialization / deserialization
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class JsonSerializer implements ISerializer
|
||||
{
|
||||
/**
|
||||
* Serialize an object with specified root element name.
|
||||
*
|
||||
* @param object $targetObject The target object.
|
||||
* @param string $rootName The name of the root element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function objectSerialize($targetObject, $rootName)
|
||||
{
|
||||
Validate::notNull($targetObject, 'targetObject');
|
||||
Validate::canCastAsString($rootName, 'rootName');
|
||||
|
||||
$contianer = new \stdClass();
|
||||
|
||||
$contianer->$rootName = $targetObject;
|
||||
|
||||
return json_encode($contianer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes given array. The array indices must be string to use them as
|
||||
* as element name.
|
||||
*
|
||||
* @param array $array The object to serialize represented in array.
|
||||
* @param array $properties The used properties in the serialization process.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function serialize(array $array = null, array $properties = null)
|
||||
{
|
||||
Validate::isArray($array, 'array');
|
||||
|
||||
return json_encode($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unserializes given serialized string to array.
|
||||
*
|
||||
* @param string $serialized The serialized object in string representation.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
Validate::canCastAsString($serialized, 'serialized');
|
||||
|
||||
$json = json_decode($serialized);
|
||||
if ($json && !is_array($json)) {
|
||||
return get_object_vars($json);
|
||||
} else {
|
||||
return $json;
|
||||
}
|
||||
}
|
||||
}
|
||||
Vendored
+178
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* LICENSE: The MIT License (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* https://github.com/azure/azure-storage-php/LICENSE
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2017 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal\Serialization;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\Internal\Validate;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Resources;
|
||||
use GuzzleHttp\Exception\RequestException;
|
||||
|
||||
/**
|
||||
* Provides functionality to serialize a message to a string.
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2017 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class MessageSerializer
|
||||
{
|
||||
/**
|
||||
* Serialize a message to a string. The message object must be either a type
|
||||
* of \Exception, or have following methods implemented.
|
||||
* getHeaders()
|
||||
* getProtocolVersion()
|
||||
* (getUri() && getMethod()) || (getStatusCode() && getReasonPhrase())
|
||||
*
|
||||
* @param object $message The message to be serialized.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function objectSerialize($targetObject)
|
||||
{
|
||||
//if the object is of exception type, serialize it using the methods
|
||||
//without checking the methods.
|
||||
if ($targetObject instanceof RequestException) {
|
||||
return self::serializeRequestException($targetObject);
|
||||
} elseif ($targetObject instanceof \Exception) {
|
||||
return self::serializeException($targetObject);
|
||||
}
|
||||
|
||||
Validate::methodExists($targetObject, 'getHeaders', 'targetObject');
|
||||
Validate::methodExists($targetObject, 'getProtocolVersion', 'targetObject');
|
||||
|
||||
// Serialize according to the implemented method.
|
||||
if (method_exists($targetObject, 'getUri') &&
|
||||
method_exists($targetObject, 'getMethod')) {
|
||||
return self::serializeRequest($targetObject);
|
||||
} elseif (method_exists($targetObject, 'getStatusCode') &&
|
||||
method_exists($targetObject, 'getReasonPhrase')) {
|
||||
return self::serializeResponse($targetObject);
|
||||
} else {
|
||||
throw new \InvalidArgumentException(
|
||||
Resources::INVALID_MESSAGE_OBJECT_TO_SERIALIZE
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the request type that implemented the following methods:
|
||||
* getHeaders()
|
||||
* getProtocolVersion()
|
||||
* getUri()
|
||||
* getMethod()
|
||||
*
|
||||
* @param object $request The request to be serialized.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function serializeRequest($request)
|
||||
{
|
||||
$headers = $request->getHeaders();
|
||||
$version = $request->getProtocolVersion();
|
||||
$uri = $request->getUri();
|
||||
$method = $request->getMethod();
|
||||
|
||||
$resultString = "Request:\n";
|
||||
$resultString .= "URI: {$uri}\nHTTP Version: {$version}\nMethod: {$method}\n";
|
||||
$resultString .= self::serializeHeaders($headers);
|
||||
|
||||
return $resultString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the response type that implemented the following methods:
|
||||
* getHeaders()
|
||||
* getProtocolVersion()
|
||||
* getStatusCode()
|
||||
* getReasonPhrase()
|
||||
*
|
||||
* @param object $response The response to be serialized
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function serializeResponse($response)
|
||||
{
|
||||
$headers = $response->getHeaders();
|
||||
$version = $response->getProtocolVersion();
|
||||
$status = $response->getStatusCode();
|
||||
$reason = $response->getReasonPhrase();
|
||||
|
||||
$resultString = "Response:\n";
|
||||
$resultString .= "Status Code: {$status}\nReason: {$reason}\n";
|
||||
$resultString .= "HTTP Version: {$version}\n";
|
||||
$resultString .= self::serializeHeaders($headers);
|
||||
|
||||
return $resultString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the message headers.
|
||||
*
|
||||
* @param array $headers The headers to be serialized.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function serializeHeaders(array $headers)
|
||||
{
|
||||
$resultString = "Headers:\n";
|
||||
foreach ($headers as $key => $value) {
|
||||
$resultString .= sprintf("%s: %s\n", $key, $value[0]);
|
||||
}
|
||||
|
||||
return $resultString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the request exception.
|
||||
*
|
||||
* @param RequestException $e the request exception to be serialized.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function serializeRequestException(RequestException $e)
|
||||
{
|
||||
$resultString = sprintf("Reason:\n%s\n", $e);
|
||||
if ($e->hasResponse()) {
|
||||
$resultString .= self::serializeResponse($e->getResponse());
|
||||
}
|
||||
|
||||
return $resultString;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize the general exception
|
||||
*
|
||||
* @param \Exception $e general exception to be serialized.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private static function serializeException(\Exception $e)
|
||||
{
|
||||
return sprintf("Reason:\n%s\n", $e);
|
||||
}
|
||||
}
|
||||
Vendored
+245
@@ -0,0 +1,245 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* LICENSE: The MIT License (the "License")
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
* https://github.com/azure/azure-storage-php/LICENSE
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
|
||||
namespace MicrosoftAzure\Storage\Common\Internal\Serialization;
|
||||
|
||||
use MicrosoftAzure\Storage\Common\Internal\Utilities;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Resources;
|
||||
use MicrosoftAzure\Storage\Common\Internal\Validate;
|
||||
|
||||
/**
|
||||
* Short description
|
||||
*
|
||||
* @ignore
|
||||
* @category Microsoft
|
||||
* @package MicrosoftAzure\Storage\Common\Internal\Serialization
|
||||
* @author Azure Storage PHP SDK <dmsh@microsoft.com>
|
||||
* @copyright 2016 Microsoft Corporation
|
||||
* @license https://github.com/azure/azure-storage-php/LICENSE
|
||||
* @link https://github.com/azure/azure-storage-php
|
||||
*/
|
||||
class XmlSerializer implements ISerializer
|
||||
{
|
||||
const STANDALONE = 'standalone';
|
||||
const ROOT_NAME = 'rootName';
|
||||
const DEFAULT_TAG = 'defaultTag';
|
||||
|
||||
/**
|
||||
* Converts a SimpleXML object to an Array recursively
|
||||
* ensuring all sub-elements are arrays as well.
|
||||
*
|
||||
* @param string $sxml The SimpleXML object.
|
||||
* @param array $arr The array into which to store results.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function sxml2arr($sxml, array $arr = null)
|
||||
{
|
||||
foreach ((array) $sxml as $key => $value) {
|
||||
if (is_object($value) || (is_array($value))) {
|
||||
$arr[$key] = $this->sxml2arr($value);
|
||||
} else {
|
||||
$arr[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $arr;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an array and produces XML based on it.
|
||||
*
|
||||
* @param XMLWriter $xmlw XMLWriter object that was previously instanted
|
||||
* and is used for creating the XML.
|
||||
* @param array $data Array to be converted to XML.
|
||||
* @param string $defaultTag Default XML tag to be used if none specified.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function arr2xml(\XMLWriter $xmlw, array $data, $defaultTag = null)
|
||||
{
|
||||
foreach ($data as $key => $value) {
|
||||
if ($key === Resources::XTAG_ATTRIBUTES) {
|
||||
foreach ($value as $attributeName => $attributeValue) {
|
||||
$xmlw->writeAttribute($attributeName, $attributeValue);
|
||||
}
|
||||
} elseif (is_array($value)) {
|
||||
if (!is_int($key)) {
|
||||
if ($key != Resources::EMPTY_STRING) {
|
||||
$xmlw->startElement($key);
|
||||
} else {
|
||||
$xmlw->startElement($defaultTag);
|
||||
}
|
||||
}
|
||||
|
||||
$this->arr2xml($xmlw, $value);
|
||||
|
||||
if (!is_int($key)) {
|
||||
$xmlw->endElement();
|
||||
}
|
||||
} else {
|
||||
$xmlw->writeElement($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the attributes of a specified object if get attributes
|
||||
* method is exposed.
|
||||
*
|
||||
* @param object $targetObject The target object.
|
||||
* @param array $methodArray The array of method of the target object.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
private static function getInstanceAttributes($targetObject, array $methodArray)
|
||||
{
|
||||
foreach ($methodArray as $method) {
|
||||
if ($method->name == 'getAttributes') {
|
||||
$classProperty = $method->invoke($targetObject);
|
||||
return $classProperty;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize an object with specified root element name.
|
||||
*
|
||||
* @param object $targetObject The target object.
|
||||
* @param string $rootName The name of the root element.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function objectSerialize($targetObject, $rootName)
|
||||
{
|
||||
Validate::notNull($targetObject, 'targetObject');
|
||||
Validate::canCastAsString($rootName, 'rootName');
|
||||
$xmlWriter = new \XmlWriter();
|
||||
$xmlWriter->openMemory();
|
||||
$xmlWriter->setIndent(true);
|
||||
$reflectionClass = new \ReflectionClass($targetObject);
|
||||
$methodArray = $reflectionClass->getMethods();
|
||||
$attributes = self::getInstanceAttributes(
|
||||
$targetObject,
|
||||
$methodArray
|
||||
);
|
||||
|
||||
$xmlWriter->startElement($rootName);
|
||||
if (!is_null($attributes)) {
|
||||
foreach (array_keys($attributes) as $attributeKey) {
|
||||
$xmlWriter->writeAttribute(
|
||||
$attributeKey,
|
||||
$attributes[$attributeKey]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($methodArray as $method) {
|
||||
if ((strpos($method->name, 'get') === 0)
|
||||
&& $method->isPublic()
|
||||
&& ($method->name != 'getAttributes')
|
||||
) {
|
||||
$variableName = substr($method->name, 3);
|
||||
$variableValue = $method->invoke($targetObject);
|
||||
if (!empty($variableValue)) {
|
||||
if (gettype($variableValue) === 'object') {
|
||||
$xmlWriter->writeRaw(
|
||||
XmlSerializer::objectSerialize(
|
||||
$variableValue,
|
||||
$variableName
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$xmlWriter->writeElement($variableName, $variableValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$xmlWriter->endElement();
|
||||
return $xmlWriter->outputMemory(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Serializes given array. The array indices must be string to use them as
|
||||
* as element name.
|
||||
*
|
||||
* @param array $array The object to serialize represented in array.
|
||||
* @param array $properties The used properties in the serialization process.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function serialize(array $array, array $properties = null)
|
||||
{
|
||||
$xmlVersion = '1.0';
|
||||
$xmlEncoding = 'UTF-8';
|
||||
$standalone = Utilities::tryGetValue($properties, self::STANDALONE);
|
||||
$defaultTag = Utilities::tryGetValue($properties, self::DEFAULT_TAG);
|
||||
$rootName = Utilities::tryGetValue($properties, self::ROOT_NAME);
|
||||
$docNamespace = Utilities::tryGetValue(
|
||||
$array,
|
||||
Resources::XTAG_NAMESPACE,
|
||||
null
|
||||
);
|
||||
|
||||
if (!is_array($array)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$xmlw = new \XmlWriter();
|
||||
$xmlw->openMemory();
|
||||
$xmlw->setIndent(true);
|
||||
$xmlw->startDocument($xmlVersion, $xmlEncoding, $standalone);
|
||||
|
||||
if (is_null($docNamespace)) {
|
||||
$xmlw->startElement($rootName);
|
||||
} else {
|
||||
foreach ($docNamespace as $uri => $prefix) {
|
||||
$xmlw->startElementNS($prefix, $rootName, $uri);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
unset($array[Resources::XTAG_NAMESPACE]);
|
||||
self::arr2xml($xmlw, $array, $defaultTag);
|
||||
|
||||
$xmlw->endElement();
|
||||
|
||||
return $xmlw->outputMemory(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Unserializes given serialized string.
|
||||
*
|
||||
* @param string $serialized The serialized object in string representation.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function unserialize($serialized)
|
||||
{
|
||||
$sxml = new \SimpleXMLElement($serialized);
|
||||
|
||||
return $this->sxml2arr($sxml);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user