Skip to content

Commit 4ac7d41

Browse files
committed
Add _getComponentClassName() to UiComponentTrait
1 parent e2c9e5f commit 4ac7d41

File tree

9 files changed

+334
-267
lines changed

9 files changed

+334
-267
lines changed

src/Component/UiComponentTrait.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ trait UiComponentTrait
99

1010
protected function _initDispatchableComponent(DispatchableComponent $component)
1111
{
12-
if(!isset(self::$_initComponents[static::class]))
12+
if(!isset(self::$_initComponents[$this->_getComponentClassName()]))
1313
{
1414
$this->_requireResources(ResourceManager::component($component));
15-
self::$_initComponents[static::class] = true;
15+
self::$_initComponents[$this->_getComponentClassName()] = true;
1616
}
1717
}
1818

19+
protected function _getComponentClassName()
20+
{
21+
return static::class;
22+
}
23+
1924
protected function _requireResources(ResourceManager $manager)
2025
{
2126
}

src/Dispatch.php

Lines changed: 41 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,47 +11,44 @@
1111
use RuntimeException;
1212
use Symfony\Component\HttpFoundation\Request;
1313
use Symfony\Component\HttpFoundation\Response;
14+
use function array_filter;
15+
use function array_shift;
16+
use function dirname;
17+
use function explode;
18+
use function file_get_contents;
19+
use function ltrim;
20+
use function md5;
21+
use function pathinfo;
22+
use function realpath;
23+
use function spl_autoload_functions;
24+
use function str_replace;
25+
use function str_split;
26+
use function strlen;
27+
use function substr;
28+
use function trim;
29+
use const DIRECTORY_SEPARATOR;
30+
use const PATHINFO_EXTENSION;
1431

1532
class Dispatch
1633
{
1734

35+
const RESOURCES_DIR = 'resources';
36+
const VENDOR_DIR = 'vendor';
37+
const PUBLIC_DIR = 'public';
1838
/**
1939
* @var Dispatch
2040
*/
2141
private static $_instance;
22-
2342
/**
2443
* @var ResourceStore
2544
*/
2645
protected $_resourceStore;
27-
2846
protected $_baseUri;
2947
protected $_requireFileHash = false;
3048
/**
3149
* @var ConfigProvider
3250
*/
3351
protected $_config;
34-
35-
const RESOURCES_DIR = 'resources';
36-
const VENDOR_DIR = 'vendor';
37-
const PUBLIC_DIR = 'public';
38-
39-
public static function bind(Dispatch $instance)
40-
{
41-
self::$_instance = $instance;
42-
return $instance;
43-
}
44-
45-
public static function instance()
46-
{
47-
return self::$_instance;
48-
}
49-
50-
public static function destroy()
51-
{
52-
self::$_instance = null;
53-
}
54-
5552
protected $_aliases = [];
5653
protected $_projectRoot;
5754
protected $_componentAliases = [];
@@ -70,6 +67,22 @@ public function __construct($projectRoot, $baseUri = null, ClassLoader $loader =
7067
$this->_classLoader = $loader;
7168
}
7269

70+
public static function bind(Dispatch $instance)
71+
{
72+
self::$_instance = $instance;
73+
return $instance;
74+
}
75+
76+
public static function instance()
77+
{
78+
return self::$_instance;
79+
}
80+
81+
public static function destroy()
82+
{
83+
self::$_instance = null;
84+
}
85+
7386
/**
7487
* Add salt to dispatch hashes, for additional resource security
7588
*
@@ -253,6 +266,11 @@ public function handleRequest(Request $request): Response
253266
return ResourceFactory::create($resource);
254267
}
255268

269+
public function config()
270+
{
271+
return $this->_config;
272+
}
273+
256274
public function componentClassResourcePath($class)
257275
{
258276
$loader = $this->_getClassLoader();
@@ -291,11 +309,6 @@ public function store()
291309
return $this->_resourceStore;
292310
}
293311

294-
public function config()
295-
{
296-
return $this->_config;
297-
}
298-
299312
public function calculateRelativePath($filePath)
300313
{
301314
return ltrim(str_replace($this->_projectRoot, '', $filePath), '/\\');

0 commit comments

Comments
 (0)