Skip to content
This repository was archived by the owner on Jan 23, 2019. It is now read-only.

Commit fe52b5b

Browse files
committed
update
1 parent 7f93111 commit fe52b5b

9 files changed

+201
-31
lines changed

src/files/Backup.php

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: inhere
5+
* Date: 2017-03-24
6+
* Time: 10:33
7+
*/
8+
9+
namespace inhere\librarys\files;
10+
11+
/**
12+
* Class Backup
13+
* @package inhere\librarys\files
14+
*
15+
* ```
16+
* $bk = new Backup;
17+
*
18+
* ```
19+
*
20+
*/
21+
class Backup
22+
{
23+
// protected $srcPath = '';
24+
25+
/**
26+
* 备份保存目录
27+
* @var string
28+
*/
29+
protected $distPath = '';
30+
31+
/**
32+
* @var array
33+
*/
34+
protected $options = [
35+
'max_version' => 5, // 最多保留最近 5 个
36+
// 备份文件名
37+
// 可用标志
38+
// {name} 文件或目录名
39+
// {date} 当前日期 'YmdHis'
40+
// {time} 当前日期时间戳
41+
'filename' => '{name}-{date}',
42+
'compress' => 'zip', // 压缩格式 zip gzip phar tgz, 为空 直接拷贝目录备份
43+
];
44+
45+
protected $finder;
46+
47+
/**
48+
* Backup constructor.
49+
* @param $srcPath
50+
* @param $distPath
51+
* @param $options
52+
*/
53+
public function __construct($srcPath, $distPath, $options = [])
54+
{
55+
$this->distPath = $distPath;
56+
57+
$options = array_merge([
58+
'sourcePath' => $srcPath,
59+
'include' => [],
60+
'exclude' => [],
61+
], $options);
62+
63+
$this->finder = new FileFinder($options);
64+
}
65+
66+
public function dirs()
67+
{
68+
69+
}
70+
71+
public function files()
72+
{
73+
74+
}
75+
76+
public function pack()
77+
{
78+
79+
}
80+
81+
public function clearExpire($name)
82+
{
83+
84+
}
85+
}

src/files/FileFinder.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ class FileFinder extends StdBase
6262
protected $include = [
6363
'file' => ['README.md'],
6464
'ext' => [
65-
'js','css',
66-
'ttf','svg', 'eot', 'woff', 'woff2',
67-
'png', 'jpg', 'jpeg', 'gif', 'ico',
65+
// 'js','css',
66+
// 'ttf','svg', 'eot', 'woff', 'woff2',
67+
// 'png', 'jpg', 'jpeg', 'gif', 'ico',
6868
],
69-
'dir' => [], // ['dist'],
69+
'dir' => [], // ['dir'],
7070
];
7171

7272
/**

src/files/Compress.php src/files/Package.php

+9-10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
namespace inhere\librarys\files;
1010

1111
use inhere\librarys\exceptions\NotFoundException;
12+
use inhere\librarys\files\compress\AbstractCompressor;
1213
use inhere\librarys\helpers\ObjectHelper;
1314
use inhere\librarys\StdBase;
1415
use ZipArchive;
@@ -18,7 +19,7 @@
1819
* Class Compress
1920
* @package inhere\librarys\files
2021
*/
21-
class Compress extends FileFinder
22+
class Package
2223
{
2324
/**
2425
* dir path, wait compress ...
@@ -36,6 +37,11 @@ class Compress extends FileFinder
3637

3738
protected $type = 'zip';
3839

40+
/**
41+
* @var AbstractCompressor
42+
*/
43+
protected $compressor;
44+
3945
/**
4046
* 包含的可发布的 文件 文件扩展匹配 目录
4147
* 比 {@see $exlude} 优先级更高
@@ -60,19 +66,12 @@ class Compress extends FileFinder
6066
// public function __construct(array $config = [])
6167
// {}
6268

63-
public function reset()
64-
{
65-
$this->compressedFile = '';
66-
67-
return parent::reset();
68-
}
69-
70-
public function compress($sourcePath, $compressedFile, $type = self::TYPE_ZIP)
69+
public function pack($sourcePath, $saveTo, $type = self::TYPE_ZIP)
7170
{
7271

7372
}
7473

75-
public function uncompress()
74+
public function unpack($pack, $extractTo)
7675
{
7776

7877
}

src/files/compress/AbstractCompressor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace inhere\librarys\files\compress;
1010

11-
use inhere\librarys\exceptions\InvalidArgumentException;
11+
use inhere\exceptions\InvalidArgumentException;
1212
use inhere\librarys\files\FileFinder;
1313
use inhere\librarys\helpers\ObjectHelper;
1414
use inhere\librarys\StdBase;

src/files/compress/PharCompressor.php

+38-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,44 @@
1212
* Class PharCompressor
1313
* @package inhere\librarys\files\compress
1414
*/
15-
class PharCompressor
15+
class PharCompressor extends AbstractCompressor
1616
{
1717

18+
/**
19+
* @return bool
20+
*/
21+
public function isSupported()
22+
{
23+
// TODO: Implement isSupported() method.
24+
}
25+
26+
/**
27+
* @param string $sourcePath
28+
* @param string $archiveFile
29+
* @param bool $override
30+
* @return bool
31+
*/
32+
public function encode($sourcePath, $archiveFile, $override = true)
33+
{
34+
// TODO: Implement encode() method.
35+
}
36+
37+
/**
38+
* @param string $archiveFile
39+
* @param string $extractTo
40+
* @param bool $override
41+
* @return bool
42+
*/
43+
public function decode($archiveFile, $extractTo = '', $override = true)
44+
{
45+
// TODO: Implement decode() method.
46+
}
47+
48+
/**
49+
* @return mixed
50+
*/
51+
public function getDriver()
52+
{
53+
// TODO: Implement getDriver() method.
54+
}
1855
}

src/files/compress/TgzCompressor.php

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: inhere
5+
* Date: 16/8/28
6+
* Time: 上午2:14
7+
*/
8+
9+
namespace inhere\librarys\files\compress;
10+
11+
/**
12+
* Class TgzCompressor
13+
* @package inhere\librarys\files\compress
14+
*/
15+
class TgzCompressor extends GzipCompressor
16+
{
17+
}

src/functions.php

+39-13
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,57 @@ function html_minify($body)
2121
}
2222
}
2323

24+
if ( !function_exists('value') ) {
25+
/**
26+
* @param $value
27+
* @return mixed
28+
*
29+
* value(new Class)->xxx
30+
*/
31+
function value($value) {
32+
return $value;
33+
}
34+
}
35+
36+
if ( !function_exists('tap') ) {
37+
function tap($value, callable $callback) {
38+
39+
$callback($value);
40+
41+
return $value;
42+
}
43+
}
44+
2445
if ( !function_exists('cookie') ) {
2546
/**
2647
* cookie get or set
2748
* @param string|array $name
2849
* @param mixed $default
29-
* @param array $params
3050
* @return mixed
3151
*/
32-
function cookie($name, $default=null, array $params = [])
52+
function cookie($name, $default=null)
3353
{
3454
// set, when $name is array
3555
if ($name && is_array($name) ) {
36-
$p = array_merge([
37-
'expire' => null,
38-
'path' => null,
39-
'domain' => null,
40-
'secure' => null,
41-
'httponly' => null
42-
],$params);
56+
$d = [
57+
'value' => '', 'expire' => null, 'path' => null, 'domain' => null, 'secure' => null, 'httpOnly' => null
58+
];
4359

44-
foreach ($name as $key => $value) {
45-
if ($key && $value && is_string($key) && is_scalar($value)) {
46-
$_COOKIE[$key] = $value;
47-
setcookie($key, $value, $p['expire'], $p['path'], $p['domain'], $p['secure'], $p['httponly']);
60+
foreach ($name as $n => $value) {
61+
if ( !$n || !is_string($n) ) {
62+
continue;
4863
}
64+
65+
if ( is_array($value) ) {
66+
$d = array_merge($d, $value);
67+
} elseif (is_scalar($value)) {
68+
$d['value'] = $value;
69+
} else {
70+
continue;
71+
}
72+
73+
$_COOKIE[$n] = $d['value'];
74+
setcookie($n, $d['value'], $d['expire'], $d['path'], $d['domain'], $d['secure'], $d['httpOnly']);
4975
}
5076

5177
return $name;

src/traits/TraitUseOption.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace inhere\librarys\traits;
1212

13+
use inhere\librarys\helpers\ArrayHelper;
14+
1315
/**
1416
* Class TraitUseOption
1517
* @package inhere\librarys\traits
@@ -104,7 +106,8 @@ public function getOptions()
104106
public function setOptions($options, $merge = false)
105107
{
106108
if ( $merge ) {
107-
$this->options = array_merge($this->options, (array)$options);
109+
// $this->options = array_merge($this->options, (array)$options);
110+
$this->options = ArrayHelper::merge($this->options, (array)$options);
108111
} else {
109112
$this->options = $options;
110113
}

src/traits/TraitUseSimpleOption.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace inhere\librarys\traits;
1212

13+
use inhere\librarys\helpers\ArrayHelper;
14+
1315
/**
1416
* Class TraitUseSimpleOption
1517
* @package inhere\librarys\traits
@@ -86,7 +88,8 @@ public function getOptions()
8688
public function setOptions($options, $merge = false)
8789
{
8890
if ( $merge ) {
89-
$this->options = array_merge($this->options, $options);
91+
// $this->options = array_merge($this->options, $options);
92+
$this->options = ArrayHelper::merge($this->options, (array)$options);
9093
} else {
9194
$this->options = $options;
9295
}

0 commit comments

Comments
 (0)