From 1a9c2cddefe4307e2ee9d5cf0ffc4c3ee9d75d70 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 17 Feb 2026 10:07:52 +0530 Subject: [PATCH 1/3] Rename IDENTITY constant to NONE for consistency with storage repo --- src/Compression/Compression.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Compression/Compression.php b/src/Compression/Compression.php index d984044..e4536c6 100644 --- a/src/Compression/Compression.php +++ b/src/Compression/Compression.php @@ -4,7 +4,12 @@ abstract class Compression { - public const IDENTITY = 'identity'; + public const NONE = 'none'; + + /** + * @deprecated Use Compression::NONE instead. + */ + public const IDENTITY = 'none'; public const BROTLI = 'brotli'; @@ -89,7 +94,8 @@ public static function fromName(string $name): ?Compression return new Algorithms\XZ(); case Compression::ZSTD: return new Algorithms\Zstd(); - case Compression::IDENTITY: + case Compression::NONE: + case 'identity': default: return null; } @@ -101,7 +107,7 @@ public static function fromName(string $name): ?Compression * - is the name of an encoding algorithm * - [;q=] is an optional quality value from 0 to 1, indicating preference (1 being the highest) * @param array $supported List of supported compression algorithms, if not provided, the default list will be used - * The default list is [br, gzip, deflate, identity] + * The default list is [zstd, br, gzip, deflate, none] * @return Compression|null */ public static function fromAcceptEncoding(string $acceptEncoding, array $supported = []): ?Compression @@ -116,7 +122,7 @@ public static function fromAcceptEncoding(string $acceptEncoding, array $support self::BROTLI => Algorithms\Brotli::isSupported(), self::GZIP => Algorithms\GZIP::isSupported(), self::DEFLATE => Algorithms\Deflate::isSupported(), - self::IDENTITY => true, + self::NONE => true, ]; } From 0059b47d8f631b6b91471172d7757a6408069456 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 17 Feb 2026 10:36:06 +0530 Subject: [PATCH 2/3] fix comment suggestions --- src/Compression/Compression.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Compression/Compression.php b/src/Compression/Compression.php index e4536c6..52faef0 100644 --- a/src/Compression/Compression.php +++ b/src/Compression/Compression.php @@ -9,7 +9,7 @@ abstract class Compression /** * @deprecated Use Compression::NONE instead. */ - public const IDENTITY = 'none'; + public const IDENTITY = 'identity'; public const BROTLI = 'brotli'; @@ -95,7 +95,7 @@ public static function fromName(string $name): ?Compression case Compression::ZSTD: return new Algorithms\Zstd(); case Compression::NONE: - case 'identity': + case Compression::IDENTITY: default: return null; } @@ -107,7 +107,7 @@ public static function fromName(string $name): ?Compression * - is the name of an encoding algorithm * - [;q=] is an optional quality value from 0 to 1, indicating preference (1 being the highest) * @param array $supported List of supported compression algorithms, if not provided, the default list will be used - * The default list is [zstd, br, gzip, deflate, none] + * The default list is [zstd, br, gzip, deflate, none, identity] * @return Compression|null */ public static function fromAcceptEncoding(string $acceptEncoding, array $supported = []): ?Compression @@ -123,6 +123,7 @@ public static function fromAcceptEncoding(string $acceptEncoding, array $support self::GZIP => Algorithms\GZIP::isSupported(), self::DEFLATE => Algorithms\Deflate::isSupported(), self::NONE => true, + self::IDENTITY => true, ]; } @@ -145,7 +146,7 @@ public static function fromAcceptEncoding(string $acceptEncoding, array $support }, $encodings); $encodings = \array_filter($encodings, function ($encoding) use ($supported) { - return \in_array($encoding['encoding'], $supported); + return isset($supported[$encoding['encoding']]) && $supported[$encoding['encoding']]; }); if (empty($encodings)) { @@ -153,7 +154,7 @@ public static function fromAcceptEncoding(string $acceptEncoding, array $support } usort($encodings, function ($a, $b) { - return $a['quality'] <=> $b['quality']; + return $b['quality'] <=> $a['quality']; }); return self::fromName($encodings[0]['encoding']); From 171e37f6fe663991448fcf06acf830f7eb0b05de Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Tue, 17 Feb 2026 10:44:21 +0530 Subject: [PATCH 3/3] fix regression --- Dockerfile | 20 ++++++++++---------- README.md | 2 +- composer.json | 2 +- src/Compression/Compression.php | 14 ++++++++++++-- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5523b6c..fec3566 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM composer:2.0 as composer +FROM composer:2.0 AS composer ARG TESTING=false ENV TESTING=$TESTING @@ -15,7 +15,7 @@ RUN composer update \ --no-scripts \ --prefer-dist -FROM php:8.0-cli-alpine as compile +FROM php:8.1-cli-alpine AS compile ENV PHP_ZSTD_VERSION="master" ENV PHP_BROTLI_VERSION="7ae4fcd8b81a65d7521c298cae49af386d1ea4e3" @@ -42,7 +42,7 @@ RUN git clone --recursive --depth 1 --branch $PHP_ZSTD_VERSION https://github.co && make && make install ## Brotli Extension -FROM compile as brotli +FROM compile AS brotli RUN git clone https://github.com/kjdev/php-ext-brotli.git \ && cd php-ext-brotli \ && git reset --hard $PHP_BROTLI_VERSION \ @@ -69,7 +69,7 @@ RUN git clone --recursive https://github.com/kjdev/php-ext-snappy.git \ && make && make install ## Xz Extension -FROM compile as xz +FROM compile AS xz RUN wget https://tukaani.org/xz/xz-${PHP_XZ_VERSION}.tar.xz -O xz.tar.xz \ && tar -xJf xz.tar.xz \ && rm xz.tar.xz \ @@ -87,7 +87,7 @@ RUN git clone https://github.com/codemasher/php-ext-xz.git --branch ${PHP_EXT_XZ && ./configure \ && make && make install -FROM compile as final +FROM compile AS final LABEL maintainer="team@appwrite.io" @@ -104,11 +104,11 @@ RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini" \ && echo "memory_limit=1024M" >> $PHP_INI_DIR/php.ini COPY --from=composer /usr/local/src/vendor /usr/src/code/vendor -COPY --from=zstd /usr/local/lib/php/extensions/no-debug-non-zts-20200930/zstd.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/ -COPY --from=brotli /usr/local/lib/php/extensions/no-debug-non-zts-20200930/brotli.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/ -COPY --from=lz4 /usr/local/lib/php/extensions/no-debug-non-zts-20200930/lz4.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/ -COPY --from=snappy /usr/local/lib/php/extensions/no-debug-non-zts-20200930/snappy.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/ -COPY --from=xz /usr/local/lib/php/extensions/no-debug-non-zts-20200930/xz.so /usr/local/lib/php/extensions/no-debug-non-zts-20200930/ +COPY --from=zstd /usr/local/lib/php/extensions/no-debug-non-zts-20210902/zstd.so /usr/local/lib/php/extensions/no-debug-non-zts-20210902/ +COPY --from=brotli /usr/local/lib/php/extensions/no-debug-non-zts-20210902/brotli.so /usr/local/lib/php/extensions/no-debug-non-zts-20210902/ +COPY --from=lz4 /usr/local/lib/php/extensions/no-debug-non-zts-20210902/lz4.so /usr/local/lib/php/extensions/no-debug-non-zts-20210902/ +COPY --from=snappy /usr/local/lib/php/extensions/no-debug-non-zts-20210902/snappy.so /usr/local/lib/php/extensions/no-debug-non-zts-20210902/ +COPY --from=xz /usr/local/lib/php/extensions/no-debug-non-zts-20210902/xz.so /usr/local/lib/php/extensions/no-debug-non-zts-20210902/ # Add Source Code COPY . /usr/src/code diff --git a/README.md b/README.md index 3eb07cd..1f83489 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ composer require utopia-php/compression ## System Requirements -Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible. +Utopia Framework requires PHP 8.1 or later. We recommend using the latest PHP version whenever possible. ## Copyright and license diff --git a/composer.json b/composer.json index 9f253b3..a4701fd 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "format": "./vendor/bin/pint" }, "require": { - "php": ">=8.0" + "php": ">=8.1" }, "require-dev": { "phpunit/phpunit": "^9.3", diff --git a/src/Compression/Compression.php b/src/Compression/Compression.php index 52faef0..2e46ff0 100644 --- a/src/Compression/Compression.php +++ b/src/Compression/Compression.php @@ -125,14 +125,24 @@ public static function fromAcceptEncoding(string $acceptEncoding, array $support self::NONE => true, self::IDENTITY => true, ]; + } else { + // Convert flat array to associative array + if (array_is_list($supported)) { + $supported = \array_fill_keys($supported, true); + } } + // Map encoding aliases to canonical names + $aliases = [ + 'br' => self::BROTLI, + ]; + $encodings = \array_map('trim', \explode(',', $acceptEncoding)); $encodings = \array_map('strtolower', $encodings); - $encodings = \array_map(function ($encoding) { + $encodings = \array_map(function ($encoding) use ($aliases) { $parts = \explode(';', $encoding); - $encoding = $parts[0]; + $encoding = $aliases[$parts[0]] ?? $parts[0]; $quality = 1.0; if (isset($parts[1])) {