Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make it possible to register drivers via a tag; allow cli commands to…
… be tied to a driver at runtime
- Loading branch information
gggeek
committed
Aug 30, 2015
1 parent
53d566f
commit 1489c8c
Showing
13 changed files
with
268 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Kaliop\QueueingBundle\Adapter; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerInterface; | ||
|
||
class DriverManager | ||
{ | ||
protected $aliases = array(); | ||
protected $defaultDriver; | ||
|
||
public function __construct(ContainerInterface $container) | ||
{ | ||
$this->container = $container; | ||
} | ||
|
||
/** | ||
* @param string $alias | ||
* @param string $serviceName | ||
*/ | ||
public function registerDriver($alias, $serviceName) | ||
{ | ||
$this->aliases[$alias] = $serviceName; | ||
} | ||
|
||
public function setDefaultDriver($alias) | ||
{ | ||
$this->defaultDriver = $alias; | ||
} | ||
|
||
/** | ||
* @param string $alias null when asking for the default driver | ||
* @return \Kaliop\QueueingBundle\Adapter\DriverInterface | ||
* @throws \Exception if driver is not registered | ||
*/ | ||
public function getDriver($alias = null) | ||
{ | ||
if ($alias == null) { | ||
$alias = $this->defaultDriver; | ||
} | ||
|
||
if (!isset($this->aliases[$alias])) { | ||
throw new \InvalidArgumentException(sprintf('No driver defined with the alias "%s".', $alias)); | ||
} | ||
|
||
/// @todo shall we check that the good interface is declared? | ||
return $this->container->get($this->aliases[$alias]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.