public function testInitWithComponent() { $this->destroyApplication(); $this->mockApplication(['components' => ['fs' => ['class' => 'creocoder\\flysystem\\LocalFilesystem', 'path' => sys_get_temp_dir()]]]); $storage = new Storage(['filesystemComponent' => 'fs']); $this->assertNotNull($storage->getFilesystem()); $this->assertInstanceOf("creocoder\\flysystem\\LocalFilesystem", $storage->getFilesystem()); }
public function build() { \yii\base\Event::on(\denoll\filekit\Storage::className(), \denoll\filekit\Storage::EVENT_BEFORE_SAVE, function ($event) { /** @var \denoll\filekit\Storage $storage */ $storage = $event->sender; if (!$storage->getFilesystem()->has('.dirindex')) { $storage->getFilesystem()->write('.dirindex', 1); $dirindex = 1; } else { $dirindex = $storage->getFilesystem()->read('.dirindex'); } if ($storage->maxDirFiles !== -1) { if ($storage->getFilesystem()->has($dirindex)) { $filesCount = count($storage->getFilesystem()->listContents($dirindex)); if ($filesCount > $storage->maxDirFiles) { $dirindex++; $storage->getFilesystem()->createDir($dirindex); } } else { $storage->getFilesystem()->createDir($dirindex); } } }); $client = new \Sabre\DAV\Client(['baseUri' => 'https://webdav.yandex.ru']); $client->addCurlSetting(CURLOPT_SSL_VERIFYPEER, false); $client->addCurlSetting(CURLOPT_HTTPHEADER, ['Authorization: OAuth TOKENTOKENTOKEN', 'Accept: */*', 'Host: webdav.yandex.ru']); $adapter = new WebDAVAdapter($client, '/'); $flysystem = new Filesystem($adapter); if (!$flysystem->has($this->pathPrefix)) { $flysystem->createDir($this->pathPrefix); } $adapter->setPathPrefix($this->pathPrefix); return $flysystem; }
/** * @return \denoll\filekit\Storage * @throws \yii\base\InvalidConfigException */ protected function getFileStorage() { if ($this->allowChangeFilestorage) { $fileStorage = \Yii::$app->request->get($this->fileStorageParam); } else { $fileStorage = $this->fileStorage; } $fileStorage = Instance::ensure($fileStorage, Storage::className()); return $fileStorage; }
/** * @return \denoll\filekit\Storage * @throws \yii\base\InvalidConfigException */ protected function getStorage() { if (!$this->storage) { $this->storage = Instance::ensure($this->filesStorage, Storage::className()); } return $this->storage; }