1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Util |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (c) Gjero Krsteski (http://krsteski.de) |
6
|
|
|
* @license http://opensource.org/licenses/MIT MIT License |
7
|
|
|
*/ |
8
|
|
|
namespace Pimf\Util; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Value |
12
|
|
|
* |
13
|
|
|
* @package Util |
14
|
|
|
* @author Gjero Krsteski <[email protected]> |
15
|
|
|
*/ |
16
|
|
|
class Value |
17
|
|
|
{ |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var string |
21
|
|
|
*/ |
22
|
|
|
protected $value; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @param string $string |
26
|
|
|
*/ |
27
|
|
|
public function __construct($string) |
28
|
|
|
{ |
29
|
|
|
$this->value = '' . $string; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function __toString() |
33
|
|
|
{ |
34
|
|
|
return $this->value; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param string $string |
39
|
|
|
* |
40
|
|
|
* @return $this |
41
|
|
|
*/ |
42
|
|
|
public function prepend($string) |
43
|
|
|
{ |
44
|
|
|
$this->value = Character::ensureLeading($string, $this->value); |
45
|
|
|
|
46
|
|
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param string $string |
51
|
|
|
* |
52
|
|
|
* @return $this |
53
|
|
|
*/ |
54
|
|
|
public function append($string) |
55
|
|
|
{ |
56
|
|
|
$this->value = Character::ensureTrailing($string, $this->value); |
57
|
|
|
|
58
|
|
|
return $this; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @param string $string |
63
|
|
|
* |
64
|
|
|
* @return $this |
65
|
|
|
*/ |
66
|
|
|
public function deleteTrailing($string) |
67
|
|
|
{ |
68
|
|
|
$this->value = Character::deleteTrailing($string, $this->value); |
69
|
|
|
|
70
|
|
|
return $this; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @param string $string |
75
|
|
|
* |
76
|
|
|
* @return $this |
77
|
|
|
*/ |
78
|
|
|
public function deleteLeading($string) |
79
|
|
|
{ |
80
|
|
|
$this->value = Character::deleteLeading($string, $this->value); |
81
|
|
|
|
82
|
|
|
return $this; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @param string|array $mixed String or list of strings |
87
|
|
|
* |
88
|
|
|
* @return boolean |
89
|
|
|
*/ |
90
|
|
|
public function contains($mixed) |
91
|
|
|
{ |
92
|
|
|
return Character::contains($this->value, $mixed); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @param string|array $with String or list of strings |
97
|
|
|
* |
98
|
|
|
* @return boolean |
99
|
|
|
*/ |
100
|
|
|
public function starts($with) |
101
|
|
|
{ |
102
|
|
|
return Character::startsWith($this->value, $with); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param string|array $with String or list of strings |
107
|
|
|
* |
108
|
|
|
* @return boolean |
109
|
|
|
*/ |
110
|
|
|
public function ends($with) |
111
|
|
|
{ |
112
|
|
|
return Character::endsWith($this->value, $with); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param string $byString The delimiter string |
117
|
|
|
* |
118
|
|
|
* @return array |
119
|
|
|
*/ |
120
|
|
|
public function explode($byString) |
121
|
|
|
{ |
122
|
|
|
return explode('' . $byString, $this->value); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|