Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM composer:2.0 as composer
FROM composer:2.0 AS composer

ARG TESTING=false
ENV TESTING=$TESTING
Expand All @@ -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"
Expand All @@ -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 \
Expand All @@ -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 \
Expand All @@ -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"

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"format": "./vendor/bin/pint"
},
"require": {
"php": ">=8.0"
"php": ">=8.1"
},
"require-dev": {
"phpunit/phpunit": "^9.3",
Expand Down
27 changes: 22 additions & 5 deletions src/Compression/Compression.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

abstract class Compression
{
public const NONE = 'none';

/**
* @deprecated Use Compression::NONE instead.
*/
public const IDENTITY = 'identity';

public const BROTLI = 'brotli';
Expand Down Expand Up @@ -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;
Expand All @@ -101,7 +107,7 @@ public static function fromName(string $name): ?Compression
* - <encoding-method> is the name of an encoding algorithm
* - [;q=<weight>] 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
Expand All @@ -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])) {
Expand All @@ -139,15 +156,15 @@ 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)) {
return null;
}

usort($encodings, function ($a, $b) {
return $a['quality'] <=> $b['quality'];
return $b['quality'] <=> $a['quality'];
});

return self::fromName($encodings[0]['encoding']);
Expand Down