1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: joshgulledge |
5
|
|
|
* Date: 9/12/18 |
6
|
|
|
* Time: 12:38 PM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace LCI\Blend\Helpers; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class Format |
13
|
|
|
{ |
14
|
|
|
protected $path_time_stamp; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Format constructor. |
18
|
|
|
* @param null $path_time_stamp |
|
|
|
|
19
|
|
|
*/ |
20
|
|
|
public function __construct($path_time_stamp = null) |
21
|
|
|
{ |
22
|
|
|
if (!empty($path_time_stamp)) { |
23
|
|
|
$this->path_time_stamp = $path_time_stamp; |
24
|
|
|
} else { |
25
|
|
|
$this->path_time_stamp = date('Y_m_d_His'); |
26
|
|
|
} |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param string $type |
31
|
|
|
* @param string|null $name |
32
|
|
|
* @return string |
33
|
|
|
*/ |
34
|
|
|
public function getMigrationName($type, $name = null) |
35
|
|
|
{ |
36
|
|
|
$dir_name = 'm'.$this->path_time_stamp.'_'; |
37
|
|
|
if (empty($name)) { |
38
|
|
|
$name = ucfirst(strtolower($type)); |
39
|
|
|
if ($name == 'Mediasource') { |
40
|
|
|
$name = 'MediaSource'; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$dir_name .= preg_replace('/[^A-Za-z0-9\_]/', '', str_replace(['/', ' '], '_', $name)); |
45
|
|
|
|
46
|
|
|
return $dir_name; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @return false|string |
51
|
|
|
*/ |
52
|
|
|
public function getPathTimeStamp() |
53
|
|
|
{ |
54
|
|
|
return $this->path_time_stamp; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param mixed|array $data |
59
|
|
|
* @param int $tabs |
60
|
|
|
* |
61
|
|
|
* @return string |
62
|
|
|
*/ |
63
|
|
|
public function prettyVarExport($data, $tabs = 1) |
64
|
|
|
{ |
65
|
|
|
$spacing = str_repeat(' ', 4 * $tabs); |
66
|
|
|
|
67
|
|
|
$string = ''; |
68
|
|
|
$parts = preg_split('/\R/', var_export($data, true)); |
69
|
|
|
foreach ($parts as $k => $part) { |
70
|
|
|
if ($k > 0) { |
71
|
|
|
$string .= $spacing; |
72
|
|
|
} |
73
|
|
|
$string .= $part.PHP_EOL; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return trim($string); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @param false|string $path_time_stamp |
81
|
|
|
* @return Format |
82
|
|
|
*/ |
83
|
|
|
public function setPathTimeStamp($path_time_stamp) |
84
|
|
|
{ |
85
|
|
|
$this->path_time_stamp = $path_time_stamp; |
86
|
|
|
return $this; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
} |