-
Notifications
You must be signed in to change notification settings - Fork 0
/
Archive.php
104 lines (96 loc) · 2.51 KB
/
Archive.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
100
101
102
103
104
<?php
/**
* This file is part of the Zest Framework.
*
* @author Muhammad Umer Farooq (Malik) <[email protected]>
*
* @link https://github.com/zestframework/Zest_Framework
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @license MIT
*
* @since 3.0.0
*/
namespace Zest\Archive;
class Archive
{
/**
* Store the adapter object.
*
* @since 3.0.0
*
* @var object
*/
private $adapter = null;
/**
* The constructor.
*
* @since 3.0.0
*/
public function __construct($adapter = null)
{
if (\defined('__ZEST__ROOT__')) {
$this->setAdapter(__config('archive.driver'));
}
if (adapter !== null) {
$this->setAdapter($adapter);
}
}
/**
* Set the adapter.
*
* @param (string) $adapter
*
* @since 3.0.0
*
* @return object
*/
public function setAdapter($adapter): self
{
switch (strtolower($adapter)) {
case 'bzip':
$adapterSet = '\Zest\Archive\Adapter\Bzip';
break;
case 'gzip':
$adapterSet = '\Zest\Archive\Adapter\Gzip';
break;
default:
$adapterSet = '\Zest\Archive\Adapter\Zip';
break;
}
$this->adapter = new $adapterSet();
return $this;
}
/**
* Open and extract the archive.
*
* @param (string) $file The file that you want uncompress/open.
* @param (string) $target Where to extract the file.
* @param (bool) $delete True to delete the file; False to not delete it.
*
* @since 1.0.0
*
* @return bool True when succeeded; False when failed.
*/
public function extract(string $file, string $target, bool $delete = false): bool
{
return $this->adapter->extract($file, $target, $delete);
}
/**
* Compress the file to an archive.
*
* @param (mixed) $files The file(/s) that you want compress.
* @param (string) $destination The file destination.
* @param (bool) $overwrite True to delete the file; False to not delete it.
*
* @since 1.0.0
*
* @return bool True when succeeded; False when failed.
*/
public function compress($files, string $destination = '', bool $overwrite = false): bool
{
return $this->adapter->compress($files, $destination, $overwrite);
}
}