Skip to content

Instantly share code, notes, and snippets.

@spaze
Last active March 24, 2022 17:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spaze/946b885dc668397bf0386eefeebf5ad1 to your computer and use it in GitHub Desktop.
Save spaze/946b885dc668397bf0386eefeebf5ad1 to your computer and use it in GitHub Desktop.
azure-storage-php composer patches for cweagans/composer-patches
  1. Install composer-patches plugin
composer require cweagans/composer-patches
  1. Download all the files (*.diff & *.json) to patches subdirectory of your project

  2. Add the following to your composer.json:

	"extra": {
		"patches-file": "patches/composer.patches.json"
	}
  1. Then the Azure SDK package will be patched automatically on composer update & composer install. The patches are "documented" and will be reapplied whenever needed until a new release with the fixes is available.
{
"patches": {
"microsoft/azure-storage-common": {
"Compare numbers to numbers": "patches/microsoft-azure-storage-common-php8-comparison-pr274.diff",
"Convert string to exception": "patches/microsoft-azure-storage-table-convert-to-exception-pr262.diff"
},
"microsoft/azure-storage-table": {
"Sort callback must return int not bool": "patches/microsoft-azure-storage-table-php8-sort-callback-pr288.diff",
"PK/RK as strings": "patches/microsoft-azure-storage-table-pk-rk-strings-pr278.diff"
}
}
}
diff --git a/azure-storage-common/src/Common/SharedAccessSignatureHelper.php b/azure-storage-common/src/Common/SharedAccessSignatureHelper.php
index 2031821e..d5cc81f4 100644
--- a/azure-storage-common/src/Common/SharedAccessSignatureHelper.php
+++ b/azure-storage-common/src/Common/SharedAccessSignatureHelper.php
@@ -291,7 +291,7 @@ class SharedAccessSignatureHelper
}
Validate::isTrue(
- strlen($input) == '',
+ strlen($input) == 0,
sprintf(
Resources::STRING_NOT_WITH_GIVEN_COMBINATION,
implode(', ', $array)
diff --git a/azure-storage-common/src/Common/Internal/ServiceRestProxy.php b/azure-storage-common/src/Common/Internal/ServiceRestProxy.php
index 1b911e594..a7119e276 100644
--- a/azure-storage-common/src/Common/Internal/ServiceRestProxy.php
+++ b/azure-storage-common/src/Common/Internal/ServiceRestProxy.php
@@ -402,24 +402,38 @@ class ServiceRestProxy extends RestProxy
);
},
function ($reason) use ($expected) {
- if (!($reason instanceof RequestException)) {
- throw $reason;
- }
- $response = $reason->getResponse();
- if ($response != null) {
- self::throwIfError(
- $response,
- $expected
- );
- } else {
- //if could not get response but promise rejected, throw reason.
- throw $reason;
- }
- return $response;
+ return $this->onRejected($reason, $expected);
}
);
}
+ /**
+ * @param string|\Exception $reason Rejection reason.
+ * @param array|int $expected Expected Status Codes.
+ *
+ * @return ResponseInterface
+ */
+ protected function onRejected($reason, $expected)
+ {
+ if (!($reason instanceof \Exception)) {
+ throw new \RuntimeException($reason);
+ }
+ if (!($reason instanceof RequestException)) {
+ throw $reason;
+ }
+ $response = $reason->getResponse();
+ if ($response != null) {
+ self::throwIfError(
+ $response,
+ $expected
+ );
+ } else {
+ //if could not get response but promise rejected, throw reason.
+ throw $reason;
+ }
+ return $response;
+ }
+
/**
* Generate the request options using the given service options and stored
* information.
diff --git a/azure-storage-table/src/Table/Models/BatchResult.php b/azure-storage-table/src/Table/Models/BatchResult.php
index 572995288..e5fc93330 100644
--- a/azure-storage-table/src/Table/Models/BatchResult.php
+++ b/azure-storage-table/src/Table/Models/BatchResult.php
@@ -96,16 +96,16 @@ class BatchResult
* @param mixed $r1 The first response object.
* @param mixed $r2 The second response object.
*
- * @return boolean
+ * @return integer
*/
private static function _compareUsingContentId($r1, $r2)
{
$h1 = array_change_key_case($r1->headers);
$h2 = array_change_key_case($r2->headers);
- $c1 = Utilities::tryGetValue($h1, Resources::CONTENT_ID, 0);
- $c2 = Utilities::tryGetValue($h2, Resources::CONTENT_ID, 0);
+ $c1 = intval(Utilities::tryGetValue($h1, Resources::CONTENT_ID, 0));
+ $c2 = intval(Utilities::tryGetValue($h2, Resources::CONTENT_ID, 0));
- return intval($c1) >= intval($c2);
+ return $c1 < $c2 ? -1 : ($c1 === $c2 ? 0 : 1);
}
/**
diff --git a/azure-storage-table/src/Table/Internal/JsonODataReaderWriter.php b/azure-storage-table/src/Table/Internal/JsonODataReaderWriter.php
index 58bcc146..3df49048 100644
--- a/azure-storage-table/src/Table/Internal/JsonODataReaderWriter.php
+++ b/azure-storage-table/src/Table/Internal/JsonODataReaderWriter.php
@@ -202,6 +202,8 @@ private function parseOneEntity($rawEntity)
$edmType;
if (array_key_exists($key . Resources::JSON_ODATA_TYPE_SUFFIX, $rawEntity)) {
$edmType = $rawEntity[$key . Resources::JSON_ODATA_TYPE_SUFFIX];
+ } elseif (in_array($key, [Resources::JSON_PARTITION_KEY, Resources::JSON_ROW_KEY], true)) {
+ $edmType = EdmType::STRING;
} else {
// Guess the property type
$edmType = EdmType::propertyType($value);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment