Blame view

common/components/archives/RarArchiveReader.php 1.61 KB
57e5a4b9   Mihail   add classes to wo...
1
2
3
4
5
6
7
8
  <?php
  /**
   * Created by PhpStorm.
   * User: Tsurkanov
   * Date: 03.11.2015
   * Time: 15:12
   */
  
4f3f27e8   Mihail   temp commit - tes...
9
  namespace common\components\archives;
57e5a4b9   Mihail   add classes to wo...
10
11
12
13
  
  
  class RarArchiveReader extends  ArchiveReader {
  
d95262f3   Mihail   finish with mail ...
14
15
16
17
18
19
20
  
      /**
       * @param $file - имя открываемого архива
       * @param string $password
       * @return bool
       * @throws \Exception
       */
57e5a4b9   Mihail   add classes to wo...
21
      public  function open( $file, $password = '' ){
4f3f27e8   Mihail   temp commit - tes...
22
  
d95262f3   Mihail   finish with mail ...
23
          $this->resource = \RarArchive::open( $file, $password );
4f3f27e8   Mihail   temp commit - tes...
24
          if ($this->resource === FALSE)
d95262f3   Mihail   finish with mail ...
25
26
27
              throw new \Exception("Failed opening rar file {$file}");
  
          return true;
57e5a4b9   Mihail   add classes to wo...
28
29
      }
  
d95262f3   Mihail   finish with mail ...
30
31
32
33
34
35
      /**
       * @param $destination - путь куда положить распакованные файлы
       * если указан аттрибут $file_name_prefix то происходит переименование файла
       * в результате выполнения метода заполняется аттрибут $extracted_files извлеченными файлами
       * если извлечение не произошло аттрибут $extracted_files - пустой
       */
57e5a4b9   Mihail   add classes to wo...
36
      public  function extractTo( $destination){
d95262f3   Mihail   finish with mail ...
37
38
39
40
41
          $list = $this->resource->getEntries();
  
          foreach($list as $entry) {
  
              $new_destination = $destination . '/'  . $this->file_name_prefix .$entry->getName();
4f3f27e8   Mihail   temp commit - tes...
42
  
d95262f3   Mihail   finish with mail ...
43
              $entry->extract( $destination, $new_destination );
4f3f27e8   Mihail   temp commit - tes...
44
  
d95262f3   Mihail   finish with mail ...
45
              $this->setExtractedFiles( $new_destination, pathinfo( $entry->getName(), PATHINFO_EXTENSION ) );
4f3f27e8   Mihail   temp commit - tes...
46
47
  
          }
57e5a4b9   Mihail   add classes to wo...
48
  
d95262f3   Mihail   finish with mail ...
49
          $this->resource->close();
57e5a4b9   Mihail   add classes to wo...
50
      }
d95262f3   Mihail   finish with mail ...
51
  
57e5a4b9   Mihail   add classes to wo...
52
53
54
55
      public static  function getExtension(){
          return 'rar';
      }
  
57e5a4b9   Mihail   add classes to wo...
56
  }