Skip to content

Commit 108ff3c

Browse files
committed
Added GridFSFilesystem
1 parent 36497b9 commit 108ff3c

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/GridFSFilesystem.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* @link https://github.com/creocoder/yii2-flysystem
4+
* @copyright Copyright (c) 2015 Alexander Kochetov
5+
* @license http://opensource.org/licenses/BSD-3-Clause
6+
*/
7+
8+
namespace creocoder\flysystem;
9+
10+
use League\Flysystem\GridFS\GridFSAdapter;
11+
use MongoClient;
12+
use Yii;
13+
use yii\base\InvalidConfigException;
14+
15+
/**
16+
* GridFSFilesystem
17+
*
18+
* @author Alexander Kochetov <[email protected]>
19+
*/
20+
class GridFSFilesystem extends Filesystem
21+
{
22+
/**
23+
* @var string
24+
*/
25+
public $server;
26+
/**
27+
* @var string
28+
*/
29+
public $database;
30+
31+
/**
32+
* @inheritdoc
33+
*/
34+
public function init()
35+
{
36+
if ($this->server === null) {
37+
throw new InvalidConfigException('The "server" property must be set.');
38+
}
39+
40+
if ($this->database === null) {
41+
throw new InvalidConfigException('The "database" property must be set.');
42+
}
43+
44+
parent::init();
45+
}
46+
47+
/**
48+
* @return GridFSAdapter
49+
*/
50+
protected function prepareAdapter()
51+
{
52+
return new GridFSAdapter((new MongoClient($this->server))->selectDB($this->database)->getGridFS());
53+
}
54+
}

0 commit comments

Comments
 (0)