Skip to content

Commit

Permalink
Laravel components v8 (#2576)
Browse files Browse the repository at this point in the history
- update actions ci
- include json for 4 spaces tab
- provide output int for process code exit
- adhere to parent type hint of builder
- mailer instance now needs a name, multiple can be instantiated
- getOriginal now uses mutators in the model
- Temporarily loosen MailableInterface requirements. This avoids an immediate BC break for classes in extensions that implement this interface.
- Temporarily provide (and autoload) old symfony translator interface
- make queue exception handler compatible with the contract of L8
- Update phpunit schema for newer version
- Update phpunit assert calls for newer version
  • Loading branch information
luceos committed Mar 5, 2021
1 parent 725863a commit 84ded0c
Show file tree
Hide file tree
Showing 39 changed files with 214 additions and 174 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -15,5 +15,5 @@ indent_size = 2
[*.{diff,md}]
trim_trailing_whitespace = false

[*.{php,xml}]
[*.{php,xml,json}]
indent_size = 4
10 changes: 3 additions & 7 deletions .github/workflows/test.yml
Expand Up @@ -8,7 +8,7 @@ jobs:

strategy:
matrix:
php: ['7.2', '7.3', '7.4', '8.0']
php: [7.3, 7.4, '8.0']
service: ['mysql:5.7', mariadb]
prefix: ['', flarum_]

Expand All @@ -21,12 +21,6 @@ jobs:
prefixStr: (prefix)

exclude:
- php: 7.2
service: 'mysql:5.7'
prefix: flarum_
- php: 7.2
service: mariadb
prefix: flarum_
- php: 7.3
service: 'mysql:5.7'
prefix: flarum_
Expand Down Expand Up @@ -80,3 +74,5 @@ jobs:

- name: Run Composer tests
run: composer test
env:
COMPOSER_PROCESS_TIMEOUT: 600
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,6 +4,7 @@ composer.phar
node_modules
.DS_Store
Thumbs.db
tests/.phpunit.result.cache
/tests/integration/tmp
.vagrant
.idea/*
Expand Down
54 changes: 29 additions & 25 deletions composer.json
@@ -1,7 +1,10 @@
{
"name": "flarum/core",
"description": "Delightfully simple forum software.",
"keywords": ["forum", "discussion"],
"keywords": [
"forum",
"discussion"
],
"homepage": "https://flarum.org/",
"license": "MIT",
"authors": [
Expand All @@ -17,27 +20,27 @@
"docs": "https://flarum.org/docs/"
},
"require": {
"php": ">=7.2",
"php": ">=7.3",
"axy/sourcemap": "^0.1.4",
"components/font-awesome": "^5.14.0",
"dflydev/fig-cookies": "^3.0.0",
"doctrine/dbal": "^2.7",
"franzl/whoops-middleware": "^2.0.0",
"illuminate/bus": "^6.0",
"illuminate/cache": "^6.0",
"illuminate/config": "^6.0",
"illuminate/container": "^6.0",
"illuminate/contracts": "^6.0",
"illuminate/database": "^6.0",
"illuminate/events": "^6.0",
"illuminate/filesystem": "^6.0",
"illuminate/hashing": "^6.0",
"illuminate/mail": "^6.0",
"illuminate/queue": "^6.0",
"illuminate/session": "^6.0",
"illuminate/support": "^6.0",
"illuminate/validation": "^6.0",
"illuminate/view": "^6.0",
"illuminate/bus": "^8.0",
"illuminate/cache": "^8.0",
"illuminate/config": "^8.0",
"illuminate/container": "^8.0",
"illuminate/contracts": "^8.0",
"illuminate/database": "^8.0",
"illuminate/events": "^8.0",
"illuminate/filesystem": "^8.0",
"illuminate/hashing": "^8.0",
"illuminate/mail": "^8.0",
"illuminate/queue": "^8.0",
"illuminate/session": "^8.0",
"illuminate/support": "^8.0",
"illuminate/validation": "^8.0",
"illuminate/view": "^8.0",
"intervention/image": "^2.5.0",
"laminas/laminas-diactoros": "^2.4.1",
"laminas/laminas-httphandlerrunner": "^1.2.0",
Expand All @@ -54,25 +57,26 @@
"psr/http-server-handler": "^1.0",
"psr/http-server-middleware": "^1.0",
"s9e/text-formatter": "^2.3.6",
"symfony/config": "^4.3.4",
"symfony/console": "^4.3.4",
"symfony/event-dispatcher": "^4.3.4",
"symfony/config": "^5.2.2",
"symfony/console": "^5.2.2",
"symfony/event-dispatcher": "^5.2.2",
"symfony/mime": "^5.2.0",
"symfony/translation": "^4.3.4",
"symfony/yaml": "^4.3.4",
"symfony/translation": "^5.1.5",
"symfony/yaml": "^5.2.2",
"tobscure/json-api": "^0.3.0",
"wikimedia/less.php": "^3.0"
},
"require-dev": {
"mockery/mockery": "^1.3.3",
"phpunit/phpunit": "^8.0"
"mockery/mockery": "^1.4",
"phpunit/phpunit": "^9.0"
},
"autoload": {
"psr-4": {
"Flarum\\": "src/"
},
"files": [
"src/helpers.php"
"src/helpers.php",
"src/TranslatorInterface.php"
]
},
"autoload-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Controller/SendConfirmationEmailController.php
Expand Up @@ -20,7 +20,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class SendConfirmationEmailController implements RequestHandlerInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Controller/SendTestMailController.php
Expand Up @@ -16,7 +16,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class SendTestMailController implements RequestHandlerInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Serializer/GroupSerializer.php
Expand Up @@ -11,7 +11,7 @@

use Flarum\Group\Group;
use InvalidArgumentException;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class GroupSerializer extends AbstractSerializer
{
Expand Down
2 changes: 1 addition & 1 deletion src/Console/AbstractCommand.php
Expand Up @@ -34,7 +34,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->input = $input;
$this->output = $output;

$this->fire();
return $this->fire() ?: 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Discussion/UserState.php
Expand Up @@ -91,7 +91,7 @@ public function user()
* @param Builder $query
* @return Builder
*/
protected function setKeysForSaveQuery(Builder $query)
protected function setKeysForSaveQuery($query)
{
$query->where('discussion_id', $this->discussion_id)
->where('user_id', $this->user_id);
Expand Down
2 changes: 1 addition & 1 deletion src/Forum/Content/Index.php
Expand Up @@ -18,7 +18,7 @@
use Illuminate\Contracts\View\Factory;
use Illuminate\Support\Arr;
use Psr\Http\Message\ServerRequestInterface as Request;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class Index
{
Expand Down
2 changes: 1 addition & 1 deletion src/Forum/ForumServiceProvider.php
Expand Up @@ -32,7 +32,7 @@
use Flarum\Settings\Event\Saving;
use Flarum\Settings\SettingsRepositoryInterface;
use Laminas\Stratigility\MiddlewarePipe;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class ForumServiceProvider extends AbstractServiceProvider
{
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/AbstractValidator.php
Expand Up @@ -12,7 +12,7 @@
use Illuminate\Support\Arr;
use Illuminate\Validation\Factory;
use Illuminate\Validation\ValidationException;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

abstract class AbstractValidator
{
Expand Down
2 changes: 1 addition & 1 deletion src/Foundation/ErrorHandling/ViewFormatter.php
Expand Up @@ -14,7 +14,7 @@
use Laminas\Diactoros\Response\HtmlResponse;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

/**
* A formatter for turning caught exceptions into "pretty" HTML error pages.
Expand Down
2 changes: 1 addition & 1 deletion src/Group/Permission.php
Expand Up @@ -39,7 +39,7 @@ public function group()
* @param Builder $query
* @return Builder
*/
protected function setKeysForSaveQuery(Builder $query)
protected function setKeysForSaveQuery($query)
{
$query->where('group_id', $this->group_id)
->where('permission', $this->permission);
Expand Down
5 changes: 4 additions & 1 deletion src/Locale/LocaleServiceProvider.php
Expand Up @@ -15,7 +15,8 @@
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Translation\Translator as TranslatorContract;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\Translation\TranslatorInterface as DeprecatedTranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class LocaleServiceProvider extends AbstractServiceProvider
{
Expand Down Expand Up @@ -62,9 +63,11 @@ public function register()

return $translator;
});

$this->container->alias('translator', Translator::class);
$this->container->alias('translator', TranslatorContract::class);
$this->container->alias('translator', TranslatorInterface::class);
$this->container->alias('translator', DeprecatedTranslatorInterface::class);
}

private function getDefaultLocale(): string
Expand Down
8 changes: 7 additions & 1 deletion src/Locale/Translator.php
Expand Up @@ -12,8 +12,9 @@
use Illuminate\Contracts\Translation\Translator as TranslatorContract;
use Symfony\Component\Translation\MessageCatalogueInterface;
use Symfony\Component\Translation\Translator as BaseTranslator;
use Symfony\Component\Translation\TranslatorInterface; // Defined locally as BC layer

class Translator extends BaseTranslator implements TranslatorContract
class Translator extends BaseTranslator implements TranslatorContract, TranslatorInterface
{
const REFERENCE_REGEX = '/^=>\s*([a-z0-9_\-\.]+)$/i';

Expand Down Expand Up @@ -84,4 +85,9 @@ private function getTranslation(MessageCatalogueInterface $catalogue, $id, $doma

return $translation;
}

public function setLocale($locale)
{
parent::setLocale($locale);
}
}
1 change: 1 addition & 0 deletions src/Mail/MailServiceProvider.php
Expand Up @@ -63,6 +63,7 @@ public function register()

$this->container->singleton('mailer', function ($container) {
$mailer = new Mailer(
'flarum',
$container['view'],
$container['swift.mailer'],
$container['events']
Expand Down
8 changes: 6 additions & 2 deletions src/Notification/MailableInterface.php
Expand Up @@ -9,7 +9,7 @@

namespace Flarum\Notification;

use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

interface MailableInterface
{
Expand All @@ -23,7 +23,11 @@ public function getEmailView();
/**
* Get the subject line for a notification email.
*
* @param TranslatorInterface $translator
*
* @return string
*/
public function getEmailSubject(TranslatorInterface $translator);
// Uncomment beta 17. Commented as temporary BC layer since Symfony changed
// the namespace of their translator interface
// public function getEmailSubject(TranslatorInterface $translator);
}
2 changes: 1 addition & 1 deletion src/Notification/NotificationMailer.php
Expand Up @@ -12,7 +12,7 @@
use Flarum\User\User;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Mail\Message;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class NotificationMailer
{
Expand Down
17 changes: 9 additions & 8 deletions src/Queue/ExceptionHandler.php
Expand Up @@ -12,6 +12,7 @@
use Exception;
use Illuminate\Contracts\Debug\ExceptionHandler as ExceptionHandling;
use Psr\Log\LoggerInterface;
use Throwable;

class ExceptionHandler implements ExceptionHandling
{
Expand All @@ -28,10 +29,10 @@ public function __construct(LoggerInterface $logger)
/**
* Report or log an exception.
*
* @param \Exception $e
* @param Throwable $e
* @return void
*/
public function report(Exception $e)
public function report(Throwable $e)
{
$this->logger->error((string) $e);
}
Expand All @@ -40,10 +41,10 @@ public function report(Exception $e)
* Render an exception into an HTTP response.
*
* @param \Illuminate\Http\Request $request
* @param \Exception $e
* @param Throwable $e
* @return \Symfony\Component\HttpFoundation\Response
*/
public function render($request, Exception $e)
public function render($request, Throwable $e)
{
// TODO: Implement render() method.
}
Expand All @@ -52,21 +53,21 @@ public function render($request, Exception $e)
* Render an exception to the console.
*
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @param \Exception $e
* @param Throwable $e
* @return void
*/
public function renderForConsole($output, Exception $e)
public function renderForConsole($output, Throwable $e)
{
// TODO: Implement renderForConsole() method.
}

/**
* Determine if the exception should be reported.
*
* @param \Exception $e
* @param Throwable $e
* @return bool
*/
public function shouldReport(Exception $e)
public function shouldReport(Throwable $e)
{
return true;
}
Expand Down
20 changes: 20 additions & 0 deletions src/TranslatorInterface.php
@@ -0,0 +1,20 @@
<?php

/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/

namespace Symfony\Component\Translation;

/**
* @deprecated beta 16, remove beta 17.
* This is here to provide a graceful transition for classes typehinting the old interface.
* Temporarily, `Flarum\Locale\Translator` will implement this to avoid breaking that typehint.
* Before beta 17, this should be removed from autoload.
*/
interface TranslatorInterface
{
}
2 changes: 1 addition & 1 deletion src/User/AccountActivationMailer.php
Expand Up @@ -14,7 +14,7 @@
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\Event\Registered;
use Illuminate\Contracts\Queue\Queue;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

class AccountActivationMailer
{
Expand Down

0 comments on commit 84ded0c

Please sign in to comment.