mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 06:53:47 +08:00
Rename view extender
As discussed in my initial review, it seems unlikely that we need the ability to remove (or otherwise modify) namespaces again. Therefore, it seems more consistent with other extenders to go for a "View" extender with a "namespace" method. Sorry for the back and forth. ;) Refs #1891, #2134.
This commit is contained in:
parent
3b6dbddee9
commit
b89ccaf83c
|
@ -13,9 +13,9 @@ use Flarum\Extension\Extension;
|
||||||
use Illuminate\Contracts\Container\Container;
|
use Illuminate\Contracts\Container\Container;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
|
|
||||||
class ViewNamespace implements ExtenderInterface
|
class View implements ExtenderInterface
|
||||||
{
|
{
|
||||||
private $adds = [];
|
private $namespaces = [];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a new namespace of Laravel views.
|
* Register a new namespace of Laravel views.
|
||||||
|
@ -33,9 +33,9 @@ class ViewNamespace implements ExtenderInterface
|
||||||
* where view files are stored, relative to the extend.php file.
|
* where view files are stored, relative to the extend.php file.
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function add($namespace, $hints)
|
public function namespace($namespace, $hints)
|
||||||
{
|
{
|
||||||
$this->adds[$namespace] = $hints;
|
$this->namespaces[$namespace] = $hints;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ class ViewNamespace implements ExtenderInterface
|
||||||
public function extend(Container $container, Extension $extension = null)
|
public function extend(Container $container, Extension $extension = null)
|
||||||
{
|
{
|
||||||
$container->resolving(Factory::class, function (Factory $view) {
|
$container->resolving(Factory::class, function (Factory $view) {
|
||||||
foreach ($this->adds as $namespace => $hints) {
|
foreach ($this->namespaces as $namespace => $hints) {
|
||||||
$view->addNamespace($namespace, $hints);
|
$view->addNamespace($namespace, $hints);
|
||||||
}
|
}
|
||||||
});
|
});
|
|
@ -13,7 +13,7 @@ use Flarum\Extend;
|
||||||
use Flarum\Tests\integration\TestCase;
|
use Flarum\Tests\integration\TestCase;
|
||||||
use Illuminate\Contracts\View\Factory;
|
use Illuminate\Contracts\View\Factory;
|
||||||
|
|
||||||
class ViewNamespaceTest extends TestCase
|
class ViewTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @test
|
* @test
|
||||||
|
@ -30,8 +30,8 @@ class ViewNamespaceTest extends TestCase
|
||||||
public function custom_view_namespace_can_be_added_by_extender()
|
public function custom_view_namespace_can_be_added_by_extender()
|
||||||
{
|
{
|
||||||
$this->extend(
|
$this->extend(
|
||||||
(new Extend\ViewNamespace)
|
(new Extend\View)
|
||||||
->add('integration.test', dirname(__FILE__, 3).'/fixtures/views')
|
->namespace('integration.test', dirname(__FILE__, 3).'/fixtures/views')
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals('<html><body>Hello World!</body></html>', trim($this->app()->getContainer()->make(Factory::class)->make('integration.test::test')->render()));
|
$this->assertEquals('<html><body>Hello World!</body></html>', trim($this->app()->getContainer()->make(Factory::class)->make('integration.test::test')->render()));
|
Loading…
Reference in New Issue
Block a user