Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
PhpSerializationCompilationDataService | |
0.00% |
0 / 18 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
getOutputFileType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
writeCompilationData | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
readCompilationData | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | |
3 | namespace oat\taoQtiTest\models; |
4 | |
5 | use qtism\data\QtiComponent; |
6 | use qtism\data\AssessmentItemRef; |
7 | |
8 | /** |
9 | * PHP Serialization Compilation Data Service. |
10 | * |
11 | * This Compilation Data Service implementation aims at compiling |
12 | * Delivery data as PHP serialized data (see serialize/unserialize PHP |
13 | * core functions). |
14 | */ |
15 | class PhpSerializationCompilationDataService extends CompilationDataService |
16 | { |
17 | public const OUTPUT_FILE_TYPE = 'php'; |
18 | |
19 | /** |
20 | * @return string |
21 | */ |
22 | public function getOutputFileType() |
23 | { |
24 | return self::OUTPUT_FILE_TYPE; |
25 | } |
26 | |
27 | public function writeCompilationData( |
28 | \tao_models_classes_service_StorageDirectory $compilationDirectory, |
29 | $path, |
30 | QtiComponent $object |
31 | ) { |
32 | $path .= '.' . self::OUTPUT_FILE_TYPE; |
33 | |
34 | // Clone the component to make sure observers are not saved. |
35 | if ($object instanceof AssessmentItemRef) { |
36 | $object = clone $object; |
37 | } |
38 | |
39 | $compilationDirectory->write( |
40 | $path, |
41 | serialize($object) |
42 | ); |
43 | } |
44 | |
45 | public function readCompilationData( |
46 | \tao_models_classes_service_StorageDirectory $compilationDirectory, |
47 | $path, |
48 | $cacheInfo = '' |
49 | ) { |
50 | |
51 | $path .= '.' . self::OUTPUT_FILE_TYPE; |
52 | |
53 | if (($compilationData = $compilationDirectory->read($path)) !== false) { |
54 | if (($component = @unserialize($compilationData)) !== false) { |
55 | return $component; |
56 | } else { |
57 | $msg = "PHP Compilation Data '" . substr($compilationData, 0, 20) . "...' in directory '" |
58 | . $compilationDirectory->getId() . "' at path '" . $path . "' could not be unserialized properly."; |
59 | throw new \common_Exception($msg); |
60 | } |
61 | } else { |
62 | $msg = "PHP Compilation data in directory '" . $compilationDirectory->getId() |
63 | . "' could not be read properly."; |
64 | throw new \common_Exception($msg); |
65 | } |
66 | } |
67 | } |