1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-08 06:06:45 +02:00

feat(parsers): standardise parsers container names with macroable ability for Parsers API. #519

This commit is contained in:
Awilum
2020-12-18 14:28:49 +03:00
parent 5cd5b9fed7
commit 6efce42e25
2 changed files with 25 additions and 10 deletions

View File

@@ -26,6 +26,11 @@ class Shortcode
*/
private static $instances = [];
/**
* Shortcode facade
*/
private $shortcodeFacade = null;
/**
* Shortcode should not be cloneable.
*/
@@ -49,7 +54,17 @@ class Shortcode
*/
protected function __construct()
{
return new ShortcodeFacade();
$this->shortcodeFacade = new ShortcodeFacade();
}
/**
* Shortcode facade
*
* @param
*/
public function facade(): ShortcodeFacade
{
return $this->shortcodeFacade;
}
/**
@@ -77,7 +92,7 @@ class Shortcode
*/
public function addHandler(string $name, callable $handler)
{
return $this->addHandler($name, $handler);
return $this->facade()->addHandler($name, $handler);
}
/**
@@ -90,7 +105,7 @@ class Shortcode
*/
public function addEventHandler(string $name, callable $handler)
{
return $this->addEventHandler($name, $handler);
return $this->facade()->addEventHandler($name, $handler);
}
/**
@@ -102,7 +117,7 @@ class Shortcode
*/
public function parse(string $input)
{
return $this->parse($input);
return $this->facade()->parse($input);
}
/**
@@ -122,13 +137,13 @@ class Shortcode
return $dataFromCache;
}
$data = $this->process($input);
$data = $this->facade()->process($input);
flextype('cache')->set($key, $data);
return $data;
}
return $this->process($input);
return $this->facade()->process($input);
}
/**

View File

@@ -8,11 +8,11 @@ use Thunder\Shortcode\Events;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;
test('test getInstance() method', function () {
$this->assertInstanceOf(ShortcodeFacade::class, flextype('parsers')->shortcode()->getInstance());
$this->assertInstanceOf(Flextype\Support\Parsers\Shortcode::class, flextype('parsers')->shortcode()->getInstance());
});
test('test addHandler() method', function () {
$this->assertInstanceOf(ShortcodeFacade::class, flextype('parsers')->shortcode()->addHandler('foo', static function() { return ''; }));
$this->assertInstanceOf(Thunder\Shortcode\ShortcodeFacade::class, flextype('parsers')->shortcode()->addHandler('foo', static function() { return ''; }));
});
test('test addEventHandler() method', function () {
@@ -24,13 +24,13 @@ test('test addEventHandler() method', function () {
});
test('test parse() method', function () {
$this->assertInstanceOf(ShortcodeFacade::class, flextype('parsers')->shortcode()->addHandler('bar', static function() { return ''; }));
$this->assertInstanceOf(Thunder\Shortcode\ShortcodeFacade::class, flextype('parsers')->shortcode()->addHandler('bar', static function() { return ''; }));
$this->assertTrue(is_array(flextype('parsers')->shortcode()->parse('[bar]')));
$this->assertTrue(is_object(flextype('parsers')->shortcode()->parse('[bar]')[0]));
});
test('test process() method', function () {
$this->assertInstanceOf(ShortcodeFacade::class, flextype('parsers')->shortcode()->addHandler('zed', static function() { return 'Zed'; }));
$this->assertInstanceOf(Thunder\Shortcode\ShortcodeFacade::class, flextype('parsers')->shortcode()->addHandler('zed', static function() { return 'Zed'; }));
$this->assertEquals('Zed', flextype('parsers')->shortcode()->process('[zed]'));
$this->assertEquals('fòôBàřZed', flextype('parsers')->shortcode()->process('fòôBàř[zed]'));
});