1 | <?php |
||
12 | class UploadController extends CompressableExternalModule |
||
13 | { |
||
14 | /** @var string Module identifier */ |
||
15 | public $id = 'upload'; |
||
16 | |||
17 | /** @var callable External handler to build relative file path */ |
||
18 | public $uploadDirHandler; |
||
19 | |||
20 | /** @var string Prefix for image path saving in db */ |
||
21 | public $pathPrefix = '/'; |
||
22 | |||
23 | /** @var callable External handler to build file name */ |
||
24 | public $fileNameHandler; |
||
25 | |||
26 | /** @var \samsonphp\fs\FileService Pointer to file system module */ |
||
27 | public $fs; |
||
28 | |||
29 | /** |
||
30 | * Init current file system module and server requests handler |
||
31 | */ |
||
32 | protected function initFileSystem() |
||
33 | { |
||
34 | /** @var \samsonphp\fs\FileService $fs */ |
||
35 | $fs = !isset($this->fs) ? $this->system->module('fs') : $this->fs; |
||
|
|||
36 | |||
37 | // Store pointer to file system module |
||
38 | $this->fs = $fs; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Initialize module |
||
43 | * @param array $params Collection of module parameters |
||
44 | * @return bool True if module successfully initialized |
||
45 | */ |
||
46 | public function init(array $params = array()) |
||
47 | { |
||
48 | // Init FileSystem and ServerHandler |
||
49 | $this->initFileSystem(); |
||
50 | |||
51 | // If no valid handlers are passed - use generic handlers |
||
52 | if (!isset($this->uploadDirHandler) || !is_callable($this->uploadDirHandler)) { |
||
53 | $this->uploadDirHandler = array($this, 'defaultDirHandler'); |
||
54 | } |
||
55 | |||
56 | // Call parent initialization |
||
57 | parent::init($params); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * Default relative path builder handler |
||
62 | * @return string Relative path for uploading |
||
63 | */ |
||
64 | public function defaultDirHandler() |
||
65 | { |
||
66 | // Default file path |
||
67 | $path = 'upload'; |
||
68 | |||
69 | // Create upload dir if it does not present |
||
70 | if (!$this->fs->exists($path)) { |
||
71 | $this->fs->mkDir($path); |
||
72 | } |
||
73 | |||
74 | return $path; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Returns a file size limit in bytes based on the PHP upload_max_filesize and post_max_size |
||
79 | * @return float Size value |
||
80 | */ |
||
81 | public function __async_maxfilesize() |
||
96 | |||
97 | /** |
||
98 | * Function to get size in bytes |
||
99 | * @param string $size File size string |
||
100 | * @return float Size number |
||
101 | */ |
||
102 | private function parseSize($size) |
||
116 | } |
||
117 |
Since your code implements the magic getter
_get
, this function will be called for any read access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.