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()) { |
|
|
|
|
34
|
|
|
$this->CloudStatus = 'Live'; |
|
|
|
|
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return bool |
40
|
|
|
*/ |
41
|
|
|
public function exists() |
42
|
|
|
{ |
43
|
|
|
return file_exists($this->getFullPath()); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return String |
48
|
|
|
*/ |
49
|
|
|
public function getRelativePath() |
50
|
|
|
{ |
51
|
|
|
return $this->getField('Filename'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Prevent creating new tables for the cached record |
57
|
|
|
* |
58
|
|
|
* @return false |
59
|
|
|
*/ |
60
|
|
|
public function requireTable() |
61
|
|
|
{ |
62
|
|
|
return false; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Prevent writing the cached image to the database, but write the store record instead |
68
|
|
|
*/ |
69
|
|
|
public function write($showDebug = false, $forceInsert = false, $forceWrite = false, $writeComponents = false) |
70
|
|
|
{ |
71
|
|
|
//throw new Exception("{$this->ClassName} can not be written back to the database."); |
72
|
|
|
// NOTE: we need to fail silently on writes because writing is part of the cloud upload process |
73
|
|
|
if ($this->storeRecord) { |
74
|
|
|
$this->storeRecord->write($showDebug, $forceInsert, $forceWrite, $writeComponents); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Simulates a delete |
81
|
|
|
*/ |
82
|
|
|
public function delete() |
83
|
|
|
{ |
84
|
|
|
$this->brokenOnDelete = true; |
85
|
|
|
$this->onBeforeDelete(); |
86
|
|
|
if ($this->brokenOnDelete) { |
87
|
|
|
user_error("$this->class has a broken onBeforeDelete() function." |
88
|
|
|
. " Make sure that you call parent::onBeforeDelete().", E_USER_ERROR); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
$path = $this->getFullPath(); |
92
|
|
|
if (file_exists($path)) { |
93
|
|
|
unlink($path); |
94
|
|
|
} |
95
|
|
|
if ($this->storeRecord) { |
96
|
|
|
$this->storeRecord->delete(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$this->flushCache(); |
100
|
|
|
$this->onAfterDelete(); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param CloudImageCachedStore $store |
106
|
|
|
* @return $this |
107
|
|
|
*/ |
108
|
|
|
public function setStoreRecord(CloudImageCachedStore $store) |
109
|
|
|
{ |
110
|
|
|
$this->storeRecord = $store; |
111
|
|
|
$this->CloudStatus = $store->CloudStatus; |
|
|
|
|
112
|
|
|
$this->CloudSize = $store->CloudSize; |
|
|
|
|
113
|
|
|
$this->CloudMetaJson = $store->CloudMetaJson; |
|
|
|
|
114
|
|
|
return $this; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* @return CloudImageCachedStore |
120
|
|
|
*/ |
121
|
|
|
public function getStoreRecord() |
122
|
|
|
{ |
123
|
|
|
return $this->storeRecord; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param $val |
129
|
|
|
*/ |
130
|
|
|
public function setCloudMetaJson($val) |
131
|
|
|
{ |
132
|
|
|
$this->setField('CloudMetaJson', $val); |
133
|
|
|
if ($this->storeRecord) { |
134
|
|
|
$this->storeRecord->CloudMetaJson = $val; |
|
|
|
|
135
|
|
|
//$this->storeRecord->write(); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @param $val |
142
|
|
|
*/ |
143
|
|
|
public function setCloudStatus($val) |
144
|
|
|
{ |
145
|
|
|
$this->setField('CloudStatus', $val); |
146
|
|
|
if ($this->storeRecord) { |
147
|
|
|
$this->storeRecord->CloudStatus = $val; |
|
|
|
|
148
|
|
|
//$this->storeRecord->write(); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
/** |
154
|
|
|
* @param $val |
155
|
|
|
*/ |
156
|
|
|
public function setCloudSize($val) |
157
|
|
|
{ |
158
|
|
|
$this->setField('CloudSize', $val); |
159
|
|
|
if ($this->storeRecord) { |
160
|
|
|
$this->storeRecord->CloudSize = $val; |
|
|
|
|
161
|
|
|
//$this->storeRecord->write(); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
|
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: