-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathExportEval.php
More file actions
36 lines (30 loc) · 886 Bytes
/
ExportEval.php
File metadata and controls
36 lines (30 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
namespace DrupalCodeBuilder\Storage;
/**
* Provides a storage handler that uses PHP exported variables in files.
*
* This is intended for use with the sample data used by our unit tests. Yes,
* eval() is evil, but this makes the resulting storage files human-readable.
*/
class ExportEval extends StorageBase {
/**
* {@inheritdoc}
*/
public function store($key, $data) {
$directory = $this->environment->getDataDirectory();
$export = var_export($data, TRUE);
file_put_contents("{$directory}/{$key}_processed.php", $export);
}
/**
* {@inheritdoc}
*/
public function retrieve($key) {
$directory = $this->environment->getDataDirectory();
$data_file = "$directory/{$key}_processed.php";
if (file_exists($data_file)) {
eval('$data = ' . file_get_contents($data_file) . ';');
return $data;
}
return [];
}
}