1
0
Fork 0

Cache VCS driver after creation to avoid initializing it several times

pull/5301/head
Jordi Boggiano 2016-05-09 21:45:46 +01:00
parent 8bfb2e8bc2
commit d11eff27d0
1 changed files with 15 additions and 12 deletions

View File

@ -39,6 +39,8 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
protected $repoConfig; protected $repoConfig;
protected $branchErrorOccurred = false; protected $branchErrorOccurred = false;
private $drivers; private $drivers;
/** @var VcsDriverInterface */
private $driver;
public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $dispatcher = null, array $drivers = null) public function __construct(array $repoConfig, IOInterface $io, Config $config, EventDispatcher $dispatcher = null, array $drivers = null)
{ {
@ -75,32 +77,33 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
public function getDriver() public function getDriver()
{ {
if ($this->driver) {
return $this->driver;
}
if (isset($this->drivers[$this->type])) { if (isset($this->drivers[$this->type])) {
$class = $this->drivers[$this->type]; $class = $this->drivers[$this->type];
$driver = new $class($this->repoConfig, $this->io, $this->config); $this->driver = new $class($this->repoConfig, $this->io, $this->config);
/** @var VcsDriverInterface $driver */ $this->driver->initialize();
$driver->initialize();
return $driver; return $this->driver;
} }
foreach ($this->drivers as $driver) { foreach ($this->drivers as $driver) {
if ($driver::supports($this->io, $this->config, $this->url)) { if ($driver::supports($this->io, $this->config, $this->url)) {
$driver = new $driver($this->repoConfig, $this->io, $this->config); $this->driver = new $driver($this->repoConfig, $this->io, $this->config);
/** @var VcsDriverInterface $driver */ $this->driver->initialize();
$driver->initialize();
return $driver; return $this->driver;
} }
} }
foreach ($this->drivers as $driver) { foreach ($this->drivers as $driver) {
if ($driver::supports($this->io, $this->config, $this->url, true)) { if ($driver::supports($this->io, $this->config, $this->url, true)) {
$driver = new $driver($this->repoConfig, $this->io, $this->config); $this->driver = new $driver($this->repoConfig, $this->io, $this->config);
/** @var VcsDriverInterface $driver */ $this->driver->initialize();
$driver->initialize();
return $driver; return $this->driver;
} }
} }
} }