Skip to content

Commit

Permalink
bit of a rejig
Browse files Browse the repository at this point in the history
  • Loading branch information
fredbradley committed Jul 27, 2021
1 parent 1f97c74 commit 252fd59
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class Facade
{
private const CONTROLLER_NAMESPACE = "\\spkm\\isams\\Controllers\\";
/**
* @var Institution
*/
Expand All @@ -29,13 +30,17 @@ public function useInstitution(Institution $institution): self
}

/**
* @param \spkm\isams\Endpoint $controller
* @param string $controller
*/
public function useController(Endpoint $controller): self
public function useController(string $controller): self
{
$this->controller = $controller;
if (class_exists(self::CONTROLLER_NAMESPACE.$controller)) {
$this->controller = new $controller($this->institution);
return $this;
}
throw new \Exception("Could not find Controller: ".self::CONTROLLER_NAMESPACE.$controller);


return $this;
}

/**
Expand All @@ -46,9 +51,8 @@ public function useController(Endpoint $controller): self
*/
public function method(string $method, array $args=null)
{
$controller = new $this->controller($this->institution);

return call_user_func_array([$controller, $method], $args);
return call_user_func_array([$this->controller, $method], $args);
}

}

0 comments on commit 252fd59

Please sign in to comment.