[BUGFIX] Fix the unit tests to work with PHPUnit 3.6
[Packages/TYPO3.CMS.git] / t3lib / file / ProcessedFile.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2012 Benjamin Mack <benni@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28
29 /**
30 * Representation of a specific processing of a file.
31 *
32 * @author Benjamin Mack <benni@typo3.org>
33 * @package TYPO3
34 * @subpackage t3lib
35 */
36 class t3lib_file_ProcessedFile extends t3lib_file_AbstractFile {
37
38 /*********************************************
39 * FILE PROCESSING CONTEXTS
40 *********************************************/
41
42 /**
43 * Basic processing context to get a processed image with smaller
44 * width/height to render a preview
45 */
46 const CONTEXT_IMAGEPREVIEW = 'image.preview';
47
48 /**
49 * Processing context
50 *
51 * @var string
52 */
53 protected $context;
54
55 /**
56 * check if the file is processed
57 *
58 * @var boolean
59 */
60 protected $processed;
61
62 /**
63 * Processing configuration
64 *
65 * @var array
66 */
67 protected $processingConfiguration;
68
69 /**
70 * Reference to the original File object underlying this FileReference.
71 *
72 * @var t3lib_file_File
73 */
74 protected $originalFile;
75
76 /**
77 * Constructor for a file processing object. Should normally not be used
78 * directly, use the corresponding factory methods instead.
79 *
80 * @param t3lib_file_File $originalFile
81 * @param string $context
82 * @param array $processingConfiguration
83 */
84 public function __construct(t3lib_file_File $originalFile, $context, array $processingConfiguration) {
85 $this->originalFile = $originalFile;
86 $this->context = $context;
87 $this->processingConfiguration = $processingConfiguration;
88 }
89
90 /*******************************
91 * VARIOUS FILE PROPERTY GETTERS
92 ************************
93
94 /**
95 * Returns the Sha1 of this file
96 *
97 * @return string
98 */
99 public function calculateChecksum() {
100 return t3lib_div::shortMD5($this->originalFile->getUid() . $this->context . serialize($this->processingConfiguration));
101 }
102
103 /******************
104 * CONTENTS RELATED
105 ******************/
106
107 /**
108 * Replace the current file contents with the given string
109 *
110 * @param string $contents The contents to write to the file.
111 * @return t3lib_file_File The file object (allows chaining).
112 */
113 public function setContents($contents) {
114 throw new BadMethodCallException('Setting contents not possible for processed file.', 1305438528);
115 }
116
117 /****************************************
118 * STORAGE AND MANAGEMENT RELATED METHDOS
119 ****************************************/
120
121 /**
122 * Returns TRUE if this file is indexed
123 *
124 * @return boolean
125 */
126 public function isIndexed() {
127 return FALSE;
128 }
129
130 /*****************
131 * SPECIAL METHODS
132 *****************/
133 /**
134 * Returns TRUE if this file is already processed.
135 *
136 * @return boolean
137 */
138 public function isProcessed() {
139 return $this->processed;
140 }
141
142 /**
143 * Called when the processed file is processed
144 *
145 * @param boolean $isProcessed
146 * @return void
147 */
148 public function setProcessed($isProcessed) {
149 $this->processed = (boolean) $isProcessed;
150
151 // DB-query to insert the info
152 /** @var $processedFileRepository t3lib_file_Repository_ProcessedFileRepository */
153 $processedFileRepository = t3lib_div::makeInstance('t3lib_file_Repository_ProcessedFileRepository');
154 $processedFileRepository->add($this);
155 }
156
157 /**
158 * @return t3lib_file_File
159 */
160 public function getOriginalFile() {
161 return $this->originalFile;
162 }
163
164 /**
165 * Updates properties of this object.
166 * This method is used to reconstitute settings from the
167 * database into this object after being intantiated.
168 *
169 * @param array $properties
170 */
171 public function updateProperties(array $properties) {
172 if ($properties['name']) {
173 $this->name = $properties['name'];
174 }
175 if ($properties['identifier']) {
176 $this->identifier = $properties['identifier'];
177 }
178 if (t3lib_utility_Math::canBeInterpretedAsInteger($properties['storage'])) {
179 $this->setStorage($properties['storage']);
180 }
181 $this->properties = array_merge($this->properties, $properties);
182 }
183
184 /**
185 * basic array function for the DB update
186 * @return array
187 */
188 public function toArray() {
189 // @todo: define what we need here
190 return array(
191 'storage' => $this->getStorage()->getUid(),
192 'identifier' => $this->getIdentifier(),
193 'name' => $this->getName(),
194 'is_processed' => intval($this->processed),
195 'checksum' => $this->calculateChecksum(),
196 'context' => $this->context,
197 'configuration' => serialize($this->processingConfiguration),
198 'original' => $this->originalFile->getUid(),
199 );
200 }
201 }
202
203 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/file/ProcessedFile.php'])) {
204 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/file/ProcessedFile.php']);
205 }
206
207 ?>