These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Wraps Image_Cached. This one we have to be a little more |
||
4 | * careful with because we don't keep a database record. |
||
5 | * |
||
6 | * NOTE: An Image_Cached can never actually be converted to |
||
7 | * one of these because it's not in the db. It must be created |
||
8 | * as this class (see CloudImage::getFormattedImage). |
||
9 | * |
||
10 | * @author Mark Guinn <[email protected]> |
||
11 | * @date 01.13.2014 |
||
12 | * @package cloudassets |
||
13 | * @subpackage wrappers |
||
14 | */ |
||
15 | class CloudImageCached extends CloudImage |
||
16 | { |
||
17 | /** @var CloudImageCachedStore */ |
||
18 | protected $storeRecord; |
||
19 | |||
20 | /** |
||
21 | * Create a new cached image. |
||
22 | * @param string $filename The filename of the image. |
||
23 | * @param boolean $isSingleton This this to true if this is a singleton() object, a stub for calling methods. |
||
24 | * Singletons don't have their defaults set. |
||
25 | */ |
||
26 | public function __construct($filename = null, $isSingleton = false) |
||
27 | { |
||
28 | parent::__construct(array(), $isSingleton); |
||
29 | $this->ID = -1; |
||
30 | $this->Filename = $filename; |
||
31 | |||
32 | // this covers the case where the image already exists in the cloud from a previous call |
||
33 | if (file_exists($this->getFullPath()) && $this->containsPlaceholder()) { |
||
0 ignored issues
–
show
|
|||
34 | $this->CloudStatus = 'Live'; |
||
0 ignored issues
–
show
The property
CloudStatus does not exist on object<CloudImageCached> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?php
/**
* @property int $x
* @property int $y
* @property string $text
*/
class MyLabel
{
private $properties;
private $allowedProperties = array('x', 'y', 'text');
public function __get($name)
{
if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
return $properties[$name];
} else {
return null;
}
}
public function __set($name, $value)
{
if (in_array($name, $this->allowedProperties)) {
$properties[$name] = $value;
} else {
throw new \LogicException("Property $name is not defined.");
}
}
}
Since the property has write access only, you can use the @property-write 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.
Loading history...
|
|||
35 | } |
||
36 | } |
||
37 | |||
38 | |||
39 | /** |
||
40 | * @return String |
||
41 | */ |
||
42 | public function getRelativePath() |
||
43 | { |
||
44 | return $this->getField('Filename'); |
||
45 | } |
||
46 | |||
47 | |||
48 | /** |
||
49 | * Prevent creating new tables for the cached record |
||
50 | * |
||
51 | * @return false |
||
52 | */ |
||
53 | public function requireTable() |
||
54 | { |
||
55 | return false; |
||
56 | } |
||
57 | |||
58 | |||
59 | /** |
||
60 | * Prevent writing the cached image to the database, but write the store record instead |
||
61 | */ |
||
62 | public function write($showDebug = false, $forceInsert = false, $forceWrite = false, $writeComponents = false) |
||
63 | { |
||
64 | //throw new Exception("{$this->ClassName} can not be written back to the database."); |
||
65 | // NOTE: we need to fail silently on writes because writing is part of the cloud upload process |
||
66 | if ($this->storeRecord) { |
||
67 | $this->storeRecord->write($showDebug, $forceInsert, $forceWrite, $writeComponents); |
||
68 | } |
||
69 | } |
||
70 | |||
71 | |||
72 | /** |
||
73 | * Simulates a delete |
||
74 | */ |
||
75 | public function delete() |
||
76 | { |
||
77 | $this->brokenOnDelete = true; |
||
78 | $this->onBeforeDelete(); |
||
79 | if ($this->brokenOnDelete) { |
||
80 | user_error("$this->class has a broken onBeforeDelete() function." |
||
81 | . " Make sure that you call parent::onBeforeDelete().", E_USER_ERROR); |
||
82 | } |
||
83 | |||
84 | $path = $this->getFullPath(); |
||
85 | if (file_exists($path)) { |
||
86 | unlink($path); |
||
87 | } |
||
88 | if ($this->storeRecord) { |
||
89 | $this->storeRecord->delete(); |
||
90 | } |
||
91 | |||
92 | $this->flushCache(); |
||
93 | $this->onAfterDelete(); |
||
94 | } |
||
95 | |||
96 | |||
97 | /** |
||
98 | * @param CloudImageCachedStore $store |
||
99 | * @return $this |
||
100 | */ |
||
101 | public function setStoreRecord(CloudImageCachedStore $store) |
||
102 | { |
||
103 | $this->storeRecord = $store; |
||
104 | $this->CloudStatus = $store->CloudStatus; |
||
105 | $this->CloudSize = $store->CloudSize; |
||
106 | $this->CloudMetaJson = $store->CloudMetaJson; |
||
107 | return $this; |
||
108 | } |
||
109 | |||
110 | |||
111 | /** |
||
112 | * @return CloudImageCachedStore |
||
113 | */ |
||
114 | public function getStoreRecord() |
||
115 | { |
||
116 | return $this->storeRecord; |
||
117 | } |
||
118 | |||
119 | |||
120 | /** |
||
121 | * @param $val |
||
122 | */ |
||
123 | public function setCloudMetaJson($val) |
||
124 | { |
||
125 | $this->setField('CloudMetaJson', $val); |
||
126 | if ($this->storeRecord) { |
||
127 | $this->storeRecord->CloudMetaJson = $val; |
||
128 | //$this->storeRecord->write(); |
||
129 | } |
||
130 | } |
||
131 | |||
132 | |||
133 | /** |
||
134 | * @param $val |
||
135 | */ |
||
136 | public function setCloudStatus($val) |
||
137 | { |
||
138 | $this->setField('CloudStatus', $val); |
||
139 | if ($this->storeRecord) { |
||
140 | $this->storeRecord->CloudStatus = $val; |
||
141 | //$this->storeRecord->write(); |
||
142 | } |
||
143 | } |
||
144 | |||
145 | |||
146 | /** |
||
147 | * @param $val |
||
148 | */ |
||
149 | public function setCloudSize($val) |
||
150 | { |
||
151 | $this->setField('CloudSize', $val); |
||
152 | if ($this->storeRecord) { |
||
153 | $this->storeRecord->CloudSize = $val; |
||
154 | //$this->storeRecord->write(); |
||
155 | } |
||
156 | } |
||
157 | } |
||
158 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: