PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / helpers / src / archive / factory.php

factory.php in VikBooking Hotel Booking Engine & PMS trunk, at admin/helpers/src/archive/factory.php

97 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Archives helper class.
16 *
17 * @since 1.5
18 */
19 abstract class VBOArchiveFactory
20 {
21 /**
22 * Extracts the file from a package.
23 *
24 * @param string $source The path of the package.
25 * @param string $destination The folder in which the files should be extracted.
26 *
27 * @return bool True on success, false otherwise.
28 *
29 * @throws Exception
30 */
31 public static function extract($source, $destination)
32 {
33 return static::getInstance($source)->extract($source, $destination);
34 }
35
36 /**
37 * Compresses the specified folder into an archive.
38 *
39 * @param string $source The path of the folder to compress.
40 * @param string $destination The path of the resulting archive.
41 *
42 * @return bool True on success, false otherwise.
43 *
44 * @throws Exception
45 */
46 public static function compress($source, $destination)
47 {
48 return static::getInstance($destination)->compress($source, $destination);
49 }
50
51 /**
52 * Downloads the specified archive.
53 *
54 * @param string $source The path of the folder to compress.
55 *
56 * @return void
57 *
58 * @throws Exception
59 */
60 public static function download($source)
61 {
62 static::getInstance($source)->download($source);
63 }
64
65 /**
66 * Returns a new instance of the specified archive handler.
67 *
68 * @param string $type Either the archive type or a path, from which
69 * the file type will be extracted.
70 *
71 * @return VBOArchiveType
72 *
73 * @throws Exception
74 */
75 protected static function getInstance($type)
76 {
77 // check if we have a path
78 if (preg_match("/[\/\\\\]/", $type))
79 {
80 // extract file type from path
81 $type = pathinfo($type, PATHINFO_EXTENSION);
82 }
83
84 switch (strtolower($type))
85 {
86 case 'zip':
87
88 // create a new ZIP archive instance
89 return new VBOArchiveTypeZip;
90
91 default:
92 // invalid archive type
93 throw new Exception(sprintf('Archive [%s] not supported', $type), 500);
94 }
95 }
96 }
97