Cache VCS driver after creation to avoid initializing it several times
parent
8bfb2e8bc2
commit
d11eff27d0
|
@ -39,6 +39,8 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt
|
|||
protected $repoConfig;
|
||||
protected $branchErrorOccurred = false;
|
||||
private $drivers;
|
||||
/** @var VcsDriverInterface */
|
||||
private $driver;
|
||||
|
||||
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()
|
||||
{
|
||||
if ($this->driver) {
|
||||
return $this->driver;
|
||||
}
|
||||
|
||||
if (isset($this->drivers[$this->type])) {
|
||||
$class = $this->drivers[$this->type];
|
||||
$driver = new $class($this->repoConfig, $this->io, $this->config);
|
||||
/** @var VcsDriverInterface $driver */
|
||||
$driver->initialize();
|
||||
$this->driver = new $class($this->repoConfig, $this->io, $this->config);
|
||||
$this->driver->initialize();
|
||||
|
||||
return $driver;
|
||||
return $this->driver;
|
||||
}
|
||||
|
||||
foreach ($this->drivers as $driver) {
|
||||
if ($driver::supports($this->io, $this->config, $this->url)) {
|
||||
$driver = new $driver($this->repoConfig, $this->io, $this->config);
|
||||
/** @var VcsDriverInterface $driver */
|
||||
$driver->initialize();
|
||||
$this->driver = new $driver($this->repoConfig, $this->io, $this->config);
|
||||
$this->driver->initialize();
|
||||
|
||||
return $driver;
|
||||
return $this->driver;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($this->drivers as $driver) {
|
||||
if ($driver::supports($this->io, $this->config, $this->url, true)) {
|
||||
$driver = new $driver($this->repoConfig, $this->io, $this->config);
|
||||
/** @var VcsDriverInterface $driver */
|
||||
$driver->initialize();
|
||||
$this->driver = new $driver($this->repoConfig, $this->io, $this->config);
|
||||
$this->driver->initialize();
|
||||
|
||||
return $driver;
|
||||
return $this->driver;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue