diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 00000000..bca79de9 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,20 @@ +name: "Linter" + +on: [pull_request] +jobs: + lint: + name: Linter + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + + - run: git checkout HEAD^2 + + - name: Run Linter + run: | + docker run --rm -v $PWD:/app composer sh -c \ + "composer install --profile --ignore-platform-reqs && composer lint" diff --git a/composer.json b/composer.json index 0b35052e..667ecfbc 100644 --- a/composer.json +++ b/composer.json @@ -11,6 +11,10 @@ "autoload-dev": { "psr-4": {"Utopia\\Tests\\Storage\\":"tests/Storage"} }, + "scripts": { + "lint": "./vendor/bin/pint --test", + "format": "./vendor/bin/pint" + }, "require": { "ext-fileinfo": "*", "ext-zlib": "*", @@ -23,7 +27,8 @@ }, "require-dev": { "phpunit/phpunit": "^9.3", - "vimeo/psalm": "4.0.1" + "vimeo/psalm": "4.0.1", + "laravel/pint": "1.2.*" }, "minimum-stability": "dev" } diff --git a/composer.lock b/composer.lock index bb73465f..5184ca1e 100644 --- a/composer.lock +++ b/composer.lock @@ -4,20 +4,20 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e968ba6362f252d347db4f34b1515ca4", + "content-hash": "0e15ac0ae89a77c7420f825af10e33fc", "packages": [ { "name": "utopia-php/framework", - "version": "0.25.1", + "version": "0.26.0", "source": { "type": "git", "url": "https://github.com/utopia-php/framework.git", - "reference": "2391b397135586b2100d39e338827bef8d2f4ad0" + "reference": "e8da5576370366d3bf9c574ec855f8c96fe4f34e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/framework/zipball/2391b397135586b2100d39e338827bef8d2f4ad0", - "reference": "2391b397135586b2100d39e338827bef8d2f4ad0", + "url": "https://api.github.com/repos/utopia-php/framework/zipball/e8da5576370366d3bf9c574ec855f8c96fe4f34e", + "reference": "e8da5576370366d3bf9c574ec855f8c96fe4f34e", "shasum": "" }, "require": { @@ -46,15 +46,15 @@ ], "support": { "issues": "https://github.com/utopia-php/framework/issues", - "source": "https://github.com/utopia-php/framework/tree/0.25.1" + "source": "https://github.com/utopia-php/framework/tree/0.26.0" }, - "time": "2022-11-23T18:22:23+00:00" + "time": "2023-01-13T08:14:43+00:00" } ], "packages-dev": [ { "name": "amphp/amp", - "version": "dev-master", + "version": "2.x-dev", "source": { "type": "git", "url": "https://github.com/amphp/amp.git", @@ -78,7 +78,6 @@ "psalm/phar": "^3.11@dev", "react/promise": "^2" }, - "default-branch": true, "type": "library", "extra": { "branch-alias": { @@ -144,7 +143,7 @@ }, { "name": "amphp/byte-stream", - "version": "dev-master", + "version": "1.x-dev", "source": { "type": "git", "url": "https://github.com/amphp/byte-stream.git", @@ -168,7 +167,6 @@ "phpunit/phpunit": "^6 || ^7 || ^8", "psalm/phar": "^3.11.4" }, - "default-branch": true, "type": "library", "extra": { "branch-alias": { @@ -300,12 +298,12 @@ "source": { "type": "git", "url": "https://github.com/composer/semver.git", - "reference": "3953f23262f2bff1919fc82183ad9acb13ff62c9" + "reference": "fa1ec24f0ab1efe642671ec15c51a3ab879f59bf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/3953f23262f2bff1919fc82183ad9acb13ff62c9", - "reference": "3953f23262f2bff1919fc82183ad9acb13ff62c9", + "url": "https://api.github.com/repos/composer/semver/zipball/fa1ec24f0ab1efe642671ec15c51a3ab879f59bf", + "reference": "fa1ec24f0ab1efe642671ec15c51a3ab879f59bf", "shasum": "" }, "require": { @@ -356,9 +354,9 @@ "versioning" ], "support": { - "irc": "irc://irc.freenode.org/composer", + "irc": "ircs://irc.libera.chat:6697/composer", "issues": "https://github.com/composer/semver/issues", - "source": "https://github.com/composer/semver/tree/3.3.2" + "source": "https://github.com/composer/semver/tree/main" }, "funding": [ { @@ -374,7 +372,7 @@ "type": "tidelift" } ], - "time": "2022-04-01T19:23:25+00:00" + "time": "2023-01-13T15:47:53+00:00" }, { "name": "composer/xdebug-handler", @@ -479,31 +477,32 @@ }, { "name": "doctrine/instantiator", - "version": "1.5.x-dev", + "version": "2.0.x-dev", "source": { "type": "git", "url": "https://github.com/doctrine/instantiator.git", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc" + "reference": "d6eef505a6c46e963e54bf73bb9de43cdea70821" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/10dcfce151b967d20fde1b34ae6640712c3891bc", - "reference": "10dcfce151b967d20fde1b34ae6640712c3891bc", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/d6eef505a6c46e963e54bf73bb9de43cdea70821", + "reference": "d6eef505a6c46e963e54bf73bb9de43cdea70821", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0" + "php": "^8.1" }, "require-dev": { - "doctrine/coding-standard": "^9", + "doctrine/coding-standard": "^11", "ext-pdo": "*", "ext-phar": "*", - "phpbench/phpbench": "^0.16 || ^1", - "phpstan/phpstan": "^1.4", - "phpstan/phpstan-phpunit": "^1", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.22" + "phpbench/phpbench": "^1.2", + "phpstan/phpstan": "^1.9.4", + "phpstan/phpstan-phpunit": "^1.3", + "phpunit/phpunit": "^9.5.27", + "vimeo/psalm": "^5.4" }, + "default-branch": true, "type": "library", "autoload": { "psr-4": { @@ -529,7 +528,7 @@ ], "support": { "issues": "https://github.com/doctrine/instantiator/issues", - "source": "https://github.com/doctrine/instantiator/tree/1.4.x" + "source": "https://github.com/doctrine/instantiator/tree/2.0.x" }, "funding": [ { @@ -545,7 +544,7 @@ "type": "tidelift" } ], - "time": "2022-03-03T08:28:38+00:00" + "time": "2023-01-04T15:42:40+00:00" }, { "name": "felixfbecker/advanced-json-rpc", @@ -649,6 +648,72 @@ }, "time": "2022-06-19T17:15:06+00:00" }, + { + "name": "laravel/pint", + "version": "v1.2.1", + "source": { + "type": "git", + "url": "https://github.com/laravel/pint.git", + "reference": "e60e2112ee779ce60f253695b273d1646a17d6f1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/pint/zipball/e60e2112ee779ce60f253695b273d1646a17d6f1", + "reference": "e60e2112ee779ce60f253695b273d1646a17d6f1", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-mbstring": "*", + "ext-tokenizer": "*", + "ext-xml": "*", + "php": "^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.11.0", + "illuminate/view": "^9.32.0", + "laravel-zero/framework": "^9.2.0", + "mockery/mockery": "^1.5.1", + "nunomaduro/larastan": "^2.2.0", + "nunomaduro/termwind": "^1.14.0", + "pestphp/pest": "^1.22.1" + }, + "bin": [ + "builds/pint" + ], + "type": "project", + "autoload": { + "psr-4": { + "App\\": "app/", + "Database\\Seeders\\": "database/seeders/", + "Database\\Factories\\": "database/factories/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nuno Maduro", + "email": "enunomaduro@gmail.com" + } + ], + "description": "An opinionated code formatter for PHP.", + "homepage": "https://laravel.com", + "keywords": [ + "format", + "formatter", + "lint", + "linter", + "php" + ], + "support": { + "issues": "https://github.com/laravel/pint/issues", + "source": "https://github.com/laravel/pint" + }, + "time": "2022-11-29T16:25:20+00:00" + }, { "name": "myclabs/deep-copy", "version": "1.x-dev", @@ -766,12 +831,12 @@ "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "3182d12b55895a2e71ed6684f9bd5cd13527e94e" + "reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/3182d12b55895a2e71ed6684f9bd5cd13527e94e", - "reference": "3182d12b55895a2e71ed6684f9bd5cd13527e94e", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/570e980a201d8ed0236b0a62ddf2c9cbb2034039", + "reference": "570e980a201d8ed0236b0a62ddf2c9cbb2034039", "shasum": "" }, "require": { @@ -813,9 +878,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/4.x" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.15.3" }, - "time": "2022-12-14T20:51:15+00:00" + "time": "2023-01-16T22:05:37+00:00" }, { "name": "openlss/lib-array2xml", @@ -1166,16 +1231,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.15.2", + "version": "1.15.3", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "5941477f100993652218928039d530b75a13a9ca" + "reference": "61800f71a5526081d1b5633766aa88341f1ade76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/5941477f100993652218928039d530b75a13a9ca", - "reference": "5941477f100993652218928039d530b75a13a9ca", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/61800f71a5526081d1b5633766aa88341f1ade76", + "reference": "61800f71a5526081d1b5633766aa88341f1ade76", "shasum": "" }, "require": { @@ -1205,9 +1270,9 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.15.2" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.15.3" }, - "time": "2022-12-16T06:42:48+00:00" + "time": "2022-12-20T20:56:55+00:00" }, { "name": "phpunit/php-code-coverage", @@ -1215,12 +1280,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "8e92388b937f78ecf46d91ea1ed9f325e186d0a9" + "reference": "2cf940ebc6355a9d430462811b5aaa308b174bed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/8e92388b937f78ecf46d91ea1ed9f325e186d0a9", - "reference": "8e92388b937f78ecf46d91ea1ed9f325e186d0a9", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/2cf940ebc6355a9d430462811b5aaa308b174bed", + "reference": "2cf940ebc6355a9d430462811b5aaa308b174bed", "shasum": "" }, "require": { @@ -1276,7 +1341,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.24" }, "funding": [ { @@ -1284,7 +1349,7 @@ "type": "github" } ], - "time": "2022-12-19T06:54:59+00:00" + "time": "2023-01-26T08:26:55+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1529,20 +1594,20 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.x-dev", + "version": "9.6.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a0560a2917c315c476a285d2888700826c9d4a81" + "reference": "e6c588044e41e22777225c4339bce021113cc829" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a0560a2917c315c476a285d2888700826c9d4a81", - "reference": "a0560a2917c315c476a285d2888700826c9d4a81", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/e6c588044e41e22777225c4339bce021113cc829", + "reference": "e6c588044e41e22777225c4339bce021113cc829", "shasum": "" }, "require": { - "doctrine/instantiator": "^1.3.1", + "doctrine/instantiator": "^1.3.1 || ^2", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", @@ -1580,7 +1645,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "9.5-dev" + "dev-master": "9.6-dev" } }, "autoload": { @@ -1611,7 +1676,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6" }, "funding": [ { @@ -1627,7 +1692,7 @@ "type": "tidelift" } ], - "time": "2022-12-19T06:50:23+00:00" + "time": "2023-01-26T08:31:58+00:00" }, { "name": "psr/container", @@ -2703,12 +2768,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "9bd719e53bce492742bf34948d8ff86bda81dfc3" + "reference": "dccb8d251a9017d5994c988b034d3e18aaabf740" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/9bd719e53bce492742bf34948d8ff86bda81dfc3", - "reference": "9bd719e53bce492742bf34948d8ff86bda81dfc3", + "url": "https://api.github.com/repos/symfony/console/zipball/dccb8d251a9017d5994c988b034d3e18aaabf740", + "reference": "dccb8d251a9017d5994c988b034d3e18aaabf740", "shasum": "" }, "require": { @@ -2794,7 +2859,7 @@ "type": "tidelift" } ], - "time": "2022-12-17T11:46:23+00:00" + "time": "2023-01-01T08:32:19+00:00" }, { "name": "symfony/deprecation-contracts", @@ -2870,12 +2935,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "5bbc823adecdae860bb64756d639ecfec17b050a" + "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a", - "reference": "5bbc823adecdae860bb64756d639ecfec17b050a", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", + "reference": "ea208ce43cbb04af6867b4fdddb1bdbf84cc28cb", "shasum": "" }, "require": { @@ -2891,7 +2956,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -2929,7 +2994,7 @@ "portable" ], "support": { - "source": "https://github.com/symfony/polyfill-ctype/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-ctype/tree/main" }, "funding": [ { @@ -2945,7 +3010,7 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-01-26T09:26:14+00:00" }, { "name": "symfony/polyfill-intl-grapheme", @@ -2953,12 +3018,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "511a08c03c1960e08a883f4cffcacd219b758354" + "reference": "875e90aeea2777b6f135677f618529449334a612" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/511a08c03c1960e08a883f4cffcacd219b758354", - "reference": "511a08c03c1960e08a883f4cffcacd219b758354", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/875e90aeea2777b6f135677f618529449334a612", + "reference": "875e90aeea2777b6f135677f618529449334a612", "shasum": "" }, "require": { @@ -2971,7 +3036,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3011,7 +3076,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/main" }, "funding": [ { @@ -3027,7 +3092,7 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-01-26T09:26:14+00:00" }, { "name": "symfony/polyfill-intl-normalizer", @@ -3035,12 +3100,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "19bd1e4fcd5b91116f14d8533c57831ed00571b6" + "reference": "8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/19bd1e4fcd5b91116f14d8533c57831ed00571b6", - "reference": "19bd1e4fcd5b91116f14d8533c57831ed00571b6", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92", + "reference": "8c4ad05dd0120b6a53c1ca374dca2ad0a1c4ed92", "shasum": "" }, "require": { @@ -3053,7 +3118,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3096,7 +3161,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/main" }, "funding": [ { @@ -3112,7 +3177,7 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-01-26T09:26:14+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -3120,12 +3185,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534" + "reference": "fd9e963bb80ccbf5d83ce813f9058aacc67cdb98" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534", - "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/fd9e963bb80ccbf5d83ce813f9058aacc67cdb98", + "reference": "fd9e963bb80ccbf5d83ce813f9058aacc67cdb98", "shasum": "" }, "require": { @@ -3141,7 +3206,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3180,7 +3245,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/main" }, "funding": [ { @@ -3196,7 +3261,7 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-01-26T09:26:14+00:00" }, { "name": "symfony/polyfill-php73", @@ -3204,12 +3269,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "9e8ecb5f92152187c4799efd3c96b78ccab18ff9" + "reference": "fe2f306d1d9d346a7fee353d0d5012e401e984b5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/9e8ecb5f92152187c4799efd3c96b78ccab18ff9", - "reference": "9e8ecb5f92152187c4799efd3c96b78ccab18ff9", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fe2f306d1d9d346a7fee353d0d5012e401e984b5", + "reference": "fe2f306d1d9d346a7fee353d0d5012e401e984b5", "shasum": "" }, "require": { @@ -3219,7 +3284,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3260,7 +3325,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php73/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-php73/tree/main" }, "funding": [ { @@ -3276,7 +3341,7 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-01-26T09:26:14+00:00" }, { "name": "symfony/polyfill-php80", @@ -3284,12 +3349,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936" + "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936", - "reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/6caa57379c4aec19c0a12a38b59b26487dcfe4b5", + "reference": "6caa57379c4aec19c0a12a38b59b26487dcfe4b5", "shasum": "" }, "require": { @@ -3299,7 +3364,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "1.27-dev" + "dev-main": "1.28-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3344,7 +3409,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.27.0" + "source": "https://github.com/symfony/polyfill-php80/tree/main" }, "funding": [ { @@ -3360,7 +3425,7 @@ "type": "tidelift" } ], - "time": "2022-11-03T14:55:06+00:00" + "time": "2023-01-26T09:26:14+00:00" }, { "name": "symfony/service-contracts", @@ -3454,12 +3519,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "145702685e0d12f81d755c71127bfff7582fdd36" + "reference": "295ef1f76d8afa41f63470f8c67e2ad4104c1abe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/145702685e0d12f81d755c71127bfff7582fdd36", - "reference": "145702685e0d12f81d755c71127bfff7582fdd36", + "url": "https://api.github.com/repos/symfony/string/zipball/295ef1f76d8afa41f63470f8c67e2ad4104c1abe", + "reference": "295ef1f76d8afa41f63470f8c67e2ad4104c1abe", "shasum": "" }, "require": { @@ -3470,13 +3535,13 @@ "symfony/polyfill-mbstring": "~1.0" }, "conflict": { - "symfony/translation-contracts": "<2.0" + "symfony/translation-contracts": "<2.5" }, "require-dev": { "symfony/error-handler": "^5.4|^6.0", "symfony/http-client": "^5.4|^6.0", "symfony/intl": "^6.2", - "symfony/translation-contracts": "^2.0|^3.0", + "symfony/translation-contracts": "^2.5|^3.0", "symfony/var-exporter": "^5.4|^6.0" }, "type": "library", @@ -3516,7 +3581,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/6.2" + "source": "https://github.com/symfony/string/tree/6.3" }, "funding": [ { @@ -3532,7 +3597,7 @@ "type": "tidelift" } ], - "time": "2022-11-30T17:13:47+00:00" + "time": "2023-01-13T09:23:11+00:00" }, { "name": "theseer/tokenizer", @@ -3854,6 +3919,9 @@ "ext-fileinfo": "*", "ext-zlib": "*", "ext-zstd": "*", + "ext-brotli": "*", + "ext-lz4": "*", + "ext-snappy": "*", "php": ">=8.0" }, "platform-dev": [], diff --git a/src/Storage/Compression/Algorithms/Brotli.php b/src/Storage/Compression/Algorithms/Brotli.php index cbc00612..e82c49cc 100644 --- a/src/Storage/Compression/Algorithms/Brotli.php +++ b/src/Storage/Compression/Algorithms/Brotli.php @@ -67,7 +67,7 @@ public function useFontMode(): void * * Allow values from 0 up to a current max of 11. * - * @param int $level + * @param int $level * @return void */ public function setLevel(int $level): void @@ -83,11 +83,10 @@ public function setLevel(int $level): void /** * Compress. * - * @param string $data - * + * @param string $data * @return string */ - public function compress(string $data):string + public function compress(string $data): string { return \brotli_compress($data, $this->getLevel(), $this->mode); } @@ -95,11 +94,10 @@ public function compress(string $data):string /** * Decompress. * - * @param string $data - * + * @param string $data * @return string */ - public function decompress(string $data):string + public function decompress(string $data): string { return \brotli_uncompress($data); } diff --git a/src/Storage/Compression/Algorithms/GZIP.php b/src/Storage/Compression/Algorithms/GZIP.php index 1dc29611..e047a266 100644 --- a/src/Storage/Compression/Algorithms/GZIP.php +++ b/src/Storage/Compression/Algorithms/GZIP.php @@ -22,11 +22,10 @@ public function getName(): string * * @see http://php.net/manual/en/function.gzencode.php * - * @param string $data - * + * @param string $data * @return string */ - public function compress(string $data):string + public function compress(string $data): string { return \gzencode($data); } @@ -34,11 +33,10 @@ public function compress(string $data):string /** * Decompress. * - * @param string $data - * + * @param string $data * @return string */ - public function decompress(string $data):string + public function decompress(string $data): string { return \gzdecode($data); } diff --git a/src/Storage/Compression/Algorithms/LZ4.php b/src/Storage/Compression/Algorithms/LZ4.php index 31001e5e..aa9da050 100644 --- a/src/Storage/Compression/Algorithms/LZ4.php +++ b/src/Storage/Compression/Algorithms/LZ4.php @@ -34,7 +34,7 @@ public function getLevel(): int * * Allow values from 0 up to a current max of 12. * - * @param int $level + * @param int $level * @return void */ public function setLevel(int $level): void @@ -58,8 +58,7 @@ public function getName(): string /** * Compress. * - * @param string $data - * + * @param string $data * @return string */ public function compress(string $data): string @@ -70,8 +69,7 @@ public function compress(string $data): string /** * Decompress. * - * @param string $data - * + * @param string $data * @return string */ public function decompress(string $data): string diff --git a/src/Storage/Compression/Algorithms/Snappy.php b/src/Storage/Compression/Algorithms/Snappy.php index a72d95e4..32af571f 100644 --- a/src/Storage/Compression/Algorithms/Snappy.php +++ b/src/Storage/Compression/Algorithms/Snappy.php @@ -17,11 +17,10 @@ public function getName(): string /** * Compress. * - * @param string $data - * + * @param string $data * @return string */ - public function compress(string $data):string + public function compress(string $data): string { return \snappy_compress($data); } @@ -29,11 +28,10 @@ public function compress(string $data):string /** * Decompress. * - * @param string $data - * + * @param string $data * @return string */ - public function decompress(string $data):string + public function decompress(string $data): string { return \snappy_uncompress($data); } diff --git a/src/Storage/Compression/Algorithms/Zstd.php b/src/Storage/Compression/Algorithms/Zstd.php index 98451af0..3e2ddf49 100644 --- a/src/Storage/Compression/Algorithms/Zstd.php +++ b/src/Storage/Compression/Algorithms/Zstd.php @@ -34,7 +34,7 @@ public function getLevel(): int * * Allow values from 1 up to a current max of 22. * - * @param int $level + * @param int $level * @return void */ public function setLevel(int $level): void @@ -58,8 +58,7 @@ public function getName(): string /** * Compress. * - * @param string $data - * + * @param string $data * @return string */ public function compress(string $data): string @@ -70,8 +69,7 @@ public function compress(string $data): string /** * Decompress. * - * @param string $data - * + * @param string $data * @return string */ public function decompress(string $data): string diff --git a/src/Storage/Compression/Compression.php b/src/Storage/Compression/Compression.php index 5654ec2b..8eda71f4 100644 --- a/src/Storage/Compression/Compression.php +++ b/src/Storage/Compression/Compression.php @@ -13,14 +13,12 @@ abstract public function getName(): string; /** * @param $data - * * @return string */ abstract public function compress(string $data); /** * @param $data - * * @return string */ abstract public function decompress(string $data); diff --git a/src/Storage/Device.php b/src/Storage/Device.php index 0f2da5bc..3756e97e 100644 --- a/src/Storage/Device.php +++ b/src/Storage/Device.php @@ -2,8 +2,6 @@ namespace Utopia\Storage; -use Exception; - abstract class Device { /** @@ -47,9 +45,8 @@ abstract public function getRoot(): string; * * Each device hold a complex directory structure that is being build in this method. * - * @param string $filename - * @param string $prefix - * + * @param string $filename + * @param string $prefix * @return string */ abstract public function getPath(string $filename, string $prefix = null): string; @@ -60,24 +57,22 @@ abstract public function getPath(string $filename, string $prefix = null): strin * Upload a file to desired destination in the selected disk * return number of chunks uploaded or 0 if it fails. * - * @param string $source - * @param string $path - * @param int $chunk - * @param int $chunks - * @param array $metadata - * - * @throws \Exception - * + * @param string $source + * @param string $path + * @param int $chunk + * @param int $chunks + * @param array $metadata * @return int + * + * @throws \Exception */ abstract public function upload(string $source, string $path, int $chunk = 1, int $chunks = 1, array &$metadata = []): int; /** * Abort Chunked Upload - * - * @param string $path - * @param string $extra - * + * + * @param string $path + * @param string $extra * @return bool */ abstract public function abort(string $path, string $extra = ''): bool; @@ -85,10 +80,9 @@ abstract public function abort(string $path, string $extra = ''): bool; /** * Read file by given path. * - * @param string $path - * @param int $offset - * @param int $length - * + * @param string $path + * @param int $offset + * @param int $length * @return string */ abstract public function read(string $path, int $offset = 0, int $length = null): string; @@ -96,9 +90,8 @@ abstract public function read(string $path, int $offset = 0, int $length = null) /** * Write file by given path. * - * @param string $path - * @param string $data - * + * @param string $path + * @param string $data * @return bool */ abstract public function write(string $path, string $data, string $contentType): bool; @@ -108,9 +101,8 @@ abstract public function write(string $path, string $data, string $contentType): * * @see http://php.net/manual/en/function.filesize.php * - * @param string $source - * @param string $target - * + * @param string $source + * @param string $target * @return bool */ abstract public function move(string $source, string $target): bool; @@ -120,19 +112,17 @@ abstract public function move(string $source, string $target): bool; * * @see http://php.net/manual/en/function.filesize.php * - * @param string $path - * @param bool $recursive - * + * @param string $path + * @param bool $recursive * @return bool */ abstract public function delete(string $path, bool $recursive = false): bool; - + /** * Delete files in given path, path must be a directory. return true on success and false on failure. * * - * @param string $path - * + * @param string $path * @return bool */ abstract public function deletePath(string $path): bool; @@ -140,8 +130,7 @@ abstract public function deletePath(string $path): bool; /** * Check if file exists * - * @param string $path - * + * @param string $path * @return bool */ abstract public function exists(string $path): bool; @@ -152,7 +141,6 @@ abstract public function exists(string $path): bool; * @see http://php.net/manual/en/function.filesize.php * * @param $path - * * @return int */ abstract public function getFileSize(string $path): int; @@ -163,7 +151,6 @@ abstract public function getFileSize(string $path): int; * @see http://php.net/manual/en/function.mime-content-type.php * * @param $path - * * @return string */ abstract public function getFileMimeType(string $path): string; @@ -174,7 +161,6 @@ abstract public function getFileMimeType(string $path): string; * @see http://php.net/manual/en/function.md5-file.php * * @param $path - * * @return string */ abstract public function getFileHash(string $path): string; @@ -185,7 +171,6 @@ abstract public function getFileHash(string $path): string; * Returns true on success or if the directory already exists and false on error * * @param $path - * * @return bool */ abstract public function createDirectory(string $path): bool; @@ -198,7 +183,6 @@ abstract public function createDirectory(string $path): bool; * Based on http://www.jonasjohn.de/snippets/php/dir-size.htm * * @param $path - * * @return int */ abstract public function getDirectorySize(string $path): int; @@ -228,24 +212,26 @@ abstract public function getPartitionTotalSpace(): float; * * Reference https://www.php.net/manual/en/function.realpath.php#84012 * - * @param string $path - * + * @param string $path * @return string */ public function getAbsolutePath(string $path): string { - $path = str_replace(array('/', '\\'), DIRECTORY_SEPARATOR, $path); + $path = str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $path); $parts = array_filter(explode(DIRECTORY_SEPARATOR, $path), 'strlen'); - $absolutes = array(); + $absolutes = []; foreach ($parts as $part) { - if ('.' == $part) continue; + if ('.' == $part) { + continue; + } if ('..' == $part) { array_pop($absolutes); } else { $absolutes[] = $part; } } - return DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $absolutes); + + return DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $absolutes); } } diff --git a/src/Storage/Device/Backblaze.php b/src/Storage/Device/Backblaze.php index d5bf6174..7420098e 100644 --- a/src/Storage/Device/Backblaze.php +++ b/src/Storage/Device/Backblaze.php @@ -2,37 +2,40 @@ namespace Utopia\Storage\Device; -use Utopia\Storage\Device\S3; use Utopia\Storage\Storage; class Backblaze extends S3 { /** * Region constants - * + * * (Technically, these are clusters. There are two Backblaze regions, * US West and EU Central.) */ const US_WEST_000 = 'us-west-000'; + const US_WEST_001 = 'us-west-001'; + const US_WEST_002 = 'us-west-002'; + const US_WEST_004 = 'us-west-004'; + const EU_CENTRAL_003 = 'eu-central-003'; /** * Backblaze Constructor * - * @param string $root - * @param string $accessKey - * @param string $secretKey - * @param string $bucket - * @param string $region - * @param string $acl + * @param string $root + * @param string $accessKey + * @param string $secretKey + * @param string $bucket + * @param string $region + * @param string $acl */ public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $region = self::US_WEST_004, string $acl = self::ACL_PRIVATE) { parent::__construct($root, $accessKey, $secretKey, $bucket, $region, $acl); - $this->headers['host'] = $bucket . '.' . 's3' . '.' . $region . '.backblazeb2.com'; + $this->headers['host'] = $bucket.'.'.'s3'.'.'.$region.'.backblazeb2.com'; } /** diff --git a/src/Storage/Device/DOSpaces.php b/src/Storage/Device/DOSpaces.php index 20bdc081..853c2dfc 100644 --- a/src/Storage/Device/DOSpaces.php +++ b/src/Storage/Device/DOSpaces.php @@ -2,36 +2,39 @@ namespace Utopia\Storage\Device; -use Utopia\Storage\Device\S3; use Utopia\Storage\Storage; class DOSpaces extends S3 { /** * Regions constants - * */ const SGP1 = 'sgp1'; + const NYC3 = 'nyc3'; + const FRA1 = 'fra1'; + const SFO2 = 'sfo2'; + const SFO3 = 'sfo3'; + const AMS3 = 'AMS3'; /** * DOSpaces Constructor * - * @param string $root - * @param string $accessKey - * @param string $secretKey - * @param string $bucket - * @param string $region - * @param string $acl + * @param string $root + * @param string $accessKey + * @param string $secretKey + * @param string $bucket + * @param string $region + * @param string $acl */ public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $region = self::NYC3, string $acl = self::ACL_PRIVATE) { parent::__construct($root, $accessKey, $secretKey, $bucket, $region, $acl); - $this->headers['host'] = $bucket . '.' . $region . '.digitaloceanspaces.com'; + $this->headers['host'] = $bucket.'.'.$region.'.digitaloceanspaces.com'; } /** diff --git a/src/Storage/Device/Linode.php b/src/Storage/Device/Linode.php index b96735bb..fd8c79b8 100644 --- a/src/Storage/Device/Linode.php +++ b/src/Storage/Device/Linode.php @@ -2,30 +2,30 @@ namespace Utopia\Storage\Device; -use Utopia\Storage\Device\S3; use Utopia\Storage\Storage; class Linode extends S3 { /** * Regions constants - * */ - const EU_CENTRAL_1='eu-central-1'; - const US_SOUTHEAST_1='us-southeast-1'; - const US_EAST_1='us-east-1'; - const AP_SOUTH_1='ap-south-1'; + const EU_CENTRAL_1 = 'eu-central-1'; + + const US_SOUTHEAST_1 = 'us-southeast-1'; + + const US_EAST_1 = 'us-east-1'; + const AP_SOUTH_1 = 'ap-south-1'; /** * Object Storage Constructor * - * @param string $root - * @param string $accessKey - * @param string $secretKey - * @param string $bucket - * @param string $region - * @param string $acl + * @param string $root + * @param string $accessKey + * @param string $secretKey + * @param string $bucket + * @param string $region + * @param string $acl */ public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $region = self::EU_CENTRAL_1, string $acl = self::ACL_PRIVATE) { diff --git a/src/Storage/Device/Local.php b/src/Storage/Device/Local.php index a1f885b2..1f44a668 100644 --- a/src/Storage/Device/Local.php +++ b/src/Storage/Device/Local.php @@ -8,7 +8,6 @@ class Local extends Device { - /** * @var string */ @@ -17,7 +16,7 @@ class Local extends Device /** * Local constructor. * - * @param string $root + * @param string $root */ public function __construct(string $root = '') { @@ -57,14 +56,13 @@ public function getRoot(): string } /** - * @param string $filename - * @param string|null $prefix - * + * @param string $filename + * @param string|null $prefix * @return string */ public function getPath(string $filename, string $prefix = null): string { - return $this->getAbsolutePath($this->getRoot() . DIRECTORY_SEPARATOR . $filename); + return $this->getAbsolutePath($this->getRoot().DIRECTORY_SEPARATOR.$filename); } /** @@ -73,131 +71,133 @@ public function getPath(string $filename, string $prefix = null): string * Upload a file to desired destination in the selected disk. * return number of chunks uploaded or 0 if it fails. * - * @param string $source - * @param string $path - * @param int $chunk - * @param int $chunks - * @param array $metadata + * @param string $source + * @param string $path + * @param int $chunk + * @param int $chunks + * @param array $metadata + * @return int * * @throws \Exception - * - * @return int */ public function upload(string $source, string $path, int $chunk = 1, int $chunks = 1, array &$metadata = []): int { - if (!\file_exists(\dirname($path))) { // Checks if directory path to file exists - if (!@\mkdir(\dirname($path), 0755, true)) { - throw new Exception('Can\'t create directory: ' . \dirname($path)); + if (! \file_exists(\dirname($path))) { // Checks if directory path to file exists + if (! @\mkdir(\dirname($path), 0755, true)) { + throw new Exception('Can\'t create directory: '.\dirname($path)); } } //move_uploaded_file() verifies the file is not tampered with - if($chunks === 1) { - if (!\move_uploaded_file($source, $path)) { - throw new Exception('Can\'t upload file ' . $path); + if ($chunks === 1) { + if (! \move_uploaded_file($source, $path)) { + throw new Exception('Can\'t upload file '.$path); } + return $chunks; } - $tmp = \dirname($path) . DIRECTORY_SEPARATOR . 'tmp_' . \basename($path) . DIRECTORY_SEPARATOR . \basename($path) . '_chunks.log'; + $tmp = \dirname($path).DIRECTORY_SEPARATOR.'tmp_'.\basename($path).DIRECTORY_SEPARATOR.\basename($path).'_chunks.log'; - if (!\file_exists(\dirname($tmp))) { // Checks if directory path to file exists - if (!@\mkdir(\dirname($tmp), 0755, true)) { - throw new Exception('Can\'t create directory: ' . \dirname($tmp)); + if (! \file_exists(\dirname($tmp))) { // Checks if directory path to file exists + if (! @\mkdir(\dirname($tmp), 0755, true)) { + throw new Exception('Can\'t create directory: '.\dirname($tmp)); } } - if(!file_put_contents($tmp, "$chunk\n", FILE_APPEND)) { - throw new Exception('Can\'t write chunk log ' . $tmp); + if (! file_put_contents($tmp, "$chunk\n", FILE_APPEND)) { + throw new Exception('Can\'t write chunk log '.$tmp); } $chunkLogs = file($tmp); - if(!$chunkLogs) { - throw new Exception('Unable to read chunk log ' . $tmp); + if (! $chunkLogs) { + throw new Exception('Unable to read chunk log '.$tmp); } $chunksReceived = count(file($tmp)); - if(!\rename($source, dirname($tmp) . DIRECTORY_SEPARATOR . pathinfo($path, PATHINFO_FILENAME) . '.part.' . $chunk)) { - throw new Exception('Failed to write chunk ' . $chunk); + if (! \rename($source, dirname($tmp).DIRECTORY_SEPARATOR.pathinfo($path, PATHINFO_FILENAME).'.part.'.$chunk)) { + throw new Exception('Failed to write chunk '.$chunk); } - + if ($chunks === $chunksReceived) { - for($i = 1; $i <= $chunks; $i++) { - $part = dirname($tmp) . DIRECTORY_SEPARATOR . pathinfo($path, PATHINFO_FILENAME) . '.part.'. $i; + for ($i = 1; $i <= $chunks; $i++) { + $part = dirname($tmp).DIRECTORY_SEPARATOR.pathinfo($path, PATHINFO_FILENAME).'.part.'.$i; $data = file_get_contents($part); - if(!$data) { - throw new Exception('Failed to read chunk ' . $part); + if (! $data) { + throw new Exception('Failed to read chunk '.$part); } - if(!file_put_contents($path, $data, FILE_APPEND)) { - throw new Exception('Failed to append chunk ' . $part); + if (! file_put_contents($path, $data, FILE_APPEND)) { + throw new Exception('Failed to append chunk '.$part); } \unlink($part); } \unlink($tmp); + return $chunksReceived; } + return $chunksReceived; } /** * Abort Chunked Upload - * - * @param string $path - * @param string $extra - * + * + * @param string $path + * @param string $extra * @return bool */ public function abort(string $path, string $extra = ''): bool { - if(file_exists($path)) { + if (file_exists($path)) { \unlink($path); } - $tmp = \dirname($path) . DIRECTORY_SEPARATOR . 'tmp_' . \basename($path) . DIRECTORY_SEPARATOR; + $tmp = \dirname($path).DIRECTORY_SEPARATOR.'tmp_'.\basename($path).DIRECTORY_SEPARATOR; - if (!\file_exists(\dirname($tmp))) { // Checks if directory path to file exists - throw new Exception('File doesn\'t exist: ' . \dirname($path)); + if (! \file_exists(\dirname($tmp))) { // Checks if directory path to file exists + throw new Exception('File doesn\'t exist: '.\dirname($path)); } - $files = \glob($tmp . '*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned + $files = \glob($tmp.'*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned foreach ($files as $file) { $this->delete($file, true); } - return \rmdir ($tmp); + return \rmdir($tmp); } /** * Read file by given path. * - * @param string $path + * @param string $path * @param int offset - * @param int|null $length + * @param int|null $length * @return string + * * @throws Exception */ public function read(string $path, int $offset = 0, int $length = null): string { - if(!$this->exists($path)) { + if (! $this->exists($path)) { throw new Exception('File Not Found'); } + return \file_get_contents($path, use_include_path: false, context: null, offset: $offset, length: $length); } /** * Write file by given path. * - * @param string $path - * @param string $data - * @param string $contentType - * + * @param string $path + * @param string $data + * @param string $contentType * @return bool */ public function write(string $path, string $data, string $contentType = ''): bool { - if (!\file_exists(\dirname($path))) { // Checks if directory path to file exists - if (!@\mkdir(\dirname($path), 0755, true)) { - throw new Exception('Can\'t create directory ' . \dirname($path)); + if (! \file_exists(\dirname($path))) { // Checks if directory path to file exists + if (! @\mkdir(\dirname($path), 0755, true)) { + throw new Exception('Can\'t create directory '.\dirname($path)); } } @@ -209,16 +209,15 @@ public function write(string $path, string $data, string $contentType = ''): boo * * @see http://php.net/manual/en/function.filesize.php * - * @param string $source - * @param string $target - * + * @param string $source + * @param string $target * @return bool */ public function move(string $source, string $target): bool { - if (!\file_exists(\dirname($target))) { // Checks if directory path to file exists - if (!@\mkdir(\dirname($target), 0755, true)) { - throw new Exception('Can\'t create directory ' . \dirname($target)); + if (! \file_exists(\dirname($target))) { // Checks if directory path to file exists + if (! @\mkdir(\dirname($target), 0755, true)) { + throw new Exception('Can\'t create directory '.\dirname($target)); } } @@ -234,15 +233,14 @@ public function move(string $source, string $target): bool * * @see http://php.net/manual/en/function.filesize.php * - * @param string $path - * @param bool $recursive - * + * @param string $path + * @param bool $recursive * @return bool */ public function delete(string $path, bool $recursive = false): bool { if (\is_dir($path) && $recursive) { - $files = \glob($path . '*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned + $files = \glob($path.'*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned foreach ($files as $file) { $this->delete($file, true); @@ -259,22 +257,22 @@ public function delete(string $path, bool $recursive = false): bool /** * Delete files in given path, path must be a directory. Return true on success and false on failure. * - * @param string $path - * + * @param string $path * @return bool */ public function deletePath(string $path): bool { - $path = realpath($this->getRoot() . DIRECTORY_SEPARATOR . $path); + $path = realpath($this->getRoot().DIRECTORY_SEPARATOR.$path); if (\is_dir($path)) { - $files = \glob($path . '*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned + $files = \glob($path.'*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned foreach ($files as $file) { $this->delete($file, true); } \rmdir($path); + return true; } @@ -284,8 +282,7 @@ public function deletePath(string $path): bool /** * Check if file exists * - * @param string $path - * + * @param string $path * @return bool */ public function exists(string $path): bool @@ -298,8 +295,7 @@ public function exists(string $path): bool * * @see http://php.net/manual/en/function.filesize.php * - * @param string $path - * + * @param string $path * @return int */ public function getFileSize(string $path): int @@ -312,8 +308,7 @@ public function getFileSize(string $path): int * * @see http://php.net/manual/en/function.mime-content-type.php * - * @param string $path - * + * @param string $path * @return string */ public function getFileMimeType(string $path): string @@ -326,8 +321,7 @@ public function getFileMimeType(string $path): string * * @see http://php.net/manual/en/function.md5-file.php * - * @param string $path - * + * @param string $path * @return string */ public function getFileHash(string $path): string @@ -341,13 +335,12 @@ public function getFileHash(string $path): string * Returns true on success or if the directory already exists and false on error * * @param $path - * * @return bool */ public function createDirectory(string $path): bool { - if (!\file_exists($path)) { - if (!@\mkdir($path, 0755, true)) { + if (! \file_exists($path)) { + if (! @\mkdir($path, 0755, true)) { return false; } } @@ -362,8 +355,7 @@ public function createDirectory(string $path): bool * * Based on http://www.jonasjohn.de/snippets/php/dir-size.htm * - * @param string $path - * + * @param string $path * @return int */ public function getDirectorySize(string $path): int @@ -372,7 +364,7 @@ public function getDirectorySize(string $path): int $directory = \opendir($path); - if (!$directory) { + if (! $directory) { return -1; } @@ -383,10 +375,10 @@ public function getDirectorySize(string $path): int } // Go recursive down, or add the file size - if (\is_dir($path . $file)) { - $size += $this->getDirectorySize($path . $file . DIRECTORY_SEPARATOR); + if (\is_dir($path.$file)) { + $size += $this->getDirectorySize($path.$file.DIRECTORY_SEPARATOR); } else { - $size += \filesize($path . $file); + $size += \filesize($path.$file); } } diff --git a/src/Storage/Device/S3.php b/src/Storage/Device/S3.php index b5fc3503..7637cd49 100644 --- a/src/Storage/Device/S3.php +++ b/src/Storage/Device/S3.php @@ -9,50 +9,85 @@ class S3 extends Device { const METHOD_GET = 'GET'; + const METHOD_POST = 'POST'; + const METHOD_PUT = 'PUT'; + const METHOD_PATCH = 'PATCH'; + const METHOD_DELETE = 'DELETE'; + const METHOD_HEAD = 'HEAD'; + const METHOD_OPTIONS = 'OPTIONS'; + const METHOD_CONNECT = 'CONNECT'; + const METHOD_TRACE = 'TRACE'; /** * AWS Regions constants */ const US_EAST_1 = 'us-east-1'; + const US_EAST_2 = 'us-east-2'; + const US_WEST_1 = 'us-west-1'; + const US_WEST_2 = 'us-west-2'; + const AF_SOUTH_1 = 'af-south-1'; + const AP_EAST_1 = 'ap-east-1'; + const AP_SOUTH_1 = 'ap-south-1'; + const AP_NORTHEAST_3 = 'ap-northeast-3'; + const AP_NORTHEAST_2 = 'ap-northeast-2'; + const AP_NORTHEAST_1 = 'ap-northeast-1'; + const AP_SOUTHEAST_1 = 'ap-southeast-1'; + const AP_SOUTHEAST_2 = 'ap-southeast-2'; + const CA_CENTRAL_1 = 'ca-central-1'; + const EU_CENTRAL_1 = 'eu-central-1'; + const EU_WEST_1 = 'eu-west-1'; + const EU_SOUTH_1 = 'eu-south-1'; + const EU_WEST_2 = 'eu-west-2'; + const EU_WEST_3 = 'eu-west-3'; + const EU_NORTH_1 = 'eu-north-1'; + const SA_EAST_1 = 'eu-north-1'; + const CN_NORTH_1 = 'cn-north-1'; + const ME_SOUTH_1 = 'me-south-1'; + const CN_NORTHWEST_1 = 'cn-northwest-1'; + const US_GOV_EAST_1 = 'us-gov-east-1'; + const US_GOV_WEST_1 = 'us-gov-west-1'; /** * AWS ACL Flag constants */ const ACL_PRIVATE = 'private'; + const ACL_PUBLIC_READ = 'public-read'; + const ACL_PUBLIC_READ_WRITE = 'public-read-write'; + const ACL_AUTHENTICATED_READ = 'authenticated-read'; /** @@ -102,12 +137,12 @@ class S3 extends Device /** * S3 Constructor * - * @param string $root - * @param string $accessKey - * @param string $secretKey - * @param string $bucket - * @param string $region - * @param string $acl + * @param string $root + * @param string $accessKey + * @param string $secretKey + * @param string $bucket + * @param string $region + * @param string $acl */ public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $region = self::US_EAST_1, string $acl = self::ACL_PRIVATE) { @@ -117,7 +152,7 @@ public function __construct(string $root, string $accessKey, string $secretKey, $this->region = $region; $this->root = $root; $this->acl = $acl; - $this->headers['host'] = $this->bucket . '.s3.' . $this->region . '.amazonaws.com'; + $this->headers['host'] = $this->bucket.'.s3.'.$this->region.'.amazonaws.com'; $this->amzHeaders = []; } @@ -154,14 +189,13 @@ public function getRoot(): string } /** - * @param string $filename - * @param string|null $prefix - * + * @param string $filename + * @param string|null $prefix * @return string */ public function getPath(string $filename, string $prefix = null): string { - return $this->getRoot() . DIRECTORY_SEPARATOR . $filename; + return $this->getRoot().DIRECTORY_SEPARATOR.$filename; } /** @@ -170,15 +204,14 @@ public function getPath(string $filename, string $prefix = null): string * Upload a file to desired destination in the selected disk. * return number of chunks uploaded or 0 if it fails. * - * @param string $source - * @param string $path + * @param string $source + * @param string $path * @param int chunk * @param int chunks - * @param array $metadata + * @param array $metadata + * @return int * * @throws \Exception - * - * @return int */ public function upload(string $source, string $path, int $chunk = 1, int $chunks = 1, array &$metadata = []): int { @@ -199,48 +232,48 @@ public function upload(string $source, string $path, int $chunk = 1, int $chunks if ($metadata['chunks'] == $chunks) { $this->completeMultipartUpload($path, $uploadId, $metadata['parts']); } + return $metadata['chunks']; } /** * Start Multipart Upload - * + * * Initiate a multipart upload and return an upload ID. - * - * @param string $path - * @param string $contentType - * - * @throws \Exception - * + * + * @param string $path + * @param string $contentType * @return string + * + * @throws \Exception */ protected function createMultipartUpload(string $path, string $contentType): string { - $uri = $path !== '' ? '/' . \str_replace(['%2F', '%3F'], ['/', '?'], \rawurlencode($path)) : '/'; + $uri = $path !== '' ? '/'.\str_replace(['%2F', '%3F'], ['/', '?'], \rawurlencode($path)) : '/'; $this->headers['content-md5'] = \base64_encode(md5('', true)); unset($this->amzHeaders['x-amz-content-sha256']); $this->headers['content-type'] = $contentType; $this->amzHeaders['x-amz-acl'] = $this->acl; $response = $this->call(self::METHOD_POST, $uri, '', ['uploads' => '']); + return $response->body['UploadId']; } /** * Upload Part - * - * @param string $source - * @param string $path - * @param int $chunk - * @param string $uploadId - * - * @throws \Exception - * + * + * @param string $source + * @param string $path + * @param int $chunk + * @param string $uploadId * @return string + * + * @throws \Exception */ protected function uploadPart(string $source, string $path, int $chunk, string $uploadId): string { - $uri = $path !== '' ? '/' . \str_replace(['%2F', '%3F'], ['/', '?'], \rawurlencode($path)) : '/'; + $uri = $path !== '' ? '/'.\str_replace(['%2F', '%3F'], ['/', '?'], \rawurlencode($path)) : '/'; $data = \file_get_contents($source); $this->headers['content-type'] = \mime_content_type($source); @@ -250,7 +283,7 @@ protected function uploadPart(string $source, string $path, int $chunk, string $ $response = $this->call(self::METHOD_PUT, $uri, $data, [ 'partNumber' => $chunk, - 'uploadId' => $uploadId + 'uploadId' => $uploadId, ]); return $response->headers['etag']; @@ -258,18 +291,17 @@ protected function uploadPart(string $source, string $path, int $chunk, string $ /** * Complete Multipart Upload - * - * @param string $path - * @param string $uploadId - * @param array $parts - * - * @throws \Exception - * + * + * @param string $path + * @param string $uploadId + * @param array $parts * @return bool + * + * @throws \Exception */ protected function completeMultipartUpload(string $path, string $uploadId, array $parts): bool { - $uri = $path !== '' ? '/' . \str_replace(['%2F', '%3F'], ['/', '?'], \rawurlencode($path)) : '/'; + $uri = $path !== '' ? '/'.\str_replace(['%2F', '%3F'], ['/', '?'], \rawurlencode($path)) : '/'; $body = ''; foreach ($parts as $part) { @@ -280,38 +312,38 @@ protected function completeMultipartUpload(string $path, string $uploadId, array $this->amzHeaders['x-amz-content-sha256'] = \hash('sha256', $body); $this->headers['content-md5'] = \base64_encode(md5($body, true)); $this->call(self::METHOD_POST, $uri, $body, ['uploadId' => $uploadId]); + return true; } /** * Abort Chunked Upload - * - * @param string $path - * @param string $extra - * - * @throws \Exception - * + * + * @param string $path + * @param string $extra * @return bool + * + * @throws \Exception */ public function abort(string $path, string $extra = ''): bool { - $uri = $path !== '' ? '/' . \str_replace(['%2F', '%3F'], ['/', '?'], \rawurlencode($path)) : '/'; + $uri = $path !== '' ? '/'.\str_replace(['%2F', '%3F'], ['/', '?'], \rawurlencode($path)) : '/'; unset($this->headers['content-type']); $this->headers['content-md5'] = \base64_encode(md5('', true)); $this->call(self::METHOD_DELETE, $uri, '', ['uploadId' => $extra]); + return true; } /** * Read file or part of file by given path, offset and length. * - * @param string $path + * @param string $path * @param int offset * @param int length - * - * @throws \Exception - * * @return string + * + * @throws \Exception */ public function read(string $path, int $offset = 0, int $length = null): string { @@ -319,28 +351,28 @@ public function read(string $path, int $offset = 0, int $length = null): string unset($this->amzHeaders['x-amz-content-sha256']); unset($this->headers['content-type']); $this->headers['content-md5'] = \base64_encode(md5('', true)); - $uri = ($path !== '') ? '/' . \str_replace('%2F', '/', \rawurlencode($path)) : '/'; + $uri = ($path !== '') ? '/'.\str_replace('%2F', '/', \rawurlencode($path)) : '/'; if ($length !== null) { $end = $offset + $length - 1; $this->headers['range'] = "bytes=$offset-$end"; } $response = $this->call(self::METHOD_GET, $uri); + return $response->body; } /** * Write file by given path. * - * @param string $path - * @param string $data - * - * @throws \Exception - * + * @param string $path + * @param string $data * @return bool + * + * @throws \Exception */ public function write(string $path, string $data, string $contentType = ''): bool { - $uri = $path !== '' ? '/' . \str_replace(['%2F', '%3F'], ['/', '?'], \rawurlencode($path)) : '/'; + $uri = $path !== '' ? '/'.\str_replace(['%2F', '%3F'], ['/', '?'], \rawurlencode($path)) : '/'; $this->headers['content-type'] = $contentType; $this->headers['content-md5'] = \base64_encode(md5($data, true)); //TODO whould this work well with big file? can we skip it? @@ -357,9 +389,9 @@ public function write(string $path, string $data, string $contentType = ''): boo * * @see http://php.net/manual/en/function.filesize.php * - * @param string $source - * @param string $target - * + * @param string $source + * @param string $target + * * @throw \Exception * * @return bool @@ -380,15 +412,14 @@ public function move(string $source, string $target): bool * * @see http://php.net/manual/en/function.filesize.php * - * @param string $path - * - * @throws \Exception - * + * @param string $path * @return bool + * + * @throws \Exception */ public function delete(string $path, bool $recursive = false): bool { - $uri = ($path !== '') ? '/' . \str_replace('%2F', '/', \rawurlencode($path)) : '/'; + $uri = ($path !== '') ? '/'.\str_replace('%2F', '/', \rawurlencode($path)) : '/'; unset($this->headers['content-type']); unset($this->amzHeaders['x-amz-acl']); @@ -402,16 +433,15 @@ public function delete(string $path, bool $recursive = false): bool /** * Get list of objects in the given path. * - * @param string $path - * - * @throws \Exception - * + * @param string $path * @return array + * + * @throws \Exception */ private function listObjects($prefix = '', $maxKeys = 1000, $continuationToken = '') { $uri = '/'; - $prefix = ltrim($prefix, '/'); /** S3 specific requirement that prefix should never contain a leading slash */ + $prefix = ltrim($prefix, '/'); /** S3 specific requirement that prefix should never contain a leading slash */ $this->headers['content-type'] = 'text/plain'; $this->headers['content-md5'] = \base64_encode(md5('', true)); @@ -420,25 +450,25 @@ private function listObjects($prefix = '', $maxKeys = 1000, $continuationToken = 'prefix' => $prefix, 'max-keys' => $maxKeys, ]; - if (!empty($continuationToken)) { + if (! empty($continuationToken)) { $parameters['continuation-token'] = $continuationToken; } $response = $this->call(self::METHOD_GET, $uri, '', $parameters); + return $response->body; } /** * Delete files in given path, path must be a directory. Return true on success and false on failure. * - * @param string $path - * - * @throws \Exception - * + * @param string $path * @return bool + * + * @throws \Exception */ public function deletePath(string $path): bool { - $path = $this->getRoot() . '/' . $path; + $path = $this->getRoot().'/'.$path; $uri = '/'; $continuationToken = ''; @@ -462,7 +492,7 @@ public function deletePath(string $path): bool $this->amzHeaders['x-amz-content-sha256'] = \hash('sha256', $body); $this->headers['content-md5'] = \base64_encode(md5($body, true)); $this->call(self::METHOD_POST, $uri, $body, ['delete' => '']); - } while (!empty($continuationToken)); + } while (! empty($continuationToken)); return true; } @@ -470,8 +500,7 @@ public function deletePath(string $path): bool /** * Check if file exists * - * @param string $path - * + * @param string $path * @return bool */ public function exists(string $path): bool @@ -490,14 +519,14 @@ public function exists(string $path): bool * * @see http://php.net/manual/en/function.filesize.php * - * @param string $path - * + * @param string $path * @return int */ public function getFileSize(string $path): int { $response = $this->getInfo($path); - return (int)($response['content-length'] ?? 0); + + return (int) ($response['content-length'] ?? 0); } /** @@ -505,13 +534,13 @@ public function getFileSize(string $path): int * * @see http://php.net/manual/en/function.mime-content-type.php * - * @param string $path - * + * @param string $path * @return string */ public function getFileMimeType(string $path): string { $response = $this->getInfo($path); + return $response['content-type'] ?? ''; } @@ -520,14 +549,14 @@ public function getFileMimeType(string $path): string * * @see http://php.net/manual/en/function.md5-file.php * - * @param string $path - * + * @param string $path * @return string */ public function getFileHash(string $path): string { $etag = $this->getInfo($path)['etag'] ?? ''; - return (!empty($etag)) ? substr($etag, 1, -1) : $etag; + + return (! empty($etag)) ? substr($etag, 1, -1) : $etag; } /** @@ -536,7 +565,6 @@ public function getFileHash(string $path): string * Returns true on success or if the directory already exists and false on error * * @param $path - * * @return bool */ public function createDirectory(string $path): bool @@ -552,8 +580,7 @@ public function createDirectory(string $path): bool * * Based on http://www.jonasjohn.de/snippets/php/dir-size.htm * - * @param string $path - * + * @param string $path * @return int */ public function getDirectorySize(string $path): int @@ -587,6 +614,7 @@ public function getPartitionTotalSpace(): float /** * Get file info + * * @return array */ private function getInfo(string $path): array @@ -595,7 +623,7 @@ private function getInfo(string $path): array unset($this->amzHeaders['x-amz-acl']); unset($this->amzHeaders['x-amz-content-sha256']); $this->headers['content-md5'] = \base64_encode(md5('', true)); - $uri = $path !== '' ? '/' . \str_replace('%2F', '/', \rawurlencode($path)) : '/'; + $uri = $path !== '' ? '/'.\str_replace('%2F', '/', \rawurlencode($path)) : '/'; $response = $this->call(self::METHOD_HEAD, $uri); return $response->headers; @@ -603,10 +631,10 @@ private function getInfo(string $path): array /** * Generate the headers for AWS Signature V4 - * @param string $method - * @param string $uri + * + * @param string $method + * @param string $uri * @param array parameters - * * @return string */ private function getSignatureV4(string $method, string $uri, array $parameters = []): string @@ -643,7 +671,7 @@ private function getSignatureV4(string $method, string $uri, array $parameters = $amzPayload[] = $queryString; foreach ($combinedHeaders as $k => $v) { // add header as string to requests - $amzPayload[] = $k . ':' . $v; + $amzPayload[] = $k.':'.$v; } $amzPayload[] = ''; // add a blank entry so we end up with an extra line break @@ -658,11 +686,11 @@ private function getSignatureV4(string $method, string $uri, array $parameters = // stringToSign $stringToSignStr = \implode("\n", [ $algorithm, $this->amzHeaders['x-amz-date'], - \implode('/', $credentialScope), \hash('sha256', $amzPayloadStr) + \implode('/', $credentialScope), \hash('sha256', $amzPayloadStr), ]); // Make Signature - $kSecret = 'AWS4' . $this->secretKey; + $kSecret = 'AWS4'.$this->secretKey; $kDate = \hash_hmac('sha256', $amzDateStamp, $kSecret, true); $kRegion = \hash_hmac('sha256', $region, $kDate, true); $kService = \hash_hmac('sha256', $service, $kRegion, true); @@ -670,29 +698,28 @@ private function getSignatureV4(string $method, string $uri, array $parameters = $signature = \hash_hmac('sha256', \utf8_encode($stringToSignStr), $kSigning); - return $algorithm . ' ' . \implode(',', [ - 'Credential=' . $this->accessKey . '/' . \implode('/', $credentialScope), - 'SignedHeaders=' . \implode(';', \array_keys($combinedHeaders)), - 'Signature=' . $signature, + return $algorithm.' '.\implode(',', [ + 'Credential='.$this->accessKey.'/'.\implode('/', $credentialScope), + 'SignedHeaders='.\implode(';', \array_keys($combinedHeaders)), + 'Signature='.$signature, ]); } /** * Get the S3 response - * - * @param string $method - * @param string $uri - * @param string $data - * @param array $parameters - * - * @throws \Exception * + * @param string $method + * @param string $uri + * @param string $data + * @param array $parameters * @return object + * + * @throws \Exception */ private function call(string $method, string $uri, string $data = '', array $parameters = []) { $uri = $this->getAbsolutePath($uri); - $url = 'https://' . $this->headers['host'] . $uri . '?' . \http_build_query($parameters, '', '&', PHP_QUERY_RFC3986); + $url = 'https://'.$this->headers['host'].$uri.'?'.\http_build_query($parameters, '', '&', PHP_QUERY_RFC3986); $response = new \stdClass; $response->body = ''; $response->headers = []; @@ -706,30 +733,31 @@ private function call(string $method, string $uri, string $data = '', array $par $httpHeaders = []; $this->amzHeaders['x-amz-date'] = \gmdate('Ymd\THis\Z'); - if (!isset($this->amzHeaders['x-amz-content-sha256'])) { + if (! isset($this->amzHeaders['x-amz-content-sha256'])) { $this->amzHeaders['x-amz-content-sha256'] = \hash('sha256', $data); } foreach ($this->amzHeaders as $header => $value) { if (\strlen($value) > 0) { - $httpHeaders[] = $header . ': ' . $value; + $httpHeaders[] = $header.': '.$value; } } $this->headers['date'] = \gmdate('D, d M Y H:i:s T'); foreach ($this->headers as $header => $value) { if (\strlen($value) > 0) { - $httpHeaders[] = $header . ': ' . $value; + $httpHeaders[] = $header.': '.$value; } } - $httpHeaders[] = 'Authorization: ' . $this->getSignatureV4($method, $uri, $parameters); + $httpHeaders[] = 'Authorization: '.$this->getSignatureV4($method, $uri, $parameters); \curl_setopt($curl, CURLOPT_HTTPHEADER, $httpHeaders); \curl_setopt($curl, CURLOPT_HEADER, false); \curl_setopt($curl, CURLOPT_RETURNTRANSFER, false); \curl_setopt($curl, CURLOPT_WRITEFUNCTION, function ($curl, string $data) use ($response) { $response->body .= $data; + return \strlen($data); }); curl_setopt($curl, CURLOPT_HEADERFUNCTION, function ($curl, string $header) use (&$response) { @@ -761,7 +789,7 @@ private function call(string $method, string $uri, string $data = '', array $par $result = \curl_exec($curl); - if (!$result) { + if (! $result) { throw new Exception(\curl_error($curl)); } @@ -785,9 +813,10 @@ private function call(string $method, string $uri, string $data = '', array $par * Sort compare for meta headers * * @internal Used to sort x-amz meta headers - * @param string $a String A - * @param string $b String B - * @return integer + * + * @param string $a String A + * @param string $b String B + * @return int */ private function sortMetaHeadersCmp($a, $b) { diff --git a/src/Storage/Device/Wasabi.php b/src/Storage/Device/Wasabi.php index 22a740f7..dbde5bcb 100644 --- a/src/Storage/Device/Wasabi.php +++ b/src/Storage/Device/Wasabi.php @@ -2,41 +2,47 @@ namespace Utopia\Storage\Device; -use Utopia\Storage\Device\S3; use Utopia\Storage\Storage; class Wasabi extends S3 { /** * Regions constants - * */ - const US_WEST_1='us-west-1'; - const AP_NORTHEAST_1='ap-northeast-1'; - const AP_NORTHEAST_2='ap-northeast-2'; - const EU_CENTRAL_1='eu-central-1'; - const EU_CENTRAL_2='eu-central-2'; - const EU_WEST_1='eu-west-1'; - const EU_WEST_2='eu-west-2'; - const US_CENTRAL_1='us-central-1'; - const US_EAST_1='us-east-1'; - const US_EAST_2='us-east-2'; + const US_WEST_1 = 'us-west-1'; + + const AP_NORTHEAST_1 = 'ap-northeast-1'; + + const AP_NORTHEAST_2 = 'ap-northeast-2'; + + const EU_CENTRAL_1 = 'eu-central-1'; + + const EU_CENTRAL_2 = 'eu-central-2'; + + const EU_WEST_1 = 'eu-west-1'; + + const EU_WEST_2 = 'eu-west-2'; + + const US_CENTRAL_1 = 'us-central-1'; + + const US_EAST_1 = 'us-east-1'; + const US_EAST_2 = 'us-east-2'; /** * Wasabi Constructor * - * @param string $root - * @param string $accessKey - * @param string $secretKey - * @param string $bucket - * @param string $region - * @param string $acl + * @param string $root + * @param string $accessKey + * @param string $secretKey + * @param string $bucket + * @param string $region + * @param string $acl */ public function __construct(string $root, string $accessKey, string $secretKey, string $bucket, string $region = self::EU_CENTRAL_1, string $acl = self::ACL_PRIVATE) { parent::__construct($root, $accessKey, $secretKey, $bucket, $region, $acl); - $this->headers['host'] = $bucket . '.'.'s3'.'.'.$region.'.'.'wasabisys'.'.'.'com'; + $this->headers['host'] = $bucket.'.'.'s3'.'.'.$region.'.'.'wasabisys'.'.'.'com'; } /** diff --git a/src/Storage/Storage.php b/src/Storage/Storage.php index 4af6fcef..cabd18c8 100644 --- a/src/Storage/Storage.php +++ b/src/Storage/Storage.php @@ -6,16 +6,20 @@ class Storage { - /** * Supported devices */ const DEVICE_LOCAL = 'local'; + const DEVICE_S3 = 's3'; + const DEVICE_DO_SPACES = 'dospaces'; + const DEVICE_WASABI = 'wasabi'; + const DEVICE_BACKBLAZE = 'backblaze'; - const DEVICE_LINODE= 'linode'; + + const DEVICE_LINODE = 'linode'; /** * Devices. @@ -31,12 +35,11 @@ class Storage * * Add device by name * - * @param string $name - * @param Device $device + * @param string $name + * @param Device $device + * @return void * * @throws Exception - * - * @return void */ public static function setDevice($name, Device $device): void { @@ -48,15 +51,14 @@ public static function setDevice($name, Device $device): void * * Get device by name * - * @param string $name - * + * @param string $name * @return Device * * @throws Exception */ public static function getDevice($name) { - if (!\array_key_exists($name, self::$devices)) { + if (! \array_key_exists($name, self::$devices)) { throw new Exception('The device "'.$name.'" is not listed'); } @@ -68,8 +70,7 @@ public static function getDevice($name) * * Checks if given storage name is registered or not * - * @param string $name - * + * @param string $name * @return bool */ public static function exists($name) @@ -82,18 +83,17 @@ public static function exists($name) * * Based on: https://stackoverflow.com/a/38659168/2299554 * - * @param int $bytes - * @param int $decimals - * @param string $system - * + * @param int $bytes + * @param int $decimals + * @param string $system * @return string */ public static function human(int $bytes, $decimals = 2, $system = 'metric') { $mod = ($system === 'binary') ? 1024 : 1000; - $units = array( - 'binary' => array( + $units = [ + 'binary' => [ 'B', 'KiB', 'MiB', @@ -103,8 +103,8 @@ public static function human(int $bytes, $decimals = 2, $system = 'metric') 'EiB', 'ZiB', 'YiB', - ), - 'metric' => array( + ], + 'metric' => [ 'B', 'kB', 'MB', @@ -114,10 +114,10 @@ public static function human(int $bytes, $decimals = 2, $system = 'metric') 'EB', 'ZB', 'YB', - ), - ); + ], + ]; - $factor = (int)floor((strlen((string)$bytes) - 1) / 3); + $factor = (int) floor((strlen((string) $bytes) - 1) / 3); return sprintf("%.{$decimals}f%s", $bytes / pow($mod, $factor), $units[$system][$factor]); } diff --git a/src/Storage/Validator/File.php b/src/Storage/Validator/File.php index a0c1e0bc..c8ffe95e 100644 --- a/src/Storage/Validator/File.php +++ b/src/Storage/Validator/File.php @@ -16,8 +16,7 @@ public function getDescription(): string * * TODO think what to do here, currently only used for parameter to be present in SDKs * - * @param mixed $name - * + * @param mixed $name * @return bool */ public function isValid($name): bool diff --git a/src/Storage/Validator/FileExt.php b/src/Storage/Validator/FileExt.php index fcd8de7a..80506c2d 100644 --- a/src/Storage/Validator/FileExt.php +++ b/src/Storage/Validator/FileExt.php @@ -7,9 +7,13 @@ class FileExt extends Validator { const TYPE_JPEG = 'jpeg'; + const TYPE_JPG = 'jpg'; + const TYPE_GIF = 'gif'; + const TYPE_PNG = 'png'; + const TYPE_GZIP = 'gz'; /** @@ -18,8 +22,7 @@ class FileExt extends Validator protected $allowed; /** - * @param array $allowed - * + * @param array $allowed */ public function __construct(array $allowed) { @@ -36,16 +39,15 @@ public function getDescription(): string /** * Check if file extenstion is allowed - * - * @param mixed $filename * + * @param mixed $filename * @return bool */ public function isValid($filename): bool { $ext = pathinfo($filename, PATHINFO_EXTENSION); - - if (!in_array($ext, $this->allowed)) { + + if (! in_array($ext, $this->allowed)) { return false; } diff --git a/src/Storage/Validator/FileName.php b/src/Storage/Validator/FileName.php index 19aae36a..7a1885e8 100644 --- a/src/Storage/Validator/FileName.php +++ b/src/Storage/Validator/FileName.php @@ -17,8 +17,7 @@ public function getDescription(): string /** * The file name can only contain "a-z", "A-Z", "0-9" and "-" and not empty. * - * @param mixed $name - * + * @param mixed $name * @return bool */ public function isValid($name): bool @@ -27,11 +26,11 @@ public function isValid($name): bool return false; } - if (!is_string($name)) { + if (! is_string($name)) { return false; } - if (!\preg_match('/^[a-zA-Z0-9.]+$/', $name)) { + if (! \preg_match('/^[a-zA-Z0-9.]+$/', $name)) { return false; } diff --git a/src/Storage/Validator/FileSize.php b/src/Storage/Validator/FileSize.php index 7f873fc7..e31aa4c6 100644 --- a/src/Storage/Validator/FileSize.php +++ b/src/Storage/Validator/FileSize.php @@ -13,8 +13,8 @@ class FileSize extends Validator /** * Max size in bytes - * - * @param int $max + * + * @param int $max */ public function __construct($max) { @@ -32,16 +32,15 @@ public function getDescription(): string /** * Finds whether a file size is smaller than required limit. * - * @param mixed $fileSize - * + * @param mixed $fileSize * @return bool */ public function isValid($fileSize): bool { - if (!is_int($fileSize)) { + if (! is_int($fileSize)) { return false; } - + if ($fileSize > $this->max) { return false; } diff --git a/src/Storage/Validator/FileType.php b/src/Storage/Validator/FileType.php index 7b607ab5..9385f360 100644 --- a/src/Storage/Validator/FileType.php +++ b/src/Storage/Validator/FileType.php @@ -11,8 +11,11 @@ class FileType extends Validator * File Types Constants. */ const FILE_TYPE_JPEG = 'jpeg'; + const FILE_TYPE_GIF = 'gif'; + const FILE_TYPE_PNG = 'png'; + const FILE_TYPE_GZIP = 'gz'; /** @@ -20,12 +23,12 @@ class FileType extends Validator * * @var array */ - protected $types = array( + protected $types = [ self::FILE_TYPE_JPEG => "\xFF\xD8\xFF", self::FILE_TYPE_GIF => 'GIF', self::FILE_TYPE_PNG => "\x89\x50\x4e\x47\x0d\x0a", - self::FILE_TYPE_GZIP => "application/x-gzip", - ); + self::FILE_TYPE_GZIP => 'application/x-gzip', + ]; /** * @var array @@ -33,14 +36,14 @@ class FileType extends Validator protected $allowed; /** - * @param array $allowed + * @param array $allowed * * @throws Exception */ public function __construct(array $allowed) { foreach ($allowed as $key) { - if (!isset($this->types[$key])) { + if (! isset($this->types[$key])) { throw new Exception('Unknown file mime type'); } } @@ -63,19 +66,18 @@ public function getDescription(): string * * @see http://stackoverflow.com/a/3313196 * - * @param mixed $path - * + * @param mixed $path * @return bool */ public function isValid($path): bool { - if (!\is_readable($path)) { + if (! \is_readable($path)) { return false; } $handle = \fopen($path, 'r'); - if (!$handle) { + if (! $handle) { return false; } diff --git a/src/Storage/Validator/Upload.php b/src/Storage/Validator/Upload.php index 85a1e17f..d3a70918 100644 --- a/src/Storage/Validator/Upload.php +++ b/src/Storage/Validator/Upload.php @@ -17,20 +17,19 @@ public function getDescription(): string /** * Check if a file is a valid upload file * - * @param mixed $path - * + * @param mixed $path * @return bool */ public function isValid($path): bool { - if (!is_string($path)) { + if (! is_string($path)) { return false; } - + if (\is_uploaded_file($path)) { return true; } - + return false; } diff --git a/tests/Storage/Compression/Algorithms/BrotliTest.php b/tests/Storage/Compression/Algorithms/BrotliTest.php index 4aa779f5..04c476d7 100644 --- a/tests/Storage/Compression/Algorithms/BrotliTest.php +++ b/tests/Storage/Compression/Algorithms/BrotliTest.php @@ -3,8 +3,8 @@ namespace Utopia\Tests\Storage\Compression\Algorithms; use InvalidArgumentException; -use Utopia\Storage\Compression\Algorithms\Brotli; use PHPUnit\Framework\TestCase; +use Utopia\Storage\Compression\Algorithms\Brotli; class BrotliTest extends TestCase { @@ -49,7 +49,7 @@ public function testCompressDecompressWithText() public function testCompressDecompressWithLargeText() { - $demo = \file_get_contents(__DIR__ . '/../../../resources/disk-a/lorem.txt'); + $demo = \file_get_contents(__DIR__.'/../../../resources/disk-a/lorem.txt'); $demoSize = mb_strlen($demo, '8bit'); $this->object->setLevel(8); @@ -70,7 +70,7 @@ public function testCompressDecompressWithLargeText() public function testCompressDecompressWithJPGImage() { - $demo = \file_get_contents(__DIR__ . '/../../../resources/disk-a/kitten-1.jpg'); + $demo = \file_get_contents(__DIR__.'/../../../resources/disk-a/kitten-1.jpg'); $demoSize = mb_strlen($demo, '8bit'); $this->object->setLevel(8); @@ -89,7 +89,7 @@ public function testCompressDecompressWithJPGImage() public function testCompressDecompressWithPNGImage() { - $demo = \file_get_contents(__DIR__ . '/../../../resources/disk-b/kitten-1.png'); + $demo = \file_get_contents(__DIR__.'/../../../resources/disk-b/kitten-1.png'); $demoSize = mb_strlen($demo, '8bit'); $this->object->setLevel(8); diff --git a/tests/Storage/Compression/Algorithms/GZIPTest.php b/tests/Storage/Compression/Algorithms/GZIPTest.php index 71e250f9..1f5a8446 100644 --- a/tests/Storage/Compression/Algorithms/GZIPTest.php +++ b/tests/Storage/Compression/Algorithms/GZIPTest.php @@ -2,8 +2,8 @@ namespace Utopia\Tests\Storage\Compression\Algorithms; -use Utopia\Storage\Compression\Algorithms\GZIP; use PHPUnit\Framework\TestCase; +use Utopia\Storage\Compression\Algorithms\GZIP; class GZIPTest extends TestCase { @@ -25,7 +25,7 @@ public function testName() { $this->assertEquals($this->object->getName(), 'gzip'); } - + public function testCompressDecompressWithText() { $demo = 'This is a demo string'; @@ -42,7 +42,7 @@ public function testCompressDecompressWithText() public function testCompressDecompressWithLargeText() { - $demo = \file_get_contents(__DIR__ . '/../../../resources/disk-a/lorem.txt'); + $demo = \file_get_contents(__DIR__.'/../../../resources/disk-a/lorem.txt'); $demoSize = mb_strlen($demo, '8bit'); $data = $this->object->compress($demo); @@ -61,7 +61,7 @@ public function testCompressDecompressWithLargeText() public function testCompressDecompressWithJPGImage() { - $demo = \file_get_contents(__DIR__ . '/../../../resources/disk-a/kitten-1.jpg'); + $demo = \file_get_contents(__DIR__.'/../../../resources/disk-a/kitten-1.jpg'); $demoSize = mb_strlen($demo, '8bit'); $data = $this->object->compress($demo); @@ -69,18 +69,18 @@ public function testCompressDecompressWithJPGImage() $this->assertEquals($demoSize, 599639); $this->assertEquals($dataSize, 599107); - + $this->assertGreaterThan($dataSize, $demoSize); - + $data = $this->object->decompress($data); $dataSize = mb_strlen($data, '8bit'); - + $this->assertEquals($dataSize, 599639); } - + public function testCompressDecompressWithPNGImage() { - $demo = \file_get_contents(__DIR__ . '/../../../resources/disk-b/kitten-1.png'); + $demo = \file_get_contents(__DIR__.'/../../../resources/disk-b/kitten-1.png'); $demoSize = mb_strlen($demo, '8bit'); $data = $this->object->compress($demo); @@ -88,12 +88,12 @@ public function testCompressDecompressWithPNGImage() $this->assertEquals($demoSize, 3038056); $this->assertEquals($dataSize, 3029202); - + $this->assertGreaterThan($dataSize, $demoSize); - + $data = $this->object->decompress($data); $dataSize = mb_strlen($data, '8bit'); - + $this->assertEquals($dataSize, 3038056); } } diff --git a/tests/Storage/Compression/Algorithms/LZ4Test.php b/tests/Storage/Compression/Algorithms/LZ4Test.php index 212b5988..9d66ee85 100644 --- a/tests/Storage/Compression/Algorithms/LZ4Test.php +++ b/tests/Storage/Compression/Algorithms/LZ4Test.php @@ -2,8 +2,8 @@ namespace Utopia\Tests\Compression\Algorithms; -use Utopia\Storage\Compression\Algorithms\LZ4; use PHPUnit\Framework\TestCase; +use Utopia\Storage\Compression\Algorithms\LZ4; class LZ4Test extends TestCase { @@ -39,7 +39,7 @@ public function testCompressDecompressWithText() public function testCompressDecompressWithJPGImage() { - $demo = \file_get_contents(__DIR__ . '/../../../resources/disk-a/kitten-1.jpg'); + $demo = \file_get_contents(__DIR__.'/../../../resources/disk-a/kitten-1.jpg'); $demoSize = \mb_strlen($demo, '8bit'); $data = $this->object->compress($demo); @@ -58,7 +58,7 @@ public function testCompressDecompressWithJPGImage() public function testCompressDecompressWithPNGImage() { - $demo = \file_get_contents(__DIR__ . '/../../../resources/disk-b/kitten-1.png'); + $demo = \file_get_contents(__DIR__.'/../../../resources/disk-b/kitten-1.png'); $demoSize = \mb_strlen($demo, '8bit'); $data = $this->object->compress($demo); diff --git a/tests/Storage/Compression/Algorithms/SnappyTest.php b/tests/Storage/Compression/Algorithms/SnappyTest.php index 72baee3a..3a752e92 100644 --- a/tests/Storage/Compression/Algorithms/SnappyTest.php +++ b/tests/Storage/Compression/Algorithms/SnappyTest.php @@ -2,8 +2,8 @@ namespace Utopia\Tests\Storage\Compression\Algorithms; -use Utopia\Storage\Compression\Algorithms\Snappy; use PHPUnit\Framework\TestCase; +use Utopia\Storage\Compression\Algorithms\Snappy; class SnappyTest extends TestCase { @@ -25,7 +25,7 @@ public function testName() { $this->assertEquals($this->object->getName(), 'snappy'); } - + public function testCompressDecompressWithText() { $demo = 'This is a demo string'; @@ -40,10 +40,10 @@ public function testCompressDecompressWithText() $this->assertEquals($this->object->decompress($data), $demo); } - + public function testCompressDecompressWithJPGImage() { - $demo = \file_get_contents(__DIR__ . '/../../../resources/disk-a/kitten-1.jpg'); + $demo = \file_get_contents(__DIR__.'/../../../resources/disk-a/kitten-1.jpg'); $demoSize = \mb_strlen($demo, '8bit'); $data = $this->object->compress($demo); @@ -51,18 +51,18 @@ public function testCompressDecompressWithJPGImage() $this->assertEquals(599639, $demoSize); $this->assertEquals(599504, $dataSize); - + $this->assertGreaterThan($dataSize, $demoSize); - + $data = $this->object->decompress($data); $dataSize = \mb_strlen($data, '8bit'); - + $this->assertEquals(599639, $dataSize); } - + public function testCompressDecompressWithPNGImage() { - $demo = \file_get_contents(__DIR__ . '/../../../resources/disk-b/kitten-1.png'); + $demo = \file_get_contents(__DIR__.'/../../../resources/disk-b/kitten-1.png'); $demoSize = \mb_strlen($demo, '8bit'); $data = $this->object->compress($demo); @@ -70,9 +70,9 @@ public function testCompressDecompressWithPNGImage() $this->assertEquals(3038056, $demoSize); $this->assertEquals(3038200, $dataSize); - + $this->assertGreaterThan($demoSize, $dataSize); - + $data = $this->object->decompress($data); $dataSize = \mb_strlen($data, '8bit'); diff --git a/tests/Storage/Compression/Algorithms/ZstdTest.php b/tests/Storage/Compression/Algorithms/ZstdTest.php index daadfa5e..488cd290 100644 --- a/tests/Storage/Compression/Algorithms/ZstdTest.php +++ b/tests/Storage/Compression/Algorithms/ZstdTest.php @@ -2,8 +2,8 @@ namespace Utopia\Tests\Storage\Compression\Algorithms; -use Utopia\Storage\Compression\Algorithms\Zstd; use PHPUnit\Framework\TestCase; +use Utopia\Storage\Compression\Algorithms\Zstd; class ZstdTest extends TestCase { @@ -22,7 +22,7 @@ public function testName() { $this->assertEquals($this->object->getName(), 'zstd'); } - + public function testCompressDecompressWithText() { $demo = 'This is a demo string'; @@ -39,7 +39,7 @@ public function testCompressDecompressWithText() public function testCompressDecompressWithLargeText() { - $demo = \file_get_contents(__DIR__ . '/../../../resources/disk-a/lorem.txt'); + $demo = \file_get_contents(__DIR__.'/../../../resources/disk-a/lorem.txt'); $demoSize = mb_strlen($demo, '8bit'); $data = $this->object->compress($demo); @@ -58,7 +58,7 @@ public function testCompressDecompressWithLargeText() public function testCompressDecompressWithJPGImage() { - $demo = \file_get_contents(__DIR__ . '/../../../resources/disk-a/kitten-1.jpg'); + $demo = \file_get_contents(__DIR__.'/../../../resources/disk-a/kitten-1.jpg'); $demoSize = \mb_strlen($demo, '8bit'); $data = $this->object->compress($demo); @@ -66,18 +66,18 @@ public function testCompressDecompressWithJPGImage() $this->assertEquals(599639, $demoSize); $this->assertEquals(599663, $dataSize); - + $this->assertGreaterThan($demoSize, $dataSize); - + $data = $this->object->decompress($data); $dataSize = \mb_strlen($data, '8bit'); - + $this->assertEquals(599639, $dataSize); } - + public function testCompressDecompressWithPNGImage() { - $demo = \file_get_contents(__DIR__ . '/../../../resources/disk-b/kitten-1.png'); + $demo = \file_get_contents(__DIR__.'/../../../resources/disk-b/kitten-1.png'); $demoSize = \mb_strlen($demo, '8bit'); $data = $this->object->compress($demo); @@ -85,12 +85,12 @@ public function testCompressDecompressWithPNGImage() $this->assertEquals(3038056, $demoSize); $this->assertEquals(3038138, $dataSize); - + $this->assertGreaterThan($demoSize, $dataSize); - + $data = $this->object->decompress($data); $dataSize = \mb_strlen($data, '8bit'); - + $this->assertEquals(3038056, $dataSize); } } diff --git a/tests/Storage/Device/BackblazeTest.php b/tests/Storage/Device/BackblazeTest.php index 7ef23ffd..159bcb0f 100644 --- a/tests/Storage/Device/BackblazeTest.php +++ b/tests/Storage/Device/BackblazeTest.php @@ -12,10 +12,9 @@ protected function init(): void $this->root = '/root'; $key = $_SERVER['BACKBLAZE_ACCESS_KEY'] ?? ''; $secret = $_SERVER['BACKBLAZE_SECRET'] ?? ''; - $bucket = "backblaze-demo"; + $bucket = 'backblaze-demo'; $this->object = new Backblaze($this->root, $key, $secret, $bucket, Backblaze::US_WEST_004, Backblaze::ACL_PRIVATE); - } protected function getAdapterName(): string diff --git a/tests/Storage/Device/DOSpacesTest.php b/tests/Storage/Device/DOSpacesTest.php index c795db2e..3eab342a 100644 --- a/tests/Storage/Device/DOSpacesTest.php +++ b/tests/Storage/Device/DOSpacesTest.php @@ -12,10 +12,9 @@ protected function init(): void $this->root = '/root'; $key = $_SERVER['DO_ACCESS_KEY'] ?? ''; $secret = $_SERVER['DO_SECRET'] ?? ''; - $bucket = "utopia-storage-tests"; + $bucket = 'utopia-storage-tests'; $this->object = new DOSpaces($this->root, $key, $secret, $bucket, DOSpaces::NYC3, DOSpaces::ACL_PUBLIC_READ); - } protected function getAdapterName(): string @@ -27,7 +26,7 @@ protected function getAdapterType(): string { return $this->object->getType(); } - + protected function getAdapterDescription(): string { return 'Digitalocean Spaces Storage'; diff --git a/tests/Storage/Device/LinodeTest.php b/tests/Storage/Device/LinodeTest.php index 58a9e2ef..397e62bc 100644 --- a/tests/Storage/Device/LinodeTest.php +++ b/tests/Storage/Device/LinodeTest.php @@ -15,7 +15,6 @@ protected function init(): void $bucket = 'everly-test'; $this->object = new Linode($this->root, $key, $secret, $bucket, Linode::EU_CENTRAL_1, Linode::ACL_PRIVATE); - } protected function getAdapterName(): string diff --git a/tests/Storage/Device/LocalTest.php b/tests/Storage/Device/LocalTest.php index 52faf823..ebaed963 100644 --- a/tests/Storage/Device/LocalTest.php +++ b/tests/Storage/Device/LocalTest.php @@ -2,8 +2,8 @@ namespace Utopia\Tests\Storage\Device; -use Utopia\Storage\Device\Local; use PHPUnit\Framework\TestCase; +use Utopia\Storage\Device\Local; class LocalTest extends TestCase { @@ -14,7 +14,7 @@ class LocalTest extends TestCase public function setUp(): void { - $this->object = new Local(realpath(__DIR__ . '/../../resources/disk-a')); + $this->object = new Local(realpath(__DIR__.'/../../resources/disk-a')); } public function tearDown(): void @@ -23,13 +23,13 @@ public function tearDown(): void public function testPaths() { - $this->assertEquals($this->object->getAbsolutePath('////storage/functions') , '/storage/functions'); - $this->assertEquals($this->object->getAbsolutePath('storage/functions') , '/storage/functions'); - $this->assertEquals($this->object->getAbsolutePath('/storage/functions') , '/storage/functions'); - $this->assertEquals($this->object->getAbsolutePath('//storage///functions//') , '/storage/functions'); - $this->assertEquals($this->object->getAbsolutePath('\\\\\storage\functions') , '/storage/functions'); - $this->assertEquals($this->object->getAbsolutePath('..\\\\\//storage\\//functions') , '/storage/functions'); - $this->assertEquals($this->object->getAbsolutePath('./..\\\\\//storage\\//functions') , '/storage/functions');; + $this->assertEquals($this->object->getAbsolutePath('////storage/functions'), '/storage/functions'); + $this->assertEquals($this->object->getAbsolutePath('storage/functions'), '/storage/functions'); + $this->assertEquals($this->object->getAbsolutePath('/storage/functions'), '/storage/functions'); + $this->assertEquals($this->object->getAbsolutePath('//storage///functions//'), '/storage/functions'); + $this->assertEquals($this->object->getAbsolutePath('\\\\\storage\functions'), '/storage/functions'); + $this->assertEquals($this->object->getAbsolutePath('..\\\\\//storage\\//functions'), '/storage/functions'); + $this->assertEquals($this->object->getAbsolutePath('./..\\\\\//storage\\//functions'), '/storage/functions'); } public function testName() @@ -49,12 +49,12 @@ public function testDescription() public function testRoot() { - $this->assertEquals($this->object->getRoot(), $this->object->getAbsolutePath( __DIR__ . '/../../resources/disk-a')); + $this->assertEquals($this->object->getRoot(), $this->object->getAbsolutePath(__DIR__.'/../../resources/disk-a')); } public function testPath() { - $this->assertEquals($this->object->getPath('image.png'), $this->object->getAbsolutePath(__DIR__ . '/../../resources/disk-a').'/image.png'); + $this->assertEquals($this->object->getPath('image.png'), $this->object->getAbsolutePath(__DIR__.'/../../resources/disk-a').'/image.png'); } public function testWrite() @@ -70,7 +70,7 @@ public function testRead() { $this->assertEquals($this->object->write($this->object->getPath('text-for-read.txt'), 'Hello World'), true); $this->assertEquals($this->object->read($this->object->getPath('text-for-read.txt')), 'Hello World'); - + $this->object->delete($this->object->getPath('text-for-read.txt')); } @@ -105,44 +105,45 @@ public function testDelete() $this->assertEquals(file_exists($this->object->getPath('text-for-delete.txt')), false); $this->assertEquals(is_readable($this->object->getPath('text-for-delete.txt')), false); } - + public function testFileSize() { - $this->assertEquals($this->object->getFileSize(__DIR__ . '/../../resources/disk-a/kitten-1.jpg'), 599639); - $this->assertEquals($this->object->getFileSize(__DIR__ . '/../../resources/disk-a/kitten-2.jpg'), 131958); + $this->assertEquals($this->object->getFileSize(__DIR__.'/../../resources/disk-a/kitten-1.jpg'), 599639); + $this->assertEquals($this->object->getFileSize(__DIR__.'/../../resources/disk-a/kitten-2.jpg'), 131958); } - + public function testFileMimeType() { - $this->assertEquals($this->object->getFileMimeType(__DIR__ . '/../../resources/disk-a/kitten-1.jpg'), 'image/jpeg'); - $this->assertEquals($this->object->getFileMimeType(__DIR__ . '/../../resources/disk-a/kitten-2.jpg'), 'image/jpeg'); - $this->assertEquals($this->object->getFileMimeType(__DIR__ . '/../../resources/disk-b/kitten-1.png'), 'image/png'); - $this->assertEquals($this->object->getFileMimeType(__DIR__ . '/../../resources/disk-b/kitten-2.png'), 'image/png'); + $this->assertEquals($this->object->getFileMimeType(__DIR__.'/../../resources/disk-a/kitten-1.jpg'), 'image/jpeg'); + $this->assertEquals($this->object->getFileMimeType(__DIR__.'/../../resources/disk-a/kitten-2.jpg'), 'image/jpeg'); + $this->assertEquals($this->object->getFileMimeType(__DIR__.'/../../resources/disk-b/kitten-1.png'), 'image/png'); + $this->assertEquals($this->object->getFileMimeType(__DIR__.'/../../resources/disk-b/kitten-2.png'), 'image/png'); } - + public function testFileHash() { - $this->assertEquals($this->object->getFileHash(__DIR__ . '/../../resources/disk-a/kitten-1.jpg'), '7551f343143d2e24ab4aaf4624996b6a'); - $this->assertEquals($this->object->getFileHash(__DIR__ . '/../../resources/disk-a/kitten-2.jpg'), '81702fdeef2e55b1a22617bce4951cb5'); - $this->assertEquals($this->object->getFileHash(__DIR__ . '/../../resources/disk-b/kitten-1.png'), '03010f4f02980521a8fd6213b52ec313'); - $this->assertEquals($this->object->getFileHash(__DIR__ . '/../../resources/disk-b/kitten-2.png'), '8a9ed992b77e4b62b10e3a5c8ed72062'); + $this->assertEquals($this->object->getFileHash(__DIR__.'/../../resources/disk-a/kitten-1.jpg'), '7551f343143d2e24ab4aaf4624996b6a'); + $this->assertEquals($this->object->getFileHash(__DIR__.'/../../resources/disk-a/kitten-2.jpg'), '81702fdeef2e55b1a22617bce4951cb5'); + $this->assertEquals($this->object->getFileHash(__DIR__.'/../../resources/disk-b/kitten-1.png'), '03010f4f02980521a8fd6213b52ec313'); + $this->assertEquals($this->object->getFileHash(__DIR__.'/../../resources/disk-b/kitten-2.png'), '8a9ed992b77e4b62b10e3a5c8ed72062'); } public function testDirectoryCreate() { $directory = uniqid(); - $this->assertTrue($this->object->createDirectory(__DIR__ . "/$directory")); - $this->assertTrue($this->object->exists(__DIR__ . "/$directory")); + $this->assertTrue($this->object->createDirectory(__DIR__."/$directory")); + $this->assertTrue($this->object->exists(__DIR__."/$directory")); } - + public function testDirectorySize() { - $this->assertGreaterThan(0, $this->object->getDirectorySize(__DIR__ . '/../../resources/disk-a/')); - $this->assertGreaterThan(0, $this->object->getDirectorySize(__DIR__ . '/../../resources/disk-b/')); + $this->assertGreaterThan(0, $this->object->getDirectorySize(__DIR__.'/../../resources/disk-a/')); + $this->assertGreaterThan(0, $this->object->getDirectorySize(__DIR__.'/../../resources/disk-b/')); } - public function testPartUpload() { - $source = __DIR__ . '/../../resources/disk-a/large_file.mp4'; + public function testPartUpload() + { + $source = __DIR__.'/../../resources/disk-a/large_file.mp4'; $dest = $this->object->getPath('uploaded.mp4'); $totalSize = $this->object->getFileSize($source); $chunkSize = 2097152; @@ -155,7 +156,7 @@ public function testPartUpload() { $handle = @fopen($source, 'rb'); while ($start < $totalSize) { $contents = fread($handle, $chunkSize); - $op = __DIR__ . '/chunk.part'; + $op = __DIR__.'/chunk.part'; $cc = fopen($op, 'wb'); fwrite($cc, $contents); fclose($cc); @@ -167,11 +168,13 @@ public function testPartUpload() { @fclose($handle); $this->assertEquals(\filesize($source), $this->object->getFileSize($dest)); $this->assertEquals(\md5_file($source), $this->object->getFileHash($dest)); + return $dest; } - public function testAbort() { - $source = __DIR__ . '/../../resources/disk-a/large_file.mp4'; + public function testAbort() + { + $source = __DIR__.'/../../resources/disk-a/large_file.mp4'; $dest = $this->object->getPath('abcduploaded.mp4'); $totalSize = $this->object->getFileSize($source); $chunkSize = 2097152; @@ -183,7 +186,7 @@ public function testAbort() { $handle = @fopen($source, 'rb'); while ($chunk < 3) { // only upload two chunks $contents = fread($handle, $chunkSize); - $op = __DIR__ . '/chunk.part'; + $op = __DIR__.'/chunk.part'; $cc = fopen($op, 'wb'); fwrite($cc, $contents); fclose($cc); @@ -195,7 +198,7 @@ public function testAbort() { @fclose($handle); // using file name with same first four chars - $source = __DIR__ . '/../../resources/disk-a/large_file.mp4'; + $source = __DIR__.'/../../resources/disk-a/large_file.mp4'; $dest1 = $this->object->getPath('abcduploaded2.mp4'); $totalSize = $this->object->getFileSize($source); $chunkSize = 2097152; @@ -207,7 +210,7 @@ public function testAbort() { $handle = @fopen($source, 'rb'); while ($chunk < 3) { // only upload two chunks $contents = fread($handle, $chunkSize); - $op = __DIR__ . '/chunk.part'; + $op = __DIR__.'/chunk.part'; $cc = fopen($op, 'wb'); fwrite($cc, $contents); fclose($cc); @@ -217,7 +220,7 @@ public function testAbort() { fseek($handle, $start); } @fclose($handle); - + $this->assertTrue($this->object->abort($dest)); $this->assertTrue($this->object->abort($dest1)); } @@ -225,19 +228,20 @@ public function testAbort() { /** * @depends testPartUpload */ - public function testPartRead($path) { - $source = __DIR__ . '/../../resources/disk-a/large_file.mp4'; - $chunk = file_get_contents($source, false,null, 0, 500); + public function testPartRead($path) + { + $source = __DIR__.'/../../resources/disk-a/large_file.mp4'; + $chunk = file_get_contents($source, false, null, 0, 500); $readChunk = $this->object->read($path, 0, 500); $this->assertEquals($chunk, $readChunk); $this->object->delete($path); } - + public function testPartitionFreeSpace() { $this->assertGreaterThan(0, $this->object->getPartitionFreeSpace()); } - + public function testPartitionTotalSpace() { $this->assertGreaterThan(0, $this->object->getPartitionTotalSpace()); diff --git a/tests/Storage/Device/S3Test.php b/tests/Storage/Device/S3Test.php index 4f9428b3..d8e05c3b 100644 --- a/tests/Storage/Device/S3Test.php +++ b/tests/Storage/Device/S3Test.php @@ -7,7 +7,6 @@ class S3Test extends S3Base { - protected function init(): void { $this->root = '/root'; @@ -21,7 +20,7 @@ protected function init(): void /** * @return string */ - protected function getAdapterName() : string + protected function getAdapterName(): string { return 'S3 Storage'; } @@ -32,7 +31,7 @@ protected function getAdapterType(): string } protected function getAdapterDescription(): string - { + { return 'S3 Bucket Storage drive for AWS or on premise solution'; } } diff --git a/tests/Storage/S3Base.php b/tests/Storage/S3Base.php index d8450606..dd82daea 100644 --- a/tests/Storage/S3Base.php +++ b/tests/Storage/S3Base.php @@ -7,7 +7,6 @@ abstract class S3Base extends TestCase { - abstract protected function init(): void; /** @@ -24,6 +23,7 @@ abstract protected function getAdapterDescription(): string; * @var S3 */ protected $object = null; + /** * @var string */ @@ -37,10 +37,10 @@ public function setUp(): void private function uploadTestFiles() { - $this->object->upload(__DIR__ . '/../resources/disk-a/kitten-1.jpg', $this->object->getPath('testing/kitten-1.jpg')); - $this->object->upload(__DIR__ . '/../resources/disk-a/kitten-2.jpg', $this->object->getPath('testing/kitten-2.jpg')); - $this->object->upload(__DIR__ . '/../resources/disk-b/kitten-1.png', $this->object->getPath('testing/kitten-1.png')); - $this->object->upload(__DIR__ . '/../resources/disk-b/kitten-2.png', $this->object->getPath('testing/kitten-2.png')); + $this->object->upload(__DIR__.'/../resources/disk-a/kitten-1.jpg', $this->object->getPath('testing/kitten-1.jpg')); + $this->object->upload(__DIR__.'/../resources/disk-a/kitten-2.jpg', $this->object->getPath('testing/kitten-2.jpg')); + $this->object->upload(__DIR__.'/../resources/disk-b/kitten-1.png', $this->object->getPath('testing/kitten-1.png')); + $this->object->upload(__DIR__.'/../resources/disk-b/kitten-2.png', $this->object->getPath('testing/kitten-2.png')); } private function removeTestFiles() @@ -58,7 +58,7 @@ public function tearDown(): void public function testName() { - $this->assertEquals( $this->getAdapterName(), $this->object->getName()); + $this->assertEquals($this->getAdapterName(), $this->object->getName()); } public function testType() @@ -73,12 +73,12 @@ public function testDescription() public function testRoot() { - $this->assertEquals( $this->root, $this->object->getRoot()); + $this->assertEquals($this->root, $this->object->getRoot()); } public function testPath() { - $this->assertEquals($this->root . '/image.png', $this->object->getPath('image.png')); + $this->assertEquals($this->root.'/image.png', $this->object->getPath('image.png')); } public function testWrite() @@ -120,9 +120,10 @@ public function testDelete() $this->assertEquals(true, $this->object->delete($this->object->getPath('text-for-delete.txt'))); } - public function testSVGUpload() { - $this->assertEquals(true, $this->object->upload(__DIR__ . '/../resources/disk-b/appwrite.svg', $this->object->getPath('testing/appwrite.svg'))); - $this->assertEquals(file_get_contents(__DIR__ . '/../resources/disk-b/appwrite.svg'), $this->object->read($this->object->getPath('testing/appwrite.svg'))); + public function testSVGUpload() + { + $this->assertEquals(true, $this->object->upload(__DIR__.'/../resources/disk-b/appwrite.svg', $this->object->getPath('testing/appwrite.svg'))); + $this->assertEquals(file_get_contents(__DIR__.'/../resources/disk-b/appwrite.svg'), $this->object->read($this->object->getPath('testing/appwrite.svg'))); $this->assertEquals(true, $this->object->exists($this->object->getPath('testing/appwrite.svg'))); $this->assertEquals(true, $this->object->delete($this->object->getPath('testing/appwrite.svg'))); } @@ -131,27 +132,26 @@ public function testDeletePath() { // Test Single Object $path = $this->object->getPath('text-for-delete-path.txt'); - $path = str_ireplace($this->object->getRoot(), $this->object->getRoot() . DIRECTORY_SEPARATOR . 'bucket', $path); + $path = str_ireplace($this->object->getRoot(), $this->object->getRoot().DIRECTORY_SEPARATOR.'bucket', $path); $this->assertEquals(true, $this->object->write($path, 'Hello World', 'text/plain')); $this->assertEquals(true, $this->object->exists($path)); $this->assertEquals(true, $this->object->deletePath('bucket')); $this->assertEquals(false, $this->object->exists($path)); - + // Test Multiple Objects $path = $this->object->getPath('text-for-delete-path1.txt'); - $path = str_ireplace($this->object->getRoot(), $this->object->getRoot() . DIRECTORY_SEPARATOR . 'bucket', $path); + $path = str_ireplace($this->object->getRoot(), $this->object->getRoot().DIRECTORY_SEPARATOR.'bucket', $path); $this->assertEquals(true, $this->object->write($path, 'Hello World', 'text/plain')); $this->assertEquals(true, $this->object->exists($path)); $path2 = $this->object->getPath('text-for-delete-path2.txt'); - $path2 = str_ireplace($this->object->getRoot(), $this->object->getRoot() . DIRECTORY_SEPARATOR . 'bucket', $path2); + $path2 = str_ireplace($this->object->getRoot(), $this->object->getRoot().DIRECTORY_SEPARATOR.'bucket', $path2); $this->assertEquals(true, $this->object->write($path2, 'Hello World', 'text/plain')); $this->assertEquals(true, $this->object->exists($path2)); $this->assertEquals(true, $this->object->deletePath('bucket')); $this->assertEquals(false, $this->object->exists($path)); $this->assertEquals(false, $this->object->exists($path2)); - } public function testFileSize() @@ -196,12 +196,13 @@ public function testPartitionTotalSpace() $this->assertEquals(-1, $this->object->getPartitionTotalSpace()); } - public function testPartUpload() { - $source = __DIR__ . '/../resources/disk-a/large_file.mp4'; + public function testPartUpload() + { + $source = __DIR__.'/../resources/disk-a/large_file.mp4'; $dest = $this->object->getPath('uploaded.mp4'); $totalSize = \filesize($source); // AWS S3 requires each part to be at least 5MB except for last part - $chunkSize = 5*1024*1024; + $chunkSize = 5 * 1024 * 1024; $chunks = ceil($totalSize / $chunkSize); @@ -215,10 +216,10 @@ public function testPartUpload() { 'content_type' => \mime_content_type($source), ]; $handle = @fopen($source, 'rb'); - $op = __DIR__ . '/chunk.part'; + $op = __DIR__.'/chunk.part'; while ($start < $totalSize) { $contents = fread($handle, $chunkSize); - $op = __DIR__ . '/chunk.part'; + $op = __DIR__.'/chunk.part'; $cc = fopen($op, 'wb'); fwrite($cc, $contents); fclose($cc); @@ -246,9 +247,10 @@ public function testPartUpload() { /** * @depends testPartUpload */ - public function testPartRead($path) { - $source = __DIR__ . '/../resources/disk-a/large_file.mp4'; - $chunk = file_get_contents($source, false,null, 0, 500); + public function testPartRead($path) + { + $source = __DIR__.'/../resources/disk-a/large_file.mp4'; + $chunk = file_get_contents($source, false, null, 0, 500); $readChunk = $this->object->read($path, 0, 500); $this->assertEquals($chunk, $readChunk); $this->object->delete($path); diff --git a/tests/Storage/StorageTest.php b/tests/Storage/StorageTest.php index 34a49828..3f04feb8 100644 --- a/tests/Storage/StorageTest.php +++ b/tests/Storage/StorageTest.php @@ -3,12 +3,12 @@ namespace Utopia\Tests\Storage; use Exception; -use Utopia\Storage\Storage; -use Utopia\Storage\Device\Local; use PHPUnit\Framework\TestCase; +use Utopia\Storage\Device\Local; +use Utopia\Storage\Storage; -Storage::setDevice('disk-a', new Local(__DIR__ . '/../resources/disk-a')); -Storage::setDevice('disk-b', new Local(__DIR__ . '/../resources/disk-b')); +Storage::setDevice('disk-a', new Local(__DIR__.'/../resources/disk-a')); +Storage::setDevice('disk-b', new Local(__DIR__.'/../resources/disk-b')); class StorageTest extends TestCase { @@ -27,7 +27,7 @@ public function testGetters() try { get_class(Storage::getDevice('disk-c')); - $this->fail("Expected exception not thrown"); + $this->fail('Expected exception not thrown'); } catch (Exception $e) { $this->assertEquals('The device "disk-c" is not listed', $e->getMessage()); } diff --git a/tests/Storage/Validator/FileExtTest.php b/tests/Storage/Validator/FileExtTest.php index 7a00e2d7..b3b6a69a 100644 --- a/tests/Storage/Validator/FileExtTest.php +++ b/tests/Storage/Validator/FileExtTest.php @@ -2,8 +2,8 @@ namespace Utopia\Tests\Storage\Validator; -use Utopia\Storage\Validator\FileExt; use PHPUnit\Framework\TestCase; +use Utopia\Storage\Validator\FileExt; class FileExtTest extends TestCase { diff --git a/tests/Storage/Validator/FileNameTest.php b/tests/Storage/Validator/FileNameTest.php index 661a7d1d..f3358bfe 100644 --- a/tests/Storage/Validator/FileNameTest.php +++ b/tests/Storage/Validator/FileNameTest.php @@ -2,8 +2,8 @@ namespace Utopia\Tests\Storage\Validator; -use Utopia\Storage\Validator\FileName; use PHPUnit\Framework\TestCase; +use Utopia\Storage\Validator\FileName; class FileNameTest extends TestCase { diff --git a/tests/Storage/Validator/FileSizeTest.php b/tests/Storage/Validator/FileSizeTest.php index a4b421bb..20deee4c 100644 --- a/tests/Storage/Validator/FileSizeTest.php +++ b/tests/Storage/Validator/FileSizeTest.php @@ -2,8 +2,8 @@ namespace Utopia\Tests\Storage\Validator; -use Utopia\Storage\Validator\FileSize; use PHPUnit\Framework\TestCase; +use Utopia\Storage\Validator\FileSize; class FileSizeTest extends TestCase { diff --git a/tests/Storage/Validator/FileTypeTest.php b/tests/Storage/Validator/FileTypeTest.php index 206430eb..c246c06d 100644 --- a/tests/Storage/Validator/FileTypeTest.php +++ b/tests/Storage/Validator/FileTypeTest.php @@ -2,8 +2,8 @@ namespace Utopia\Tests\Storage\Validator; -use Utopia\Storage\Validator\FileType; use PHPUnit\Framework\TestCase; +use Utopia\Storage\Validator\FileType; class FileTypeTest extends TestCase { @@ -23,9 +23,9 @@ public function tearDown(): void public function testValues() { - $this->assertEquals($this->object->isValid(__DIR__ . '/../../resources/disk-a/kitten-1.jpg'), true); - $this->assertEquals($this->object->isValid(__DIR__ . '/../../resources/disk-a/kitten-2.jpg'), true); - $this->assertEquals($this->object->isValid(__DIR__ . '/../../resources/disk-b/kitten-1.png'), false); - $this->assertEquals($this->object->isValid(__DIR__ . '/../../resources/disk-b/kitten-2.png'), false); + $this->assertEquals($this->object->isValid(__DIR__.'/../../resources/disk-a/kitten-1.jpg'), true); + $this->assertEquals($this->object->isValid(__DIR__.'/../../resources/disk-a/kitten-2.jpg'), true); + $this->assertEquals($this->object->isValid(__DIR__.'/../../resources/disk-b/kitten-1.png'), false); + $this->assertEquals($this->object->isValid(__DIR__.'/../../resources/disk-b/kitten-2.png'), false); } } diff --git a/tests/Storage/Validator/UploadTest.php b/tests/Storage/Validator/UploadTest.php index 0ba32c81..35de5cbb 100644 --- a/tests/Storage/Validator/UploadTest.php +++ b/tests/Storage/Validator/UploadTest.php @@ -2,8 +2,8 @@ namespace Utopia\Tests\Storage\Validator; -use Utopia\Storage\Validator\Upload; use PHPUnit\Framework\TestCase; +use Utopia\Storage\Validator\Upload; class UploadTest extends TestCase { @@ -23,10 +23,10 @@ public function tearDown(): void public function testValues() { - $this->assertEquals($this->object->isValid(__DIR__ . '/../../resources/disk-a/kitten-1.jpg'), false); - $this->assertEquals($this->object->isValid(__DIR__ . '/../../resources/disk-a/kitten-2.jpg'), false); - $this->assertEquals($this->object->isValid(__DIR__ . '/../../resources/disk-b/kitten-1.png'), false); - $this->assertEquals($this->object->isValid(__DIR__ . '/../../resources/disk-b/kitten-2.png'), false); + $this->assertEquals($this->object->isValid(__DIR__.'/../../resources/disk-a/kitten-1.jpg'), false); + $this->assertEquals($this->object->isValid(__DIR__.'/../../resources/disk-a/kitten-2.jpg'), false); + $this->assertEquals($this->object->isValid(__DIR__.'/../../resources/disk-b/kitten-1.png'), false); + $this->assertEquals($this->object->isValid(__DIR__.'/../../resources/disk-b/kitten-2.png'), false); $this->assertEquals($this->object->isValid(__FILE__), false); } }