forked from yii2tech/file-storage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBaseBucket.php
89 lines (80 loc) · 2.01 KB
/
BaseBucket.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
* @link https://github.com/yii2tech
* @copyright Copyright (c) 2015 Yii2tech
* @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
*/
namespace yii2tech\filestorage;
use Yii;
use yii\base\Object;
use yii\log\Logger;
/**
* BaseBucket is a base class for the file storage buckets.
*
* @property string $name bucket name.
* @property StorageInterface $storage file storage, which owns the bucket.
*
* @author Paul Klimov <[email protected]>
* @since 1.0
*/
abstract class BaseBucket extends Object implements BucketInterface
{
/**
* @var string bucket name.
*/
private $_name = '';
/**
* @var StorageInterface file storage, which owns the bucket.
*/
private $_storage = null;
/**
* Logs a message.
* @see Logger
* @param string $message message to be logged.
* @param integer $level the level of the message.
*/
protected function log($message, $level = Logger::LEVEL_INFO)
{
if (!YII_DEBUG && $level === Logger::LEVEL_INFO) {
return;
}
$category = get_class($this) . '(' . $this->getName() . ')';
Yii::getLogger()->log($message, $level, $category);
}
/**
* Sets bucket name.
* @param string $name - bucket name.
* @return boolean success.
*/
public function setName($name)
{
$this->_name = $name;
return true;
}
/**
* Gets current bucket name.
* @return string $name - bucket name.
*/
public function getName()
{
return $this->_name;
}
/**
* Sets bucket file storage.
* @param StorageInterface $storage - file storage.
* @return boolean success.
*/
public function setStorage(StorageInterface $storage)
{
$this->_storage = $storage;
return true;
}
/**
* Gets bucket file storage.
* @return StorageInterface - bucket file storage.
*/
public function getStorage()
{
return $this->_storage;
}
}