Mercurial > hg > cmmr2012-drupal-site
comparison core/lib/Drupal/Core/Archiver/Tar.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\Archiver; | |
4 | |
5 /** | |
6 * Defines a archiver implementation for .tar files. | |
7 */ | |
8 class Tar implements ArchiverInterface { | |
9 | |
10 /** | |
11 * The underlying ArchiveTar instance that does the heavy lifting. | |
12 * | |
13 * @var \Drupal\Core\Archiver\ArchiveTar | |
14 */ | |
15 protected $tar; | |
16 | |
17 /** | |
18 * Constructs a Tar object. | |
19 * | |
20 * @param string $file_path | |
21 * The full system path of the archive to manipulate. Only local files | |
22 * are supported. If the file does not yet exist, it will be created if | |
23 * appropriate. | |
24 * | |
25 * @throws \Drupal\Core\Archiver\ArchiverException | |
26 */ | |
27 public function __construct($file_path) { | |
28 $this->tar = new ArchiveTar($file_path); | |
29 } | |
30 | |
31 /** | |
32 * {@inheritdoc} | |
33 */ | |
34 public function add($file_path) { | |
35 $this->tar->add($file_path); | |
36 | |
37 return $this; | |
38 } | |
39 | |
40 /** | |
41 * {@inheritdoc} | |
42 */ | |
43 public function remove($file_path) { | |
44 // @todo Archive_Tar doesn't have a remove operation | |
45 // so we'll have to simulate it somehow, probably by | |
46 // creating a new archive with everything but the removed | |
47 // file. | |
48 | |
49 return $this; | |
50 } | |
51 | |
52 /** | |
53 * {@inheritdoc} | |
54 */ | |
55 public function extract($path, array $files = []) { | |
56 if ($files) { | |
57 $this->tar->extractList($files, $path); | |
58 } | |
59 else { | |
60 $this->tar->extract($path); | |
61 } | |
62 | |
63 return $this; | |
64 } | |
65 | |
66 /** | |
67 * {@inheritdoc} | |
68 */ | |
69 public function listContents() { | |
70 $files = []; | |
71 foreach ($this->tar->listContent() as $file_data) { | |
72 $files[] = $file_data['filename']; | |
73 } | |
74 return $files; | |
75 } | |
76 | |
77 /** | |
78 * Retrieves the tar engine itself. | |
79 * | |
80 * In some cases it may be necessary to directly access the underlying | |
81 * Archive_Tar object for implementation-specific logic. This is for advanced | |
82 * use only as it is not shared by other implementations of ArchiveInterface. | |
83 * | |
84 * @return Archive_Tar | |
85 * The Archive_Tar object used by this object. | |
86 */ | |
87 public function getArchive() { | |
88 return $this->tar; | |
89 } | |
90 | |
91 } |