ArchiveCreator.php
1.71 KB
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
<?php
/**
* Created by PhpStorm.
* User: Tsurkanov
* Date: 03.11.2015
* Time: 14:51
*/
namespace common\components\archives;
class ArchiveCreator {
protected $handleExtension = ['rar', 'zip'];
public function create( $file, $ext ){
// if ( $this->isHandleableExtension( $ext )) {
// $arh_class = ucfirst( $ext ) . 'ArchiveReader';
// if ( class_exists( $arh_class ) ) {
//
// $arh_reader = new $arh_class();
//
// if ($arh_reader instanceof ArchiveReader ) {
// $arh_reader->open($file);
// return $arh_reader;
// }
//
// }
//
// }
if ( $ext = 'zip' ) {
$arh_reader = new ZipArchiveReader();
}else{
$arh_reader = new RarArchiveReader();
}
$arh_reader->open($file);
return $arh_reader;
// не найден подходящий обработчик
throw new \Exception( "Для расширения {$ext} не найден подходящий распаковщик" );
}
protected function isHandleableExtension( $ext ){
// $this->setHandleExtension( );
return (bool) array_search( $ext, $this->handleExtension);
}
// protected function setHandleExtension( ){
// if ( !$this->handleExtension ) {
// foreach (get_declared_classes() as $class) {
// if (is_subclass_of( $class, ArchiveReader::class ))
//
// $this->handleExtension[] = $class::getExtension();
//
// }
// }
// }
public function getHandleExtension( ){
// $this->setHandleExtension( );
return $this->handleExtension;
}
}