1 | <?php |
||
5 | abstract class AbstractName implements NameInterface |
||
6 | { |
||
7 | /** |
||
8 | * The stack of name parts. |
||
9 | * |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $nameStack = []; |
||
13 | |||
14 | /** |
||
15 | * Construct a new name given the name stack parts. |
||
16 | * |
||
17 | * @param array $parts |
||
18 | */ |
||
19 | private function __construct($parts) |
||
23 | |||
24 | /** |
||
25 | * Construct a new name from the supplied function arguments. |
||
26 | * Eg: fromArgs('Hubert', 'Cumberdale') |
||
27 | * |
||
28 | * @return self |
||
29 | */ |
||
30 | public static function fromArgs() |
||
34 | |||
35 | /** |
||
36 | * Construct a new name from the supplied array. |
||
37 | * Eg: fromArray(['Hubert', 'Cumberdale']) |
||
38 | * |
||
39 | * @return self |
||
40 | */ |
||
41 | public static function fromArray($parts) |
||
45 | |||
46 | /** |
||
47 | * Construct a new name from the supplied string. |
||
48 | * Eg: fromString('Hubert Cumberdale') |
||
49 | * |
||
50 | * @return self |
||
51 | */ |
||
52 | public static function fromString($string) |
||
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | abstract public function full(); |
||
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | abstract public function first($short = false); |
||
66 | |||
67 | /** |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | abstract public function middle($short = false); |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
74 | */ |
||
75 | abstract public function last($short = false); |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | public function atIndex($index) |
||
88 | |||
89 | /** |
||
90 | * The number of elements in the name stack. |
||
91 | * |
||
92 | * @return int |
||
93 | */ |
||
94 | protected function stackCount() |
||
98 | |||
99 | /** |
||
100 | * Peel back from the end of the name stack at the given depth |
||
101 | * and return the name portion located there. |
||
102 | * |
||
103 | * @param integer $depth The depth to traverse back by. |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | protected function peel($depth = 1) |
||
111 | |||
112 | /** |
||
113 | * Returns an array slice from the given start (from) and end (to) |
||
114 | * locations. |
||
115 | * |
||
116 | * @param int $from The starting location. |
||
117 | * @param int $to The ending location. |
||
118 | * |
||
119 | * @return array |
||
120 | */ |
||
121 | protected function slice($from, $to) |
||
133 | |||
134 | /** |
||
135 | * Shorten the given string part. |
||
136 | * |
||
137 | * @param string $part |
||
138 | * |
||
139 | * @return string |
||
140 | */ |
||
141 | protected function shorten($part) |
||
145 | |||
146 | /** |
||
147 | * Walks over the array and returns a copy with all unwanted |
||
148 | * whitespace stripped out. |
||
149 | * |
||
150 | * @param array $parts The array to process. |
||
151 | * |
||
152 | * @return array |
||
153 | */ |
||
154 | protected function removeUnwantedWhitespace($parts) |
||
160 | } |
||
161 |