Skip to content

Commit

Permalink
[facade] add ability to pass builders for
Browse files Browse the repository at this point in the history
http requiest verifeir
token factory
generic token factory
core gateway factory.
  • Loading branch information
makasim committed Sep 28, 2015
1 parent 52264b3 commit 3aa1b76
Show file tree
Hide file tree
Showing 2 changed files with 341 additions and 14 deletions.
46 changes: 33 additions & 13 deletions PayumBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PayumBuilder
protected $tokenFactory;

/**
* @var GenericTokenFactoryInterface
* @var GenericTokenFactoryInterface|callable|null
*/
protected $genericTokenFactory;

Expand Down Expand Up @@ -217,15 +217,23 @@ public function setTokenFactory($tokenFactory = null)
}

/**
* @param GenericTokenFactoryInterface $tokenFactory
* @param GenericTokenFactoryInterface|callable|null $tokenFactory
*
* @return static
*/
public function setGenericTokenFactory(GenericTokenFactoryInterface $tokenFactory = null)
public function setGenericTokenFactory($tokenFactory = null)
{
$this->genericTokenFactory = $tokenFactory;
if (
null === $tokenFactory ||
$tokenFactory instanceof GenericTokenFactoryInterface ||
is_callable($tokenFactory))
{
$this->genericTokenFactory = $tokenFactory;

return $this;
return $this;
}

throw new InvalidArgumentException('Invalid argument');
}

/**
Expand Down Expand Up @@ -330,7 +338,12 @@ public function getPayum()
}

$tokenFactory = $this->buildTokenFactory($this->tokenStorage, $this->buildRegistry([], $this->storages));
$genericTokenFactory = $this->buildGenericTokenFactory($tokenFactory);
$genericTokenFactory = $this->buildGenericTokenFactory($tokenFactory, array_replace([
'capture' => 'capture.php',
'notify' => 'notify.php',
'authorize' => 'authorize.php',
'refund' => 'refund.php',
], $this->genericTokenFactoryPaths));

$httpRequestVerifier = $this->buildHttpRequestVerifier($this->tokenStorage);

Expand Down Expand Up @@ -387,17 +400,24 @@ protected function buildTokenFactory(StorageInterface $tokenStorage, StorageRegi

/**
* @param TokenFactoryInterface $tokenFactory
* @param string[] $paths
*
* @return GenericTokenFactoryInterface
*
*/
protected function buildGenericTokenFactory(TokenFactoryInterface $tokenFactory)
protected function buildGenericTokenFactory(TokenFactoryInterface $tokenFactory, array $paths)
{
return $this->genericTokenFactory ?: new GenericTokenFactory($tokenFactory, $this->genericTokenFactoryPaths ?: [
'capture' => 'capture.php',
'notify' => 'notify.php',
'authorize' => 'authorize.php',
'refund' => 'refund.php',
]);
$genericTokenFactory = $this->genericTokenFactory;

if (is_callable($genericTokenFactory)) {
$genericTokenFactory = call_user_func($genericTokenFactory, $tokenFactory, $paths);

if (false == $genericTokenFactory instanceof GenericTokenFactoryInterface) {
throw new \LogicException('Builder returned invalid instance');
}
}

return $genericTokenFactory ?: new GenericTokenFactory($tokenFactory, $paths);
}

/**
Expand Down
Loading

0 comments on commit 3aa1b76

Please sign in to comment.