-
-
Notifications
You must be signed in to change notification settings - Fork 179
/
Copy pathChunkFile.php
99 lines (86 loc) · 1.92 KB
/
ChunkFile.php
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Pion\Laravel\ChunkUpload;
use Pion\Laravel\ChunkUpload\Storage\ChunkStorage;
/**
* Class Chunk.
*/
class ChunkFile
{
/**
* @var string
*/
protected $path;
/**
* @var int
*/
protected $modifiedTime;
/**
* The chunk storage.
*
* @var ChunkStorage
*/
protected $storage;
/**
* Creates the chunk file.
*
* @param string $path
* @param int $modifiedTime
* @param ChunkStorage $storage
*/
public function __construct($path, $modifiedTime, $storage)
{
$this->path = $path;
$this->modifiedTime = $modifiedTime;
$this->storage = $storage;
}
/**
* @return string relative to the disk
*/
public function getPath()
{
return $this->path;
}
public function getAbsolutePath()
{
$pathPrefix = $this->storage->getDiskPathPrefix();
return $pathPrefix.'/'.$this->path;
}
/**
* @return int
*/
public function getModifiedTime()
{
return $this->modifiedTime;
}
/**
* Moves the chunk file to given relative path (within the disk).
*
* @param string $pathTo
*
* @return bool
*/
public function move($pathTo)
{
return $this->storage->disk()->move($this->path, $pathTo);
}
/**
* Deletes the chunk file.
*
* @return bool
*/
public function delete()
{
return $this->storage->disk()->delete($this->path);
}
/**
* The __toString method allows a class to decide how it will react when it is converted to a string.
*
* @return string
*
* @see http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.tostring
*/
public function __toString()
{
return sprintf('ChunkFile %s uploaded at %s', $this->getPath(), date('Y-m-d H:i:s', $this->getModifiedTime()));
}
}