Skip to content

Commit

Permalink
Merge branch '2.x' into dev-theming-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Sep 15, 2023
2 parents 06432c5 + ec5cb98 commit 0ad0ffc
Show file tree
Hide file tree
Showing 16 changed files with 351 additions and 167 deletions.
9 changes: 8 additions & 1 deletion .github/workflows/REUSABLE_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ on:
description: Versions of databases to test with. Should be array of strings encoded as JSON array
type: string
required: false
default: '["mysql:5.7", "mysql:8.0.30", "mariadb"]'
default: '["mysql:5.7", "mysql:8.0.30", "mysql:8.1.0", "mariadb"]'

php_ini_values:
description: PHP ini values
Expand Down Expand Up @@ -76,6 +76,8 @@ jobs:
db: MySQL 8.0
- service: mariadb
db: MariaDB
- service: 'mysql:8.1.0'
db: MySQL 8.1

# Include Database prefix tests with only one PHP version.
- php: ${{ fromJSON(inputs.php_versions)[0] }}
Expand All @@ -93,6 +95,11 @@ jobs:
db: MariaDB
prefix: flarum_
prefixStr: (prefix)
- php: ${{ fromJSON(inputs.php_versions)[0] }}
service: 'mysql:8.1.0'
db: MySQL 8.1
prefix: flarum_
prefixStr: (prefix)

# To reduce number of actions, we exclude some PHP versions from running with some DB versions.
exclude:
Expand Down
4 changes: 2 additions & 2 deletions extensions/mentions/src/Formatter/UnparsePostMentions.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function updatePostMentionTags(mixed $context, string $xml): string
$attributes['displayname'] = $this->translator->trans('core.lib.username.deleted_text');
}

if (strpos($attributes['displayname'], '"#') !== false) {
if (str_contains($attributes['displayname'], '"#')) {
$attributes['displayname'] = preg_replace('/"#[a-z]{0,3}[0-9]+/', '_', $attributes['displayname']);
}

Expand All @@ -62,7 +62,7 @@ protected function unparsePostMentionTags(string $xml): string
{
$tagName = 'POSTMENTION';

if (strpos($xml, $tagName) === false) {
if (! str_contains($xml, $tagName)) {
return $xml;
}

Expand Down
2 changes: 1 addition & 1 deletion extensions/mentions/src/Formatter/UnparseTagMentions.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function unparseTagMentionTags(string $xml): string
{
$tagName = 'TAGMENTION';

if (strpos($xml, $tagName) === false) {
if (! str_contains($xml, $tagName)) {
return $xml;
}

Expand Down
4 changes: 2 additions & 2 deletions extensions/mentions/src/Formatter/UnparseUserMentions.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function updateUserMentionTags(mixed $context, string $xml): string

$attributes['displayname'] = $user?->display_name ?? $this->translator->trans('core.lib.username.deleted_text');

if (strpos($attributes['displayname'], '"#') !== false) {
if (str_contains($attributes['displayname'], '"#')) {
$attributes['displayname'] = preg_replace('/"#[a-z]{0,3}[0-9]+/', '_', $attributes['displayname']);
}

Expand All @@ -55,7 +55,7 @@ protected function unparseUserMentionTags(string $xml): string
{
$tagName = 'USERMENTION';

if (strpos($xml, $tagName) === false) {
if (! str_contains($xml, $tagName)) {
return $xml;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function handle(RequireExtension $command): array
$packageName = $command->package;

// Auto append :* if not requiring a specific version.
if (strpos($packageName, ':') === false) {
if (! str_contains($packageName, ':')) {
$packageName .= ':*';
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 6 additions & 13 deletions framework/core/src/Foundation/AbstractServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,17 @@

namespace Flarum\Foundation;

use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
use Illuminate\Support\ServiceProvider;

abstract class AbstractServiceProvider extends ServiceProvider
{
/**
* @deprecated perpetually, not removed because Laravel needs it.
* @var Container
*/
protected $app;
protected ApplicationContract $container;

public function __construct(
protected Container $container
) {
parent::__construct($container);
}

public function register()
public function __construct(ApplicationContract $app)
{
parent::__construct($app);

$this->container = $app;
}
}
71 changes: 25 additions & 46 deletions framework/core/src/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@

namespace Flarum\Foundation;

use Illuminate\Contracts\Container\Container;
use Flarum\Foundation\Concerns\InteractsWithLaravel;
use Illuminate\Container\Container as IlluminateContainer;
use Illuminate\Contracts\Foundation\Application as LaravelApplication;
use Illuminate\Events\EventServiceProvider;
use Illuminate\Support\Arr;
use Illuminate\Support\ServiceProvider;

class Application
class Application extends IlluminateContainer implements LaravelApplication
{
use InteractsWithLaravel;

/**
* The Flarum version.
*
Expand All @@ -34,7 +38,6 @@ class Application
protected array $loadedProviders = [];

public function __construct(
private readonly Container $container,
protected Paths $paths
) {
$this->registerBaseBindings();
Expand All @@ -44,19 +47,14 @@ public function __construct(

public function config(string $key, mixed $default = null): mixed
{
$config = $this->container->make('flarum.config');
$config = $this->make('flarum.config');

return $config[$key] ?? $default;
}

public function inDebugMode(): bool
{
return $this->config('debug', true);
}

public function url(string $path = null): string
{
$config = $this->container->make('flarum.config');
$config = $this->make('flarum.config');
$url = (string) $config->url();

if ($path) {
Expand All @@ -68,31 +66,27 @@ public function url(string $path = null): string

protected function registerBaseBindings(): void
{
\Illuminate\Container\Container::setInstance($this->container);
IlluminateContainer::setInstance($this);

/**
* Needed for the laravel framework code.
* Use container inside flarum instead.
*/
$this->container->instance('app', $this->container);
$this->container->alias('app', \Illuminate\Container\Container::class);
$this->instance('app', $this);
$this->alias('app', IlluminateContainer::class);

$this->container->instance('container', $this->container);
$this->container->alias('container', \Illuminate\Container\Container::class);
$this->instance('container', $this);
$this->alias('container', IlluminateContainer::class);

$this->container->instance('flarum', $this);
$this->container->alias('flarum', self::class);
$this->instance('flarum', $this);
$this->alias('flarum', self::class);

$this->container->instance('flarum.paths', $this->paths);
$this->container->alias('flarum.paths', Paths::class);
$this->instance('flarum.paths', $this->paths);
$this->alias('flarum.paths', Paths::class);
}

protected function registerBaseServiceProviders(): void
{
$this->register(new EventServiceProvider($this->container));
$this->register(new EventServiceProvider($this));
}

public function register(string|ServiceProvider $provider, array $options = [], bool $force = false): ServiceProvider
public function register($provider, $force = false): ServiceProvider
{
if (($registered = $this->getProvider($provider)) && ! $force) {
return $registered;
Expand All @@ -102,18 +96,11 @@ public function register(string|ServiceProvider $provider, array $options = [],
// application instance automatically for the developer. This is simply
// a more convenient way of specifying your service provider classes.
if (is_string($provider)) {
$provider = $this->resolveProviderClass($provider);
$provider = $this->resolveProvider($provider);
}

$provider->register();

// Once we have registered the service we will iterate through the options
// and set each of them on the application so they will be available on
// the actual loading of the service objects and for developer usage.
foreach ($options as $key => $value) {
$this[$key] = $value;
}

$this->markAsRegistered($provider);

// If the application has already booted, we will call this boot method on
Expand All @@ -140,14 +127,14 @@ public function getProvider(string|ServiceProvider $provider): ?ServiceProvider
*
* @param class-string<ServiceProvider> $provider
*/
public function resolveProviderClass(string $provider): ServiceProvider
public function resolveProvider($provider): ServiceProvider
{
return new $provider($this->container);
return new $provider($this);
}

protected function markAsRegistered(ServiceProvider $provider): void
{
$this->container['events']->dispatch($class = get_class($provider), [$provider]);
$this['events']->dispatch($class = get_class($provider), [$provider]);

$this->serviceProviders[] = $provider;

Expand Down Expand Up @@ -182,7 +169,7 @@ public function boot(): void
protected function bootProvider(ServiceProvider $provider): mixed
{
if (method_exists($provider, 'boot')) {
return $this->container->call([$provider, 'boot']);
return $this->call([$provider, 'boot']);
}

return null;
Expand Down Expand Up @@ -232,7 +219,7 @@ public function registerCoreContainerAliases(): void

foreach ($aliases as $key => $aliasGroup) {
foreach ($aliasGroup as $alias) {
$this->container->alias($key, $alias);
$this->alias($key, $alias);
}
}
}
Expand All @@ -241,12 +228,4 @@ public function version(): string
{
return static::VERSION;
}

public function terminating(): void
{
}

public function terminate(): void
{
}
}
Loading

0 comments on commit 0ad0ffc

Please sign in to comment.