1 | <?php |
||
17 | class Generic implements CompressibleInterface |
||
18 | { |
||
19 | /** @var Compressor Parent compressing object */ |
||
20 | protected $parent; |
||
21 | |||
22 | /** @var string[] Collection of ignored file extensions */ |
||
23 | protected $ignoredExtensions = array('php', 'txt', 'js', 'css', 'md', 'map', 'dbs', 'vphp', 'less' , 'gz', 'lock', 'json', 'sql', 'xml', 'yml'); |
||
24 | |||
25 | /** @var string[] Collection of ignored files */ |
||
26 | protected $ignoredFiles = array('.project', '.buildpath', '.gitignore', '.travis.yml', 'phpunit.xml', 'thumbs.db'); |
||
27 | |||
28 | /** @var string[] Collection of ignored folders */ |
||
29 | protected $ignoredFolders = array('vendor', 'var', 'docs'); |
||
30 | |||
31 | /** @var string[] Collection of module paths for creating beautiful structure */ |
||
32 | protected $moduleFolders = array(); |
||
33 | |||
34 | /** |
||
35 | * @param Compressor $compressor Pointer to parent compressing object |
||
36 | * @param string[] $ignoredExtensions Collection of ignored file extensions |
||
37 | * @param string[] $ignoredFiles Collection of ignored files |
||
38 | * @param string[] $ignoredFolders Collection of ignored folders |
||
39 | */ |
||
40 | public function __construct(Compressor & $compressor, $ignoredExtensions = array(), $ignoredFiles = array(), $ignoredFolders = array()) |
||
41 | { |
||
42 | $this->parent = & $compressor; |
||
43 | |||
44 | // TODO: Maybe we need to fully override defaults, or merge? |
||
45 | |||
46 | // Merge passed parameters |
||
47 | $this->ignoredExtensions = array_merge($this->ignoredExtensions, $ignoredExtensions); |
||
48 | $this->ignoredFiles = array_merge($this->ignoredFiles, $ignoredFiles); |
||
49 | $this->ignoredFolders = array_merge($this->ignoredFolders, $ignoredFolders); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Create folder, method use recursive approach for creating if |
||
54 | * "folder/folder/.." is passed. |
||
55 | * @param string $path Folder path |
||
56 | * @param string $group Folder group(www-data) |
||
57 | * @param int $mode Folder mode(0775) |
||
58 | * @return int 1 - success, 0 - folder exists, -1 - errors |
||
59 | */ |
||
60 | public function createFolderStructure($path, $group = 'www-data', $mode = 0775) |
||
78 | |||
79 | /** |
||
80 | * Update file resource |
||
81 | * @param string $fromFilePath Source file path |
||
82 | * @param string $toFilePath Destination file path |
||
83 | */ |
||
84 | protected function update($fromFilePath, $toFilePath) |
||
85 | { |
||
86 | copy($fromFilePath, $toFilePath); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Compress file resource |
||
91 | * @param string $fromFilePath Source file path |
||
92 | * @param string $toFilePath Destination file path |
||
93 | * @return mixed Compression result |
||
94 | */ |
||
95 | public function compress($fromFilePath, $toFilePath) |
||
122 | |||
123 | /** |
||
124 | * Define if this file is a valid resource |
||
125 | * @param string $filePath File path |
||
126 | * @return bool True if file is valid |
||
127 | */ |
||
128 | protected function isValid($filePath) |
||
156 | } |
||
157 |
If you suppress an error, we recommend checking for the error condition explicitly: