Skip to content

Commit

Permalink
Fix sub component classes
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Mar 28, 2019
1 parent a0d6f04 commit cc8a656
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/Dispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public function handleRequest(Request $request): Response
{
try
{
$manager = ResourceManager::componentPath($this->componentClassResourcePath($class));
$manager = ResourceManager::componentClass($class);
}
catch(RuntimeException $e)
{
Expand Down
29 changes: 11 additions & 18 deletions src/ResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ class ResourceManager
protected $_type = self::MAP_RESOURCES;
protected $_mapOptions = [];
protected $_baseUri = [];
/** @var DispatchableComponent */
protected $_component;
protected $_componentPath;
protected $_options = [];

Expand Down Expand Up @@ -87,25 +85,20 @@ public static function external()
return new static(self::MAP_EXTERNAL, []);
}

public static function componentPath($path)
public static function component(DispatchableComponent $component)
{
$manager = new static(self::MAP_COMPONENT);
$manager->_componentPath = $path;
return $manager;
$fullClass = $component instanceof FixedClassComponent ? $component->getComponentClass() : get_class($component);
return static::_componentManager($fullClass, Dispatch::instance());
}

public static function component(DispatchableComponent $component)
public static function componentClass(string $componentClassName)
{
$dispatch = Dispatch::instance();
if($component instanceof FixedClassComponent)
{
$fullClass = $component->getComponentClass();
}
else
{
$fullClass = get_class($component);
}
$class = $fullClass;
return static::_componentManager($componentClassName, Dispatch::instance());
}

protected static function _componentManager($fullClass, Dispatch $dispatch = null): ResourceManager
{
$class = ltrim($fullClass, '\\');
if($dispatch)
{
$maxPrefix = $maxAlias = '';
Expand All @@ -125,8 +118,8 @@ public static function component(DispatchableComponent $component)
}
$parts = explode('\\', $class);
array_unshift($parts, count($parts));

$manager = new static(self::MAP_COMPONENT, $parts);
$manager->_component = $component;
$manager->_componentPath = $dispatch->componentClassResourcePath($fullClass);
return $manager;
}
Expand Down

0 comments on commit cc8a656

Please sign in to comment.