Skip to content

Commit

Permalink
Refactor gateway class resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
gregoriohc committed Mar 12, 2018
1 parent d7df600 commit b7eb801
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 15 additions & 2 deletions src/Common/GatewayFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,27 @@

class GatewayFactory
{
protected $contextNamespace;

/**
* GatewayFactory constructor.
* @param string|null $contextNamespace
*/
public function __construct($contextNamespace = null)
{
$this->contextNamespace = $contextNamespace ?: substr(get_class($this), 0, -strlen('\\Common\\GatewayFactory'));
}


/**
* Create a new gateway instance
*
* @param string $name
* @param array $parameters
* @param mixed $context
* @return GatewayInterface
*/
public function create($name, $parameters = null)
public function create($name, $parameters = null, $context = null)
{
$class = $this->gatewayClass($name);

Expand Down Expand Up @@ -53,6 +66,6 @@ private function gatewayClass($name)
return $name;
}

return 'Gregoriohc\\Moneta\\' . ucfirst($name) . '\\Gateway';
return $this->contextNamespace . '\\' . ucfirst($name) . '\\Gateway';
}
}
2 changes: 1 addition & 1 deletion src/Moneta.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Moneta
public static function factory()
{
if (is_null(self::$factory)) {
self::$factory = new GatewayFactory;
self::$factory = new GatewayFactory(__NAMESPACE__);
}

return self::$factory;
Expand Down

0 comments on commit b7eb801

Please sign in to comment.