forked from idlesign/ist-yii-cfile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CFileHelper.php
100 lines (82 loc) · 2.25 KB
/
CFileHelper.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
90
91
92
93
94
95
96
97
98
99
100
<?php
require_once 'CFile.php';
/**
* Yii base class stab.
*
* Introduces property-like access to CFile methods.
*/
class CApplicationComponent {
public function __get($name) {
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter();
}
throw new Exception('Unable to get an unknown property ' . $name);
}
public function __set($name, $value) {
$setter = 'set' . $name;
if (method_exists($this, $setter)) {
return $this->$setter($value);
}
throw new Exception('Unable to set an unknown property ' . $name);
}
}
/**
* CFileHelper is used to access CFile functionality from environments
* without Yii Framework.
*
* Usage example:
*
* $cf_file = CFileHelper::get('files/test.txt');
*
*/
class CFileHelper extends CFile {
/**
* @var null|CFile
*/
private static $_obj = null;
private static $_log = array();
/**
* Helper method. Return an appropriate CFile instance for a given filesystem object path.
*
* @static
* @param string $filepath Path to the file.
* @param bool $greedy If `True` file properties (such as 'Size', 'Owner', 'Permission', etc.) would be autoloaded
* @return CFile
*/
public static function get($filepath, $greedy=false) {
if (self::$_obj===null) {
self::$_obj = new self();
}
return self::$_obj->set($filepath, $greedy);
}
/**
* Returns log data from class property.
*
* @return array
*/
public function getLog() {
return self::$_log;
}
/* ================================================== */
public static function getInstance($filepath) {
return parent::getInstance($filepath, __CLASS__);
}
/**
* Adds log data into into class property.
*
* Use {@link getLog} to get data.
*
* @param string $message
* @param string $level
*/
protected function addLog($message, $level='info') {
self::$_log[] = array($level, $message);
}
protected function getPathOfAlias($alias) {
return null;
}
protected function formatNumber ($number, $format) {
return (string)$number;
}
}