Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laravel 9 compatibility #5188

Merged
merged 74 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
c785544
Dependency hell (wip).
jesseleite Jan 26, 2022
e3e6388
Use new method of instantiating environment and converter with custom…
jesseleite Jan 27, 2022
a38251d
Cannot get config array from environment anymore, so return new objec…
jesseleite Jan 27, 2022
c582d69
Ensure we merge with the original `$config` array.
jesseleite Jan 27, 2022
f8ee8ed
The `convertToHtml()` method is deprecated, use new `convert()` method.
jesseleite Jan 27, 2022
7176751
Update custom parser extension examples to adhere to new interfaces.
jesseleite Jan 27, 2022
d0ebaf0
Update parser tests to use the new getters and valid config rules (ie…
jesseleite Jan 27, 2022
49391ef
Make `ParserTest` pass for league/commonmark 1 and 2.
jesseleite Jan 28, 2022
f683f95
Actually, we can continue using `CommonMarkConverter`, as it has a `g…
jesseleite Jan 28, 2022
d563e13
Ensure `Markdown\Manager` returns correct parser for commonmark version.
jesseleite Jan 28, 2022
22bc5ae
There was never a constructor in this class.
jesseleite Jan 28, 2022
67b368d
Check commonmark version without composer lock file, like we're doing…
jesseleite Jan 28, 2022
cf7bd3b
Have `LegacyParser` extend `Parser` to clean up duplication and confi…
jesseleite Jan 28, 2022
00daab9
Merge branch 'master' of https://github.com/statamic/cms into laravel…
jesseleite Feb 1, 2022
1a78b83
Refactor `AssetContainer::accessible()` to go through filesystem conf…
jesseleite Feb 1, 2022
72144f8
Refactor `AssetContainer::listContents()` to output normalized payloa…
jesseleite Feb 1, 2022
3fd5670
Pass `AssetContainerTest` again.
jesseleite Feb 1, 2022
1b35487
Pass `AssetQueryBuilderTest` again.
jesseleite Feb 1, 2022
9ca09f6
Add `prefixPath()` helper, since `getPathPrefix()` is no longer avail…
jesseleite Feb 1, 2022
dec34ef
Pass `AttributesTest` and `DimensionsTest` again.
jesseleite Feb 1, 2022
f894fe9
These were never being used.
jesseleite Feb 1, 2022
25eefbb
Make `AugmentedCollection::jsonSerialize()` compatible with parent.
jesseleite Feb 1, 2022
fe6619c
Normalizing flysystem meta, since `getMetadata()` no longer exists.
jesseleite Feb 2, 2022
3ed38c2
More `getPathPrefix()` refactorings.
jesseleite Feb 2, 2022
92c711b
Fix merging of array data when meta returns false due to missing file.
jesseleite Feb 2, 2022
2f7cd30
Use `path()` helper on disk instead of hardcoding to pass moar tests.
jesseleite Feb 2, 2022
7ee618f
Get normalized meta data with less flysystem API calls.
jesseleite Feb 2, 2022
176718a
Clean up and better explain normalization.
jesseleite Feb 2, 2022
0b99d2c
Pass `AssetRepositoryTest` by setting config at laravel level.
jesseleite Feb 2, 2022
b7bdb6f
We can still `getConfig()` from flysystem if we normalize it.
jesseleite Feb 2, 2022
d254941
Update a bunch of storage fakes to use `$config` param, as flysystem …
jesseleite Feb 2, 2022
9890f84
Fix adapter instantiation to work for both Flysystem 1.x and 3.x.
jesseleite Feb 2, 2022
84d22b4
Remove testing around `disable_asserts` (see commit description).
jesseleite Feb 2, 2022
b14c3b2
Pass `AssetTest` again.
jesseleite Feb 2, 2022
7dc5d11
Make these compatible again.
jesseleite Feb 2, 2022
70dce1d
Refactor config handling in these tests since we removed `diskConfig(…
jesseleite Feb 2, 2022
390f2ab
This funtionality moved in Flysystem 3.x.
jesseleite Feb 2, 2022
1d628c2
Php-cs-fixer keeps changing this on me, but it's just an alias anyway.
jesseleite Feb 2, 2022
fa48b7a
Clean up test output, since we're expecting exception instead of asse…
jesseleite Feb 2, 2022
89ddca3
More `Storage::fake()` fixes.
jesseleite Feb 4, 2022
f179822
Fix `/graphql` 404.
jesseleite Feb 4, 2022
7be5242
Ensure `graphql.prefix` config is compatible between both versions.
jesseleite Feb 4, 2022
312e6b9
Ensure `graphql.middleware` config is compatible between both versions.
jesseleite Feb 4, 2022
5b50583
The `graphql.routes` config/feature is completely removed in 8.x.
jesseleite Feb 4, 2022
7f75a6a
Remove flysystem typehint to make compatible with both 1.x and 3.x.
jesseleite Feb 4, 2022
b20b034
Use `Queue::fake()` assertion, as `expectsJobs()` was deprecated and …
jesseleite Feb 4, 2022
0407f55
Do not support rebing/graphql-laravel version 7.x.
jesseleite Feb 4, 2022
b719cdd
Use `Event::fake()` assertion, as `withoutEvents()` was deprecated an…
jesseleite Feb 4, 2022
7dbe5f1
Fix leftover state issue on `tearDown()`.
jesseleite Feb 5, 2022
b5ba2a3
Actually remove state issues by loading lang fixtures directly.
jesseleite Feb 5, 2022
0487b92
Make `Local` adapter check compatible for both versions.
jesseleite Feb 5, 2022
b381084
Todos.
jesseleite Feb 5, 2022
dc657a1
Update composer.json for CI.
jesseleite Feb 5, 2022
f44ee5d
Fix `FlysystemAdapter` since `getPathPrefix()` has been removed.
jesseleite Feb 7, 2022
d1b89af
Theoretical fix for `getPathPrefix()` call in `glide:generate` tag.
jesseleite Feb 7, 2022
bf4dcc4
Skip tests in older versions of laravel which will soon not be suppor…
jesseleite Feb 7, 2022
90a7295
The `build()` method was introduced in Laravel 8.48.0.
jesseleite Feb 7, 2022
b37afb5
Merge branch 'master' of https://github.com/statamic/cms into laravel…
jesseleite Feb 8, 2022
e931ae1
Use stable versions of laravel and testbench.
jesseleite Feb 8, 2022
9ea47d5
Update PHP and Laravel supported versions (#5229)
jasonvarga Feb 8, 2022
ec13204
changelog
jasonvarga Feb 8, 2022
9fb8d07
Merge branch 'master' of https://github.com/statamic/cms into laravel…
jesseleite Feb 8, 2022
4d6dba0
Jason's order.
jesseleite Feb 8, 2022
17d1ac1
Merge branch 'master' of https://github.com/statamic/cms into laravel…
jesseleite Feb 11, 2022
f75c1cb
Fix `ResponseFactory` backwards compatibility.
jesseleite Feb 11, 2022
cfc519c
Merge branch 'master' of https://github.com/statamic/cms into laravel…
jesseleite Feb 14, 2022
6fe9653
Support both new and old lang path conventions in addons.
jesseleite Feb 15, 2022
0b79222
Suppress PHP deprecation warnings in log.
jesseleite Feb 17, 2022
5514675
Merge branch 'master' of https://github.com/statamic/cms into laravel…
jesseleite Feb 18, 2022
defdb8a
Merge branch 'master' into laravel-9-compatibility
jasonvarga Feb 21, 2022
62c9c61
Test for disabling graphql routes ...
jasonvarga Feb 21, 2022
296b65b
statamic pro test to make sure the middleware is added
jasonvarga Feb 21, 2022
298f82c
fix graphql bootstrapping across versions
jasonvarga Feb 21, 2022
b9ca3c2
minor refactor
jasonvarga Feb 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,22 @@ jobs:
strategy:
matrix:
php: [7.4, 8.0, 8.1]
laravel: [8.*]
laravel: [8.*, 9.*]
stability: [prefer-lowest, prefer-stable]
os: [ubuntu-latest]
include:
- laravel: 8.*
framework: ^8.24.0
- laravel: 9.*
framework: ^9.0
- os: windows-latest
php: 8.0
laravel: 8.*
framework: ^8.24.0
stability: prefer-stable
exclude:
- laravel: 9.*
php: 7.4

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
- CP forms only submit visible fields, in order to fix sometimes/required_if/etc validation rules. [#5101](https://github.com/statamic/cms/issues/5101) by @jesseleite

### What's changed
- PHP 7.2 and 7.3 are no longer supported.
- Laravel 6 and 7 are no longer supported.
- Entries fieldtypes augment to query builders instead of collections. [#5238](https://github.com/statamic/cms/issues/5238) by @jasonvarga
- The `page` and each Global Set in the cascade are now `Values` instances. [#5201](https://github.com/statamic/cms/issues/5201) by @jasonvarga
- The `Augmented` interface's `get` method now has a return typehint of `Value`. [#5302](https://github.com/statamic/cms/issues/5302) by @jasonvarga
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@
"facade/ignition-contracts": "^1.0",
"guzzlehttp/guzzle": "^6.3 || ^7.0",
"james-heinrich/getid3": "^1.9",
"laravel/framework": "^6.20.14 || ^7.30.4 || ^8.24.0",
"laravel/framework": "^8.24.0 || ^9.0",
"laravel/helpers": "^1.1",
"league/commonmark": "^1.5",
"league/commonmark": "^1.5 || ^2.0",
"league/csv": "^9.0",
"league/glide": "^1.1",
"league/glide": "^1.1 || ^2.0",
"michelf/php-smartypants": "^1.8",
"pixelfear/composer-dist-plugin": "^0.1.4",
"rebing/graphql-laravel": "^6.5",
"rebing/graphql-laravel": "^6.5 || ^8.0",
"spatie/blink": "^1.1.2",
"statamic/stringy": "^3.1",
"symfony/http-foundation": "^4.3.3 || ^5.1.4",
"symfony/http-foundation": "^4.3.3 || ^5.1.4 || ^6.0",
"symfony/lock": "^5.1",
"symfony/var-exporter": "^4.3 || ^5.1",
"symfony/yaml": "^4.1 || ^5.1",
"symfony/yaml": "^4.1 || ^5.1 || ^6.0",
"ueberdosis/html-to-prosemirror": "^1.3",
"ueberdosis/prosemirror-to-html": "^2.6",
"wilderborn/partyline": "^1.0"
Expand All @@ -37,7 +37,7 @@
"fakerphp/faker": "~1.10",
"google/cloud-translate": "^1.6",
"mockery/mockery": "^1.2.3",
"orchestra/testbench": "^4.0 || ^5.0 || ^6.7.0"
"orchestra/testbench": "^6.7.0 || ^7.0"
},
"config": {
"optimize-autoloader": true,
Expand Down
10 changes: 9 additions & 1 deletion src/Assets/AssetContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,15 @@ public function assetFolder($path)
*/
public function accessible()
{
return $this->disk()->filesystem()->getDriver()->getConfig()->get('url') !== null;
$config = $this->disk()->filesystem()->getConfig();

// If Flysystem 1.x, it will be an array, so wrap it with `collect()` so it can `get()` values;
// Otherwise it will already be a `ReadOnlyConfiguration` object with a `get()` method.
if (is_array($config)) {
$config = collect($config);
}

return $config->get('url') !== null;
}

/**
Expand Down
114 changes: 96 additions & 18 deletions src/Assets/AssetContainerContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Statamic\Assets;

use Illuminate\Support\Facades\Cache;
use League\Flysystem\Util;
use Statamic\Support\Str;

class AssetContainerContents
Expand All @@ -26,10 +25,93 @@ public function all()
// and will let us perform more efficient filtering and caching.
$files = $this->filesystem()->listContents('/', true);

// If Flysystem 3.x, re-apply sorting and return a backwards compatible result set.
// See: https://flysystem.thephpleague.com/v2/docs/usage/directory-listings/
if (! is_array($files)) {
return collect($files->sortByPath()->toArray())->keyBy('path')->map(function ($file) {
return $this->normalizeFlysystemAttributes($file);
});
}

return collect($files)->keyBy('path');
});
}

/**
* Normalize flysystem 3.x `FileAttributes` and `DirectoryAttributes` payloads back to the 1.x array style.
*
* @param mixed $attributes
* @return array
*/
private function normalizeFlysystemAttributes($attributes)
{
// Merge attributes with `pathinfo()`, since Flysystem 3.x removed `Util::pathinfo()`.
$normalized = array_merge([
'type' => $attributes->type(),
'path' => $attributes->path(),
'timestamp' => $attributes->lastModified(),
], pathinfo($attributes['path']));

// Flysystem 1.x never returned `.` dirnames.
if (isset($normalized['dirname']) && $normalized['dirname'] === '.') {
$normalized['dirname'] = '';
}

// Only return `size` if type is file.
if ($normalized['type'] === 'file') {
$normalized['size'] = $attributes->fileSize();
}

return $normalized;
}

/**
* Normalize flysystem 3.x meta data to match 1.x payloads.
*
* @param string $path
* @return array
*/
private function getNormalizedFlysystemMetadata($path)
{
$isFlysystemV1 = method_exists($this->filesystem(), 'getTimestamp');

// Determine whether or not to use Flysystem 1.x or 3.x getter methods.
$lastModifiedMethod = $isFlysystemV1 ? 'getTimestamp' : 'lastModified';
$fileSizeMethod = $isFlysystemV1 ? 'getSize' : 'fileSize';

// Use exception handling to avoid another `has()` API method call.
try {
$timestamp = $this->filesystem()->{$lastModifiedMethod}($path);
} catch (\Exception $exception) {
return false;
}

// Use exception handling to normalize file size output.
try {
$size = $this->filesystem()->{$fileSizeMethod}($path);
} catch (\Exception $exception) {
$size = false;
}

// Determine `type` off returned size to avoid another API method call.
$type = $size === false ? 'dir' : 'file';

// Merge `pathinfo()` in, since Flysystem 3.x removed `Util::pathinfo()`.
$normalized = array_merge(compact('type', 'path', 'timestamp'), pathinfo($path));

// Flysystem 1.x never returned `.` dirnames.
if (isset($normalized['dirname']) && $normalized['dirname'] === '.') {
$normalized['dirname'] = '';
}

// Only return `size` if type is file.
if ($type === 'file') {
$normalized['size'] = $size;
}

return $normalized;
}

public function cached()
{
return Cache::get($this->key());
Expand Down Expand Up @@ -124,25 +206,21 @@ public function forget($path)

public function add($path)
{
try {
// If the file doesn't exist, this will either throw an exception or return
// false depending on the adapter and whether or not asserts are enabled.
if (! $metadata = $this->filesystem()->getMetadata($path)) {
return $this;
}

// Add parent directories
if (($dir = dirname($path)) !== '.') {
$this->add($dir);
}

$this->all()->put($path, $metadata + Util::pathinfo($path));

$this->filteredFiles = null;
$this->filteredDirectories = null;
} finally {
if (! $metadata = $this->getNormalizedFlysystemMetadata($path)) {
return $this;
}

// Add parent directories
if (($dir = dirname($path)) !== '.') {
$this->add($dir);
}

$this->all()->put($path, $metadata);

$this->filteredFiles = null;
$this->filteredDirectories = null;

return $this;
}

private function key()
Expand Down
9 changes: 7 additions & 2 deletions src/Assets/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private function getImageAttributes()
$manager->copy("source://{$this->asset->path()}", $destination);

try {
[$width, $height] = getimagesize($cache->getAdapter()->getPathPrefix().$cachePath);
[$width, $height] = getimagesize($this->prefixPath($cachePath));
$size = compact('width', 'height');
} catch (\Exception $e) {
$size = [];
Expand Down Expand Up @@ -126,7 +126,7 @@ private function getSvgAttributes()

$manager->copy("source://{$this->asset->path()}", $destination);

$svg = simplexml_load_file($cache->getAdapter()->getPathPrefix().$cachePath);
$svg = simplexml_load_file($this->prefixPath($cachePath));

$cache->delete($cachePath);

Expand Down Expand Up @@ -170,4 +170,9 @@ private function getCacheFlysystem()

return Storage::disk($disk)->getDriver();
}

private function prefixPath($path)
{
return Storage::disk('attributes-cache')->path($path);
}
}
2 changes: 1 addition & 1 deletion src/Auth/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function value(string $value = null)
return $this;
}

return str_replace('{'.$this->placeholder.'}', $this->placeholderValue, $this->value);
return str_replace('{'.$this->placeholder.'}', (string) $this->placeholderValue, $this->value);
}

public function originalValue()
Expand Down
3 changes: 2 additions & 1 deletion src/Console/Commands/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Command;
use Statamic\Console\RunsInPlease;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Helper\DescriptorHelper;

class ListCommand extends Command
Expand Down Expand Up @@ -31,7 +32,7 @@ public function handle()
]);
}

public function getApplication()
public function getApplication(): ?Application
{
$app = parent::getApplication();

Expand Down
2 changes: 1 addition & 1 deletion src/Console/EnhancesCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

trait EnhancesCommands
{
public function run(InputInterface $input, OutputInterface $output)
public function run(InputInterface $input, OutputInterface $output): int
{
Partyline::bind($this);

Expand Down
2 changes: 1 addition & 1 deletion src/Data/AugmentedCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function toArray()
})->all();
}

public function jsonSerialize()
public function jsonSerialize(): array
{
return array_map(function ($value) {
if ($this->shallowNesting && $value instanceof Augmentable) {
Expand Down
14 changes: 9 additions & 5 deletions src/Facades/Endpoint/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Statamic\Facades\Endpoint;

use League\Flysystem\Util;
use Statamic\Facades\Pattern;
use Statamic\Support\Str;

Expand Down Expand Up @@ -83,7 +82,12 @@ public function resolve($path)
{
$leadingSlash = Str::startsWith($path, '/');

$path = Util::normalizeRelativePath(self::tidy($path));
$path = self::tidy($path);

// The `Util` class was removed in Flysystem 3.x, but this functionality exists in the new `WhitespacePathNormalizer`.
$path = class_exists('\League\Flysystem\Util')
? \League\Flysystem\Util::normalizeRelativePath($path)
: (new \League\Flysystem\WhitespacePathNormalizer)->normalizePath($path);

// Flysystem's method removes the leading slashes. We want to maintain them.
return $leadingSlash ? Str::ensureLeft($path, '/') : $path;
Expand All @@ -106,7 +110,7 @@ public function assemble($args)
return null;
}

return self::tidy(join('/', $args));
return self::tidy(implode('/', $args));
}

/**
Expand Down Expand Up @@ -194,10 +198,10 @@ public function tidy($path)
{
// Replace backslashes with forward slashes for consistency between platforms.
// PHP is capable of understanding Windows paths that use forward slashes.
$path = str_replace('\\', '/', $path);
$path = str_replace('\\', '/', (string) $path);

// Remove occurrences of "//" in a $path (except when part of a protocol).
return preg_replace('#(^|[^:])//+#', '\\1/', $path);
return preg_replace('#(^|[^:])//+#', '\\1/', (string) $path);
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/Filesystem/FlysystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Statamic\Filesystem;

use Illuminate\Contracts\Filesystem\Filesystem as FilesystemAdapter;
use League\Flysystem\Adapter\Local;
use Statamic\Facades\Path;
use Statamic\Support\Str;

Expand All @@ -25,13 +24,18 @@ public function normalizePath($path)
}

if (Path::isAbsolute($path)) {
$adapter = $this->filesystem->getDriver()->getAdapter();
$adapter = $this->filesystem->getAdapter();

if (! $adapter instanceof Local) {
// Determine which adapter to use for Flysystem 1.x or 3.x.
$localClass = class_exists($legacyAdapter = '\League\Flysystem\Adapter\Local')
? $legacyAdapter
: '\League\Flysystem\Local\LocalFilesystemAdapter';

if (! $adapter instanceof $localClass) {
throw new \LogicException('Cannot use absolute paths on non-local adapters.');
}

if (! Str::startsWith($path, $root = Path::tidy($adapter->getPathPrefix()))) {
if (! Str::startsWith($path, $root = Path::tidy($this->filesystem->path('/')))) {
throw new \LogicException("Cannot reference path [{$path}] outside the root [{$root}]");
}

Expand Down
2 changes: 1 addition & 1 deletion src/GraphQL/DefaultSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getConfig()
'query' => $this->getQueries(),
'mutation' => [],
'middleware' => $this->getMiddleware(),
'method' => ['get', 'post'],
'method' => ['GET', 'POST'],
];
}

Expand Down
Loading