1: <?php
2: namespace Datadepo\Api;
3:
4: class RunningFiles
5: {
6:
7:
8: protected $iniConfiguration;
9:
10:
11: protected $filename;
12:
13: 14: 15: 16:
17: public function __construct(IniConfiguration $iniConfiguration, $filename)
18: {
19: $this->iniConfiguration = $iniConfiguration;
20: $this->filename = $filename;
21: }
22:
23: 24: 25:
26: public function exists()
27: {
28: if (!$this->isActive()) {
29: return FALSE;
30: }
31: $file = $this->getRunningFile();
32: return is_file($file) && $this->isValid($file);
33: }
34:
35: 36:
37: public function create()
38: {
39: if (!$this->isActive()) {
40: return FALSE;
41: }
42: file_put_contents($this->getRunningFile(), time());
43: }
44:
45: 46:
47: public function delete()
48: {
49: if (!$this->isActive()) {
50: return FALSE;
51: }
52: unlink($this->getRunningFile());
53: }
54:
55:
56: 57: 58:
59: protected function isActive()
60: {
61: return $this->iniConfiguration->get('local', 'createRunningFiles');
62: }
63:
64: 65: 66:
67: protected function getRunningFile()
68: {
69: $tempPath = $this->iniConfiguration->getTempPath();
70: return $tempPath . '/' . $this->filename . '.running';
71: }
72:
73: 74: 75: 76:
77: protected function isValid($file)
78: {
79: $c = file_get_contents($file);
80: $validity = $this->iniConfiguration->get('local', 'runningFileValidity');
81: return $c + $validity >= time();
82: }
83:
84: }