Skip to content

Commit

Permalink
UiComponentTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Jan 31, 2019
1 parent 2e0cbd1 commit 94f1b27
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
],
"require": {
"php": ">=7.1",
"packaged/helpers": "~1.17",
"packaged/config": "~1.3",
"packaged/helpers": "^1.0||^2.0",
"packaged/http": "~1.1",
"tedivm/jshrink": "~1.3"
},
Expand Down
14 changes: 2 additions & 12 deletions src/Component/UiComponent.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
<?php
namespace Packaged\Dispatch\Component;

use Packaged\Dispatch\ResourceManager;

abstract class UiComponent implements DispatchableComponent
{
private static $_initComponents = [];
use UiComponentTrait;

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

protected function _requireResources(ResourceManager $manager)
{
$this->_initDispatchableComponent($this);
}
}
22 changes: 22 additions & 0 deletions src/Component/UiComponentTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace Packaged\Dispatch\Component;

use Packaged\Dispatch\ResourceManager;

trait UiComponentTrait
{
private static $_initComponents = [];

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

protected function _requireResources(ResourceManager $manager)
{
}
}
8 changes: 4 additions & 4 deletions src/ResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function requireJs($toRequire, $options = null)
{
if($this->_type == self::MAP_INLINE)
{
return $this->requireInlineJs($toRequire);
return $this->_requireInlineJs($toRequire);
}
Dispatch::instance()->store()->requireJs($this->getResourceUri($toRequire), $options);
return $this;
Expand All @@ -229,7 +229,7 @@ public function requireJs($toRequire, $options = null)
*
* @return ResourceManager
*/
public function requireInlineJs($javascript)
protected function _requireInlineJs($javascript)
{
Dispatch::instance()->store()->requireInlineJs($javascript);
return $this;
Expand All @@ -248,7 +248,7 @@ public function requireCss($toRequire, $options = null)
{
if($this->_type == self::MAP_INLINE)
{
return $this->requireInlineCss($toRequire);
return $this->_requireInlineCss($toRequire);
}
Dispatch::instance()->store()->requireCss($this->getResourceUri($toRequire), $options);
return $this;
Expand All @@ -261,7 +261,7 @@ public function requireCss($toRequire, $options = null)
*
* @return ResourceManager
*/
public function requireInlineCss($stylesheet)
protected function _requireInlineCss($stylesheet)
{
Dispatch::instance()->store()->requireInlineCss($stylesheet);
return $this;
Expand Down

0 comments on commit 94f1b27

Please sign in to comment.