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 d984044..2e46ff0 100644 --- a/src/Compression/Compression.php +++ b/src/Compression/Compression.php @@ -4,6 +4,11 @@ abstract class Compression { + public const NONE = 'none'; + + /** + * @deprecated Use Compression::NONE instead. + */ public const IDENTITY = 'identity'; public const BROTLI = 'brotli'; @@ -89,6 +94,7 @@ public static function fromName(string $name): ?Compression return new Algorithms\XZ(); case Compression::ZSTD: return new Algorithms\Zstd(); + case Compression::NONE: case Compression::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, identity] * @return Compression|null */ public static function fromAcceptEncoding(string $acceptEncoding, array $supported = []): ?Compression @@ -116,16 +122,27 @@ public static function fromAcceptEncoding(string $acceptEncoding, array $support self::BROTLI => Algorithms\Brotli::isSupported(), self::GZIP => Algorithms\GZIP::isSupported(), self::DEFLATE => Algorithms\Deflate::isSupported(), + 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])) { @@ -139,7 +156,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)) { @@ -147,7 +164,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']);