Skip to content

Commit

Permalink
Add _getComponentClassName() to UiComponentTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Apr 29, 2019
1 parent e2c9e5f commit 4ac7d41
Show file tree
Hide file tree
Showing 9 changed files with 334 additions and 267 deletions.
9 changes: 7 additions & 2 deletions src/Component/UiComponentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@ trait UiComponentTrait

protected function _initDispatchableComponent(DispatchableComponent $component)
{
if(!isset(self::$_initComponents[static::class]))
if(!isset(self::$_initComponents[$this->_getComponentClassName()]))
{
$this->_requireResources(ResourceManager::component($component));
self::$_initComponents[static::class] = true;
self::$_initComponents[$this->_getComponentClassName()] = true;
}
}

protected function _getComponentClassName()
{
return static::class;
}

protected function _requireResources(ResourceManager $manager)
{
}
Expand Down
69 changes: 41 additions & 28 deletions src/Dispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,44 @@
use RuntimeException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use function array_filter;
use function array_shift;
use function dirname;
use function explode;
use function file_get_contents;
use function ltrim;
use function md5;
use function pathinfo;
use function realpath;
use function spl_autoload_functions;
use function str_replace;
use function str_split;
use function strlen;
use function substr;
use function trim;
use const DIRECTORY_SEPARATOR;
use const PATHINFO_EXTENSION;

class Dispatch
{

const RESOURCES_DIR = 'resources';
const VENDOR_DIR = 'vendor';
const PUBLIC_DIR = 'public';
/**
* @var Dispatch
*/
private static $_instance;

/**
* @var ResourceStore
*/
protected $_resourceStore;

protected $_baseUri;
protected $_requireFileHash = false;
/**
* @var ConfigProvider
*/
protected $_config;

const RESOURCES_DIR = 'resources';
const VENDOR_DIR = 'vendor';
const PUBLIC_DIR = 'public';

public static function bind(Dispatch $instance)
{
self::$_instance = $instance;
return $instance;
}

public static function instance()
{
return self::$_instance;
}

public static function destroy()
{
self::$_instance = null;
}

protected $_aliases = [];
protected $_projectRoot;
protected $_componentAliases = [];
Expand All @@ -70,6 +67,22 @@ public function __construct($projectRoot, $baseUri = null, ClassLoader $loader =
$this->_classLoader = $loader;
}

public static function bind(Dispatch $instance)
{
self::$_instance = $instance;
return $instance;
}

public static function instance()
{
return self::$_instance;
}

public static function destroy()
{
self::$_instance = null;
}

/**
* Add salt to dispatch hashes, for additional resource security
*
Expand Down Expand Up @@ -253,6 +266,11 @@ public function handleRequest(Request $request): Response
return ResourceFactory::create($resource);
}

public function config()
{
return $this->_config;
}

public function componentClassResourcePath($class)
{
$loader = $this->_getClassLoader();
Expand Down Expand Up @@ -291,11 +309,6 @@ public function store()
return $this->_resourceStore;
}

public function config()
{
return $this->_config;
}

public function calculateRelativePath($filePath)
{
return ltrim(str_replace($this->_projectRoot, '', $filePath), '/\\');
Expand Down
Loading

0 comments on commit 4ac7d41

Please sign in to comment.