|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace BigFileTools; |
|
4
|
|
|
use BigFileTools\Driver\SizeDriverAggregator; |
|
5
|
|
|
use BigFileTools\Driver\ComDriver; |
|
6
|
|
|
use BigFileTools\Driver\CurlDriver; |
|
7
|
|
|
use BigFileTools\Driver\ExecDriver; |
|
8
|
|
|
use BigFileTools\Driver\ISizeDriver; |
|
9
|
|
|
use BigFileTools\Driver\NativeSeekDriver; |
|
10
|
|
|
use BigFileTools\Driver\SizeDriverFactory; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @author Honza Kuchař |
|
14
|
|
|
* @license New BSD |
|
15
|
|
|
* @encoding UTF-8 |
|
16
|
|
|
* @copyright Copyright (c) 2016, Jan Kuchař |
|
17
|
|
|
*/ |
|
18
|
|
|
class BigFileTools { |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Create BigFileTools from $path |
|
22
|
|
|
* @param string $path |
|
23
|
|
|
* @return File |
|
24
|
|
|
* @deprecated |
|
25
|
|
|
*/ |
|
26
|
|
|
static function fromPath($path) { |
|
|
|
|
|
|
27
|
|
|
return static::createDefault()->getFile($path); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var SizeDriverAggregator |
|
32
|
|
|
*/ |
|
33
|
|
|
private $sizeDriver; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Create new instance of BigFileTools by providing list of drivers. |
|
37
|
|
|
* Those that cannot be initialized on given platform will be skipped. |
|
38
|
|
|
* @param string[] $drivers |
|
39
|
|
|
* @return static |
|
40
|
|
|
*/ |
|
41
|
|
|
public static function createFrom(array $drivers) { |
|
42
|
|
|
return new static( |
|
43
|
|
|
new SizeDriverAggregator( |
|
44
|
|
|
(new SizeDriverFactory($drivers))->getInitializedDrivers() |
|
45
|
|
|
) |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Create new instance of BigFileTools using default configuration. |
|
51
|
|
|
* This uses default drivers ordered by speed. |
|
52
|
|
|
* @return static |
|
53
|
|
|
*/ |
|
54
|
|
|
public static function createDefault() { |
|
55
|
|
|
return static::createFrom([ |
|
56
|
|
|
CurlDriver::class, |
|
57
|
|
|
NativeSeekDriver::class, |
|
58
|
|
|
ComDriver::class, |
|
59
|
|
|
ExecDriver::class, |
|
60
|
|
|
//NativeReadDriver::class, |
|
61
|
|
|
]); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Constructor - do not call directly |
|
66
|
|
|
* @param ISizeDriver $sizeDriver |
|
67
|
|
|
*/ |
|
68
|
|
|
function __construct(ISizeDriver $sizeDriver) |
|
69
|
|
|
{ |
|
70
|
|
|
$this->sizeDriver = $sizeDriver; |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Get file resource for further manipulation |
|
75
|
|
|
* @param string $path **full** path to file |
|
76
|
|
|
* @return File |
|
77
|
|
|
*/ |
|
78
|
|
|
public function getFile($path) |
|
79
|
|
|
{ |
|
80
|
|
|
return new File($path, $this->sizeDriver); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.