Skip to content

Commit

Permalink
Laravel 9 upgrade (#86)
Browse files Browse the repository at this point in the history
* laravel 9 wip - brainmaestro/composer-git-hooks removed until it supports symfony 6 BrainMaestro/composer-git-hooks#123

* wip

* comment out cghooks

* rename

* wip

* wip

* wip

* remove cachedadapter

* wip

* wip

* wip

* Update README.md
  • Loading branch information
wfeller authored Apr 8, 2022
1 parent b936df0 commit 02dfb45
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 170 deletions.
7 changes: 2 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.4, 8.0]
illuminate: [7.*, 8.*]
exclude:
- illuminate: 7.*
php: 8.0
php: [8.0, 8.1]
illuminate: [9.*]
dependency-version: [prefer-stable]

name: P${{ matrix.php }} - L${{ matrix.illuminate }} - ${{ matrix.dependency-version }}
Expand Down
16 changes: 9 additions & 7 deletions .php_cs → .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
'indentation_type' => true,
'linebreak_after_opening_tag' => true,
'lowercase_cast' => true,
'lowercase_constants' => true,
'constant_case' => ['case' => 'lower'],
'lowercase_keywords' => true,
'magic_constant_casing' => true,
'method_argument_space' => true,
Expand Down Expand Up @@ -63,9 +63,11 @@
'normalize_index_brace' => true,
'not_operator_with_successor_space' => false,
'object_operator_without_whitespace' => true,
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'phpdoc_indent' => true,
'phpdoc_inline_tag' => true,
'general_phpdoc_tag_rename' => true,
'phpdoc_inline_tag_normalizer' => true,
'phpdoc_tag_type' => true,
'phpdoc_no_access' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
Expand All @@ -78,7 +80,7 @@
'phpdoc_var_without_name' => true,
'increment_style' => ['style' => 'post'],
'no_mixed_echo_print' => true,
'psr4' => true,
'psr_autoloading' => true,
'self_accessor' => true,
'array_syntax' => ['syntax' => 'short'],
'short_scalar_cast' => true,
Expand All @@ -94,7 +96,7 @@
'switch_case_semicolon_to_colon' => true,
'switch_case_space' => true,
'ternary_operator_spaces' => true,
'trailing_comma_in_multiline_array' => true,
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'line_ending' => true,
Expand All @@ -118,8 +120,8 @@
->ignoreDotFiles(true)
->ignoreVCS(true);

return Config::create()
return (new Config)
->setFinder($finder)
->setRules($rules)
->setRiskyAllowed(true)
->setUsingCache(true);
->setUsingCache(true);
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Also, take note of the upgrade.
| `4.x` | `>=7.2` | `>=5.4` | Above + Set private key on container | Deprecated |
| `5.x` | `>=7.4` | `>=5.8` | Above + Config-based Expiring Objects + Form Post Signature + Prefix | Maintained |
| `6.x` | `>=7.4` | `>=7.x` | PHP 8 support | Active |
| `7.x` | `>=8.0` | `>=9.x` | Laravel 9 support | Active |

If you are using Laravel versions older than 5.5, add the service provider to the `providers` array in `config/app.php`:
```php
Expand Down Expand Up @@ -71,9 +72,10 @@ as below
// If you're not willing to DELETE uploaded objects by DEFAULT, leave it empty.
// Really, if you don't know what you're doing, you should leave this empty as well.
'deleteAfter' => env('OS_DEFAULT_DELETE_AFTER', null),

// Optional variable to cache your storage objects in memory
// You must require league/flysystem-cached-adapter to enable caching
// This option is not available on laravel-ovh >= 7.0
'cache' => true, // Defaults to false

// Optional variable to set a prefix on all paths
Expand Down Expand Up @@ -118,6 +120,10 @@ file have been renamed to better correspond with the names used by OpenStack in
is intended to give the developer a better understanding of the contents of each configuration
key. If you're coming from `3.x`, updating the variable names in the `.env` might be essential to prevent failure.

### From 5.x/6.x to 7.x
Starting with `7.x` branch, only Laravel 9 and PHP 8 are supported. The `cache` option should be removed from
your config if you previously used it since Flysystem no longer supports "cached adapters".

# Usage

Refer to the extensive [Laravel Storage Documentation](https://laravel.com/docs/7.x/filesystem) for usage.
Expand Down
21 changes: 8 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@
}
},
"require": {
"php": "^7.4|^8.0",
"illuminate/console": "^7.0|^8.0",
"illuminate/support": "^7.0|^8.0",
"nimbusoft/flysystem-openstack-swift": "^0.3.3"
"php": "^8.0",
"illuminate/console": "^9.0",
"illuminate/support": "^9.0",
"nimbusoft/flysystem-openstack-swift": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"mockery/mockery": "^1.3 >= 1.3.1",
"friendsofphp/php-cs-fixer": "^2.18",
"brainmaestro/composer-git-hooks": "^2.8",
"league/flysystem-cached-adapter": "^1.0 >= 1.0.2",
"orchestra/testbench": "^5.0|^6.0"
"friendsofphp/php-cs-fixer": "^3.0",
"orchestra/testbench": "^7.0"
},
"extra": {
"laravel": {
Expand All @@ -59,11 +57,11 @@
"scripts": {
"post-install-cmd": [
"Sausin\\LaravelOvh\\Composer\\Scripts::devOnly",
"cghooks add --ignore-lock"
"# cghooks add --ignore-lock"
],
"post-update-cmd": [
"Sausin\\LaravelOvh\\Composer\\Scripts::devOnly",
"cghooks update"
"# cghooks update"
],

"lint": "php-cs-fixer fix",
Expand All @@ -73,8 +71,5 @@
"@test:lint",
"@test:unit"
]
},
"suggest": {
"league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0 >= 1.0.2)."
}
}
5 changes: 0 additions & 5 deletions src/Commands/SetCORSHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Storage;
use InvalidArgumentException;
use League\Flysystem\Cached\CachedAdapter;
use OpenStack\ObjectStore\v1\Models\Container;

class SetCORSHeaders extends Command
Expand Down Expand Up @@ -55,10 +54,6 @@ public function handle(): void

$adapter = Storage::disk($disk)->getAdapter();

if ($adapter instanceof CachedAdapter) {
$adapter = $adapter->getAdapter();
}

$this->container = $adapter->getContainer();
} catch (InvalidArgumentException $e) {
$this->error($e->getMessage());
Expand Down
5 changes: 0 additions & 5 deletions src/Commands/SetTempUrlKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Storage;
use InvalidArgumentException;
use League\Flysystem\Cached\CachedAdapter;
use OpenStack\ObjectStore\v1\Models\Container;

class SetTempUrlKey extends Command
Expand Down Expand Up @@ -57,10 +56,6 @@ public function handle(): void

$adapter = Storage::disk($disk)->getAdapter();

if ($adapter instanceof CachedAdapter) {
$adapter = $adapter->getAdapter();
}

$this->container = $adapter->getContainer();
} catch (InvalidArgumentException $e) {
$this->error($e->getMessage());
Expand Down
18 changes: 3 additions & 15 deletions src/OVHServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

namespace Sausin\LaravelOvh;

use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Cached\CachedAdapter;
use League\Flysystem\Cached\Storage\Memory as MemoryStore;
use League\Flysystem\Filesystem;
use OpenStack\ObjectStore\v1\Models\Container;
use OpenStack\OpenStack;
Expand Down Expand Up @@ -47,8 +44,6 @@ protected function configureCommands(): void
protected function configureStorage(): void
{
Storage::extend('ovh', function ($app, array $config) {
$cache = Arr::pull($config, 'cache', false);

// Creates a Configuration instance.
$this->config = OVHConfiguration::make($config);

Expand All @@ -57,7 +52,7 @@ protected function configureStorage(): void
// Get the Object Storage container.
$container = $client->objectStoreV1()->getContainer($this->config->getContainerName());

return $this->makeFileSystem($container, $cache);
return $this->makeFileSystem($container);
});
}

Expand Down Expand Up @@ -90,19 +85,12 @@ protected function makeOpenStackClient(): OpenStack
* Creates a Filesystem instance for interaction with the Object Storage.
*
* @param Container $container
* @param bool
* @return Filesystem
*/
protected function makeFileSystem(Container $container, bool $cache): Filesystem
protected function makeFileSystem(Container $container): Filesystem
{
$adapter = new OVHSwiftAdapter($container, $this->config, $this->config->getPrefix());

if ($cache) {
$adapter = new CachedAdapter($adapter, new MemoryStore);
}

return new Filesystem(
$adapter,
new OVHSwiftAdapter($container, $this->config, $this->config->getPrefix()),
array_filter([
'swiftLargeObjectThreshold' => $this->config->getSwiftLargeObjectThreshold(),
'swiftSegmentSize' => $this->config->getSwiftSegmentSize(),
Expand Down
25 changes: 12 additions & 13 deletions src/OVHSwiftAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
use DateTimeInterface;
use InvalidArgumentException;
use League\Flysystem\Config;
use League\Flysystem\UnableToCheckFileExistence;
use League\Flysystem\UnableToReadFile;
use Nimbusoft\Flysystem\OpenStack\SwiftAdapter;
use OpenStack\Common\Error\BadResponseError;
use OpenStack\ObjectStore\v1\Models\Container;

class OVHSwiftAdapter extends SwiftAdapter
Expand All @@ -24,7 +25,7 @@ class OVHSwiftAdapter extends SwiftAdapter
*/
public function __construct(Container $container, OVHConfiguration $config, ?string $prefix = null)
{
parent::__construct($container, $prefix);
parent::__construct($container, $prefix ?? '');

$this->config = $config;
}
Expand All @@ -49,7 +50,7 @@ protected function getEndpoint(?string $path = null): string
);

if (!empty($path)) {
$url .= $this->applyPathPrefix($path);
$url .= $this->prefixer->prefixPath($path);
}

return $url;
Expand All @@ -72,15 +73,13 @@ public function getUrl($path)
*
* @param string $path
* @return string
* @throws BadResponseError
* @throws UnableToReadFile|UnableToCheckFileExistence
*/
public function getUrlConfirm($path): string
{
// check if object exists
try {
$this->has($path);
} catch (BadResponseError $e) {
throw $e;
if (!$this->fileExists($path)) {
throw UnableToReadFile::fromLocation($path, 'File does not exist.');
}

return $this->getEndpoint($path);
Expand Down Expand Up @@ -114,7 +113,7 @@ public function getTemporaryUrl(string $path, DateTimeInterface $expiresAt, arra
'/v1/AUTH_%s/%s/%s',
$this->config->getProjectId(),
$this->config->getContainerName(),
$this->applyPathPrefix($path)
$this->prefixer->prefixPath($path)
);

// Body for the HMAC hash
Expand Down Expand Up @@ -158,7 +157,7 @@ public function getFormPostSignature(string $path, DateTimeInterface $expiresAt,
}

// Ensure $path doesn't begin with a slash
$path = $this->applyPathPrefix($path);
$path = $this->prefixer->prefixPath($path);

// The url on the OVH host
$codePath = sprintf(
Expand Down Expand Up @@ -193,14 +192,14 @@ public function getContainer(): Container
* @return array
* @see SwiftAdapter
*/
protected function getWriteData($path, $config): array
protected function getWriteData(string $path, Config $config): array
{
$data = parent::getWriteData($path, $config);

if ($config->has('deleteAfter')) {
if (null !== $config->get('deleteAfter')) {
// Apply object expiration timestamp if given
$data['deleteAfter'] = $config->get('deleteAfter');
} elseif ($config->has('deleteAt')) {
} elseif (null !== $config->get('deleteAt')) {
// Apply object expiration time if given
$data['deleteAt'] = $config->get('deleteAt');
} elseif (!empty($this->config->getDeleteAfter())) {
Expand Down
58 changes: 0 additions & 58 deletions tests/Functional/CachedAdapterTest.php

This file was deleted.

Loading

0 comments on commit 02dfb45

Please sign in to comment.