설치된 플러그인들의 정보를 초기화 한다. 만약 cache에 저장된 정보가 있을 경우 cache로부터 저장된 정보를 가져오며,
캐싱된 정보가 없거나 refresh가 설정돼 있을 경우 다시 플러그인 디렉토리를 스캔하여 정보를 생성한다.
public initialize ( boolean $refresh = false ) : void | ||
$refresh | boolean | true일 경우, 캐싱된 데이터를 삭제하고 플러그인 정보를 새로 생성한다. |
return | void |
/** * 등록된 플러그인의 목록을 반환한다. * * @param bool $refresh true일 경우, cache를 사용하지 않고 다시 목록을 생성하여 반환한다. * * @return PluginCollection */ public function getAllPlugins($refresh = false) { if ($refresh === true) { $this->plugins->initialize(true); } return $this->plugins; }
public function testInitializeWithRefresh() { $scanner = \Mockery::mock('\\Xpressengine\\Plugin\\PluginScanner', ['scanDirectory' => $this->getPluginInfos()]); $cache = \Mockery::mock('Xpressengine\\Plugin\\Cache\\PluginCache'); $cache->shouldReceive('hasCachedPlugins')->once()->andReturnNull(); $cache->shouldReceive('hasCachedPlugins')->once()->andReturn(true); $cache->shouldReceive('getPluginsFromCache')->once()->andReturn($this->getPluginInfos()); $cache->shouldReceive('setPluginsToCache')->once()->andReturnNull(); $collection = new PluginCollection($scanner, $cache, PluginEntityStub::class, []); $collection->initialize(false); $this->assertCount(2, $this->getPropertyValue($collection, 'plugins')); return $collection; }
/** * 등록된 플러그인의 목록을 반환한다. * * @param bool $refresh true일 경우, cache를 사용하지 않고 다시 목록을 생성하여 반환한다. * * @return PluginCollection */ public function getAllPlugins($refresh = false) { if ($refresh === true) { $this->plugins->initialize(true); // 각 플러그인의 설치된 버전과 실제버전이 다르고, 별도의 install이나 update가 필요없을 경우, 설치된 버전정보를 갱신한다. foreach ($this->plugins->getList() as $plugin) { /** @var PluginEntity $plugin */ $installedVersion = $plugin->getInstalledVersion(); $sourceVersion = $plugin->getVersion(); if ($sourceVersion !== $installedVersion) { if ($plugin->checkInstalled($installedVersion) && $plugin->checkUpdated($installedVersion)) { $this->setPluginStatus($plugin->getId(), ['version' => $sourceVersion, 'status' => $plugin->getStatus()]); $plugin->setInstalledVersion($sourceVersion); } } } } return $this->plugins; }