Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
CacheFile.php
Go to the documentation of this file.
1<?php
2
3namespace Ubiquity\cache;
4
6
7class CacheFile {
8 private $type;
9 private $name;
10 private $timestamp;
11 private $size;
12 private $file;
13
14 public function __construct($type = "", $name = "", $timestamp = 0, $size = 0, $fileKey = "") {
15 $this->type = $type;
16 $this->name = $name;
17 $this->timestamp = $timestamp;
18 $this->size = $size;
19 $this->file = $fileKey;
20 }
21
22 public static function initFromFiles($folder, $type, $keyFunction = null) {
23 $files = UFileSystem::glob_recursive ( $folder . \DS . '*' );
24 $result = [ ];
25 if (! isset ( $keyFunction )) {
26 $keyFunction = function ($file) {
27 return \basename ( $file );
28 };
29 }
30 foreach ( $files as $file ) {
31 if (is_file ( $file )) {
32 $result [] = new CacheFile ( $type, $keyFunction ( $file ), \filectime ( $file ), \filesize ( $file ), $file );
33 }
34 }
35 if (\count ( $result ) == 0)
36 $result [] = new CacheFile ( $type, "", "", "", "" );
37 return $result;
38 }
39
40 public static function delete($folder) {
41 $files = UFileSystem::glob_recursive ( $folder . \DS . '*' );
42 foreach ( $files as $file ) {
43 if (is_file ( $file )) {
44 \unlink ( $file );
45 }
46 }
47 }
48
49 public function getName() {
50 return $this->name;
51 }
52
53 public function setName($name) {
54 $this->name = $name;
55 return $this;
56 }
57
58 public function getTimestamp() {
59 return $this->timestamp;
60 }
61
62 public function setTimestamp($timestamp) {
63 $this->timestamp = $timestamp;
64 return $this;
65 }
66
67 public function getSize() {
68 return $this->size;
69 }
70
71 public function setSize($size) {
72 $this->size = $size;
73 return $this;
74 }
75
76 public function getType() {
77 return $this->type;
78 }
79
80 public function setType($type) {
81 $this->type = $type;
82 return $this;
83 }
84
85 public function getFile() {
86 return $this->file;
87 }
88
89 public function setFile($file) {
90 $this->file = $file;
91 return $this;
92 }
93}
static initFromFiles($folder, $type, $keyFunction=null)
Definition CacheFile.php:22
__construct($type="", $name="", $timestamp=0, $size=0, $fileKey="")
Definition CacheFile.php:14
File system utilities Ubiquity\utils\base$UFileSystem This class is part of Ubiquity.
Cache managment.
Definition CacheFile.php:3