Skip to content

Commit

Permalink
Apply fixes from StyleCI
Browse files Browse the repository at this point in the history
  • Loading branch information
StyleCIBot committed Nov 21, 2024
1 parent 0d1ba3d commit 41e63d3
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 44 deletions.
4 changes: 2 additions & 2 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
/*
* This file is part of blomstra/s3-assets.
*
* Copyright (c) 2022 Blomstra Ltd.
* Copyright (c) FriendsOfFlarum
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace FoF\S3Assets;

use FoF\S3Assets\Extend\Drivers;
use Flarum\Extend;
use FoF\S3Assets\Extend\Drivers;

return [
(new Extend\Frontend('admin'))
Expand Down
22 changes: 15 additions & 7 deletions src/Console/MoveAssetsCommand.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of blomstra/s3-assets.
*
* Copyright (c) FriendsOfFlarum
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace FoF\S3Assets\Console;

use Flarum\Console\AbstractCommand;
Expand All @@ -21,7 +30,7 @@ class MoveAssetsCommand extends AbstractCommand
*/
protected $container;

/**
/**
* @var Factory
*/
protected $factory;
Expand All @@ -37,16 +46,15 @@ class MoveAssetsCommand extends AbstractCommand
protected $url;

/**
* @var Paths
*/
* @var Paths
*/
protected $paths;

/**
* @var AssetsPublishCommand
*/
protected $publishCommand;


public function __construct(Container $container, Factory $factory, Paths $paths, AssetsPublishCommand $publishCommand)
{
$this->container = $container;
Expand Down Expand Up @@ -78,13 +86,13 @@ protected function fire()

// Move avatars
$this->info('Moving avatars...');
$this->moveFilesToDisk($localFilesystem, $this->paths->public . '/assets/avatars', $this->avatarDisk);
$this->moveFilesToDisk($localFilesystem, $this->paths->public.'/assets/avatars', $this->avatarDisk);

// Move profile covers
if (Arr::has($this->getFlarumDisks(), 'sycho-profile-cover')) {
$this->info('Moving profile covers...');
$coversDisk = $this->factory->disk('sycho-profile-cover');
$this->moveFilesToDisk($localFilesystem, $this->paths->public . '/assets/covers', $coversDisk);
$this->moveFilesToDisk($localFilesystem, $this->paths->public.'/assets/covers', $coversDisk);
}

$this->publishCommand->run(
Expand All @@ -107,7 +115,7 @@ protected function moveFilesToDisk(Filesystem $localFilesystem, string $localPat
{
foreach ($localFilesystem->allFiles($localPath) as $file) {
/** @var \Symfony\Component\Finder\SplFileInfo $file */
$this->info('Moving ' . $file->getPathname());
$this->info('Moving '.$file->getPathname());
$written = $disk->put($file->getRelativePathname(), $file->getContents());

if ($written) {
Expand Down
9 changes: 9 additions & 0 deletions src/Content/AdminPayload.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of blomstra/s3-assets.
*
* Copyright (c) FriendsOfFlarum
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace FoF\S3Assets\Content;

use Flarum\Frontend\Document;
Expand Down
54 changes: 32 additions & 22 deletions src/Driver/Config.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
<?php

/*
* This file is part of blomstra/s3-assets.
*
* Copyright (c) FriendsOfFlarum
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace FoF\S3Assets\Driver;

use Flarum\Settings\SettingsRepositoryInterface;
Expand All @@ -8,21 +17,22 @@
class Config
{
public function __construct(protected SettingsRepositoryInterface $settings)
{}
{
}

public function valid(): bool
{
$validator = resolve(Factory::class)->make($this->config(), [
'driver' => 'required|in:s3',
'key' => 'required|string',
'secret' => 'required|string',
'region' => 'required|string',
'bucket' => 'required|string',
'url' => 'url',
'endpoint' => 'required|url',
'driver' => 'required|in:s3',
'key' => 'required|string',
'secret' => 'required|string',
'region' => 'required|string',
'bucket' => 'required|string',
'url' => 'url',
'endpoint' => 'required|url',
'use_path_style_endpoint' => 'required|bool',
'options.ACL' => 'required|string',
'set_by_environment' => 'required|bool',
'options.ACL' => 'required|string',
'set_by_environment' => 'required|bool',
]);

return $validator->passes();
Expand All @@ -33,28 +43,28 @@ public function config(): array
$bucket = env('AWS_BUCKET', $this->settings->get('fof-upload.awsS3Bucket'));
$region = env('AWS_DEFAULT_REGION', $this->settings->get('fof-upload.awsS3Region'));
$cdnUrl = env('AWS_URL', $this->settings->get('fof-upload.cdnUrl'));
$pathStyle = (bool) (env('AWS_PATH_STYLE_ENDPOINT', $this->settings->get('fof-upload.awsS3UsePathStyleEndpoint')));
$pathStyle = (bool) env('AWS_PATH_STYLE_ENDPOINT', $this->settings->get('fof-upload.awsS3UsePathStyleEndpoint'));

if (! $cdnUrl) {
if (!$cdnUrl) {
$cdnUrl = sprintf('https://%s.s3.%s.amazonaws.com', $bucket, $region);
$pathStyle = false;
}

$setByEnv = (env('AWS_ACCESS_KEY_ID') || env('AWS_SECRET_ACCESS_KEY') || env('AWS_ENDPOINT'));

return [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID', $this->settings->get('fof-upload.awsS3Key')),
'secret' => env('AWS_SECRET_ACCESS_KEY', $this->settings->get('fof-upload.awsS3Secret')),
'region' => $region,
'bucket' => $bucket,
'url' => $cdnUrl,
'endpoint' => env('AWS_ENDPOINT', $this->settings->get('fof-upload.awsS3Endpoint')),
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID', $this->settings->get('fof-upload.awsS3Key')),
'secret' => env('AWS_SECRET_ACCESS_KEY', $this->settings->get('fof-upload.awsS3Secret')),
'region' => $region,
'bucket' => $bucket,
'url' => $cdnUrl,
'endpoint' => env('AWS_ENDPOINT', $this->settings->get('fof-upload.awsS3Endpoint')),
'use_path_style_endpoint' => $pathStyle,
'set_by_environment' => $setByEnv,
'options' => [
'set_by_environment' => $setByEnv,
'options' => [
'ACL' => env('AWS_ACL', $this->settings->get('fof-upload.awsS3ACL')),
]
],
];
}
}
11 changes: 10 additions & 1 deletion src/Driver/S3Driver.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
<?php

/*
* This file is part of blomstra/s3-assets.
*
* Copyright (c) FriendsOfFlarum
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace FoF\S3Assets\Driver;

use FoF\S3Assets\Driver\Config as DriverConfig;
use Flarum\Filesystem\DriverInterface;
use Flarum\Foundation\Config;
use Flarum\Foundation\Paths;
use Flarum\Settings\SettingsRepositoryInterface;
use FoF\S3Assets\Driver\Config as DriverConfig;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Filesystem\Cloud;
use Illuminate\Filesystem\FilesystemManager;
Expand Down
19 changes: 14 additions & 5 deletions src/Extend/Drivers.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
<?php

/*
* This file is part of blomstra/s3-assets.
*
* Copyright (c) FriendsOfFlarum
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace FoF\S3Assets\Extend;

use FoF\S3Assets\Driver\Config;
use FoF\S3Assets\Driver\S3Driver;
use Flarum\Extend\ExtenderInterface;
use Flarum\Extend\Filesystem;
use Flarum\Extension\Extension;
use Flarum\Foundation\Paths;
use Flarum\Http\UrlGenerator;
use FoF\S3Assets\Driver\Config;
use FoF\S3Assets\Driver\S3Driver;
use Illuminate\Contracts\Container\Container;

class Drivers implements ExtenderInterface
Expand All @@ -18,7 +27,7 @@ public function extend(Container $container, Extension $extension = null)
/** @var Config $config */
$config = $container->make(Config::class);

if (! $config->valid()) {
if (!$config->valid()) {
return;
}

Expand All @@ -27,11 +36,11 @@ public function extend(Container $container, Extension $extension = null)
->driver('local', S3Driver::class)
->disk('flarum-assets', fn (Paths $paths, UrlGenerator $url) => [
'root' => '/assets',
'url' => $config->config()['url'] . '/assets'
'url' => $config->config()['url'].'/assets',
])
->disk('flarum-avatars', fn (Paths $paths, UrlGenerator $url) => [
'root' => '/avatars',
'url' => $config->config()['url'] . '/avatars'
'url' => $config->config()['url'].'/avatars',
])
->extend($container, $extension);
}
Expand Down
10 changes: 9 additions & 1 deletion src/Frontend/Versioner.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
<?php

/*
* This file is part of blomstra/s3-assets.
*
* Copyright (c) FriendsOfFlarum
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace FoF\S3Assets\Frontend;

use Flarum\Frontend\Compiler\RevisionCompiler;
use Flarum\Frontend\Compiler\VersionerInterface;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Support\Arr;
Expand Down
14 changes: 11 additions & 3 deletions src/Provider/S3DiskProvider.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<?php

/*
* This file is part of blomstra/s3-assets.
*
* Copyright (c) FriendsOfFlarum
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

namespace FoF\S3Assets\Provider;

use FoF\S3Assets\Driver\Config;
use FoF\S3Assets\Frontend\Versioner;
use Flarum\Filesystem\FilesystemManager;
use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Frontend\Compiler\VersionerInterface;
use FoF\S3Assets\Driver\Config;
use FoF\S3Assets\Frontend\Versioner;

class S3DiskProvider extends AbstractServiceProvider
{
Expand Down
8 changes: 5 additions & 3 deletions tests/integration/setup.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
<?php

/*
* This file is part of Flarum.
* This file is part of blomstra/s3-assets.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
* Copyright (c) FriendsOfFlarum
*
* For the full copyright and license information, please view the LICENSE.md
* file that was distributed with this source code.
*/

use Flarum\Testing\integration\Setup\SetupScript;
Expand Down

0 comments on commit 41e63d3

Please sign in to comment.