Skip to content

Commit

Permalink
Allow component Trait to initDispatchable without providing $this
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Apr 29, 2019
1 parent 4ac7d41 commit a059cae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
20 changes: 11 additions & 9 deletions src/Component/UiComponentTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ trait UiComponentTrait
{
private static $_initComponents = [];

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

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

protected function _requireResources(ResourceManager $manager)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@

class ChildComponent extends AbstractComponent
{

public function __construct()
{
$this->_initDispatchableComponent();
parent::__construct();
}
}

0 comments on commit a059cae

Please sign in to comment.