1
0
mirror of https://github.com/flarum/core.git synced 2025-08-06 08:27:42 +02:00

Apply fixes from StyleCI

[ci skip] [skip ci]
This commit is contained in:
luceos
2020-11-24 00:55:18 +00:00
committed by Matthew Kilgore
parent a8fa57ad30
commit 696dc8ef6b
3 changed files with 35 additions and 14 deletions

View File

@@ -1,5 +1,11 @@
<?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 Flarum\Extend;
@@ -30,7 +36,8 @@ class ModelUrl implements ExtenderInterface
* @param string $driver ::class attribute of driver class, which must implement Flarum\Http\SlugDriverInterface
* @return self
*/
public function addSlugDriver(string $identifier, string $driver) {
public function addSlugDriver(string $identifier, string $driver)
{
$this->slugDrivers[$identifier] = $driver;
return $this;
@@ -60,14 +67,16 @@ class ModelUrl implements ExtenderInterface
public function extend(Container $container, Extension $extension = null)
{
if ($this->urlGenerator) {
$container->extend('flarum.http.resourceUrlGenerators', function($existingUrlGenerators) use ($container) {
$container->extend('flarum.http.resourceUrlGenerators', function ($existingUrlGenerators) use ($container) {
$existingUrlGenerators[$this->modelClass] = ContainerUtil::wrapCallback($this->urlGenerator, $container);
return $existingUrlGenerators;
});
}
if ($this->slugDrivers) {
$container->extend('flarum.http.slugDrivers', function ($existingDrivers) {
$existingDrivers[$this->modelClass] = array_merge(Arr::get($existingDrivers, $this->modelClass, []), $this->slugDrivers);
return $existingDrivers;
});
}

View File

@@ -51,7 +51,7 @@ class HttpServiceProvider extends AbstractServiceProvider
foreach ($this->app->make('flarum.http.slugDrivers') as $resourceClass => $resourceDrivers) {
$driverClass = $resourceDrivers[$settings->get("slug_driver_$resourceClass", 'default')];
echo "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
echo 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
echo "slug_driver_$resourceClass";
//echo $settings->get("slug_driver_$resourceClass", 'default');
$compiledDrivers[$resourceClass] = $this->app->make($driverClass);

View File

@@ -1,5 +1,11 @@
<?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 Flarum\Tests\integration\extenders;
@@ -26,7 +32,8 @@ class ModelUrlTest extends TestCase
]);
}
protected function activateCustomDriver() {
protected function activateCustomDriver()
{
$userClass = User::class;
$this->prepareDatabase([
'settings' => [
@@ -49,7 +56,8 @@ class ModelUrlTest extends TestCase
/**
* @test
*/
public function default_url_generator_used_by_default() {
public function default_url_generator_used_by_default()
{
$this->prepDb();
$urlGenerator = $this->app()->getContainer()->make(UrlGenerator::class);
@@ -62,10 +70,11 @@ class ModelUrlTest extends TestCase
/**
* @test
*/
public function custom_url_generator_can_be_used() {
public function custom_url_generator_can_be_used()
{
$this->extend(
(new Extend\ModelUrl(User::class))->setUrlGenerator(function(UrlGenerator $urlGenerator, User $instance) {
return "hello there!";
(new Extend\ModelUrl(User::class))->setUrlGenerator(function (UrlGenerator $urlGenerator, User $instance) {
return 'hello there!';
})
);
@@ -75,10 +84,11 @@ class ModelUrlTest extends TestCase
$testUser = User::find(1);
$this->assertEquals("hello there!", $urlGenerator->toResource(User::class, $testUser));
$this->assertEquals('hello there!', $urlGenerator->toResource(User::class, $testUser));
}
public function uses_default_driver_by_default() {
public function uses_default_driver_by_default()
{
$this->prepDb();
$slugManager = $this->app()->getContainer()->make(SlugManager::class);
@@ -92,7 +102,8 @@ class ModelUrlTest extends TestCase
/**
* @test
*/
public function custom_slug_driver_doesnt_have_effect_unless_enabled() {
public function custom_slug_driver_doesnt_have_effect_unless_enabled()
{
$this->extend((new Extend\ModelUrl(User::class))->addSlugDriver('testDriver', TestSlugDriver::class));
$this->prepDb();
@@ -108,7 +119,8 @@ class ModelUrlTest extends TestCase
/**
* @test
*/
public function custom_slug_driver_has_effect_if_enabled() {
public function custom_slug_driver_has_effect_if_enabled()
{
$this->extend((new Extend\ModelUrl(User::class))->addSlugDriver('testDriver', TestSlugDriver::class));
$this->prepDb();
@@ -123,8 +135,8 @@ class ModelUrlTest extends TestCase
}
}
class TestSlugDriver implements SlugDriverInterface {
class TestSlugDriver implements SlugDriverInterface
{
public function toSlug(AbstractModel $instance): string
{
return 'test-slug';