mirror of
https://github.com/flarum/core.git
synced 2025-08-08 09:26:34 +02:00
Apply fixes from StyleCI
[ci skip] [skip ci]
This commit is contained in:
@@ -1,5 +1,11 @@
|
|||||||
<?php
|
<?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;
|
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
|
* @param string $driver ::class attribute of driver class, which must implement Flarum\Http\SlugDriverInterface
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function addSlugDriver(string $identifier, string $driver) {
|
public function addSlugDriver(string $identifier, string $driver)
|
||||||
|
{
|
||||||
$this->slugDrivers[$identifier] = $driver;
|
$this->slugDrivers[$identifier] = $driver;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@@ -60,14 +67,16 @@ class ModelUrl implements ExtenderInterface
|
|||||||
public function extend(Container $container, Extension $extension = null)
|
public function extend(Container $container, Extension $extension = null)
|
||||||
{
|
{
|
||||||
if ($this->urlGenerator) {
|
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);
|
$existingUrlGenerators[$this->modelClass] = ContainerUtil::wrapCallback($this->urlGenerator, $container);
|
||||||
|
|
||||||
return $existingUrlGenerators;
|
return $existingUrlGenerators;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if ($this->slugDrivers) {
|
if ($this->slugDrivers) {
|
||||||
$container->extend('flarum.http.slugDrivers', function ($existingDrivers) {
|
$container->extend('flarum.http.slugDrivers', function ($existingDrivers) {
|
||||||
$existingDrivers[$this->modelClass] = array_merge(Arr::get($existingDrivers, $this->modelClass, []), $this->slugDrivers);
|
$existingDrivers[$this->modelClass] = array_merge(Arr::get($existingDrivers, $this->modelClass, []), $this->slugDrivers);
|
||||||
|
|
||||||
return $existingDrivers;
|
return $existingDrivers;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@@ -51,7 +51,7 @@ class HttpServiceProvider extends AbstractServiceProvider
|
|||||||
|
|
||||||
foreach ($this->app->make('flarum.http.slugDrivers') as $resourceClass => $resourceDrivers) {
|
foreach ($this->app->make('flarum.http.slugDrivers') as $resourceClass => $resourceDrivers) {
|
||||||
$driverClass = $resourceDrivers[$settings->get("slug_driver_$resourceClass", 'default')];
|
$driverClass = $resourceDrivers[$settings->get("slug_driver_$resourceClass", 'default')];
|
||||||
echo "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
|
echo 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
|
||||||
echo "slug_driver_$resourceClass";
|
echo "slug_driver_$resourceClass";
|
||||||
//echo $settings->get("slug_driver_$resourceClass", 'default');
|
//echo $settings->get("slug_driver_$resourceClass", 'default');
|
||||||
$compiledDrivers[$resourceClass] = $this->app->make($driverClass);
|
$compiledDrivers[$resourceClass] = $this->app->make($driverClass);
|
||||||
|
@@ -1,5 +1,11 @@
|
|||||||
<?php
|
<?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;
|
namespace Flarum\Tests\integration\extenders;
|
||||||
|
|
||||||
@@ -26,7 +32,8 @@ class ModelUrlTest extends TestCase
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function activateCustomDriver() {
|
protected function activateCustomDriver()
|
||||||
|
{
|
||||||
$userClass = User::class;
|
$userClass = User::class;
|
||||||
$this->prepareDatabase([
|
$this->prepareDatabase([
|
||||||
'settings' => [
|
'settings' => [
|
||||||
@@ -49,7 +56,8 @@ class ModelUrlTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function default_url_generator_used_by_default() {
|
public function default_url_generator_used_by_default()
|
||||||
|
{
|
||||||
$this->prepDb();
|
$this->prepDb();
|
||||||
|
|
||||||
$urlGenerator = $this->app()->getContainer()->make(UrlGenerator::class);
|
$urlGenerator = $this->app()->getContainer()->make(UrlGenerator::class);
|
||||||
@@ -62,10 +70,11 @@ class ModelUrlTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
*/
|
*/
|
||||||
public function custom_url_generator_can_be_used() {
|
public function custom_url_generator_can_be_used()
|
||||||
|
{
|
||||||
$this->extend(
|
$this->extend(
|
||||||
(new Extend\ModelUrl(User::class))->setUrlGenerator(function(UrlGenerator $urlGenerator, User $instance) {
|
(new Extend\ModelUrl(User::class))->setUrlGenerator(function (UrlGenerator $urlGenerator, User $instance) {
|
||||||
return "hello there!";
|
return 'hello there!';
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -75,10 +84,11 @@ class ModelUrlTest extends TestCase
|
|||||||
|
|
||||||
$testUser = User::find(1);
|
$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();
|
$this->prepDb();
|
||||||
|
|
||||||
$slugManager = $this->app()->getContainer()->make(SlugManager::class);
|
$slugManager = $this->app()->getContainer()->make(SlugManager::class);
|
||||||
@@ -92,7 +102,8 @@ class ModelUrlTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @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->extend((new Extend\ModelUrl(User::class))->addSlugDriver('testDriver', TestSlugDriver::class));
|
||||||
|
|
||||||
$this->prepDb();
|
$this->prepDb();
|
||||||
@@ -108,7 +119,8 @@ class ModelUrlTest extends TestCase
|
|||||||
/**
|
/**
|
||||||
* @test
|
* @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->extend((new Extend\ModelUrl(User::class))->addSlugDriver('testDriver', TestSlugDriver::class));
|
||||||
|
|
||||||
$this->prepDb();
|
$this->prepDb();
|
||||||
@@ -123,8 +135,8 @@ class ModelUrlTest extends TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class TestSlugDriver implements SlugDriverInterface {
|
class TestSlugDriver implements SlugDriverInterface
|
||||||
|
{
|
||||||
public function toSlug(AbstractModel $instance): string
|
public function toSlug(AbstractModel $instance): string
|
||||||
{
|
{
|
||||||
return 'test-slug';
|
return 'test-slug';
|
||||||
|
Reference in New Issue
Block a user