1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Puzzle\Pieces; |
4
|
|
|
|
5
|
|
|
trait StringManipulation |
6
|
|
|
{ |
7
|
8 |
|
private function removeAccents($string) |
|
|
|
|
8
|
|
|
{ |
9
|
8 |
|
if(! is_string($string)) |
10
|
8 |
|
{ |
11
|
4 |
|
throw new \InvalidArgumentException('String expected'); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
$alphabet = array( |
15
|
4 |
|
'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A', |
16
|
4 |
|
'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I', |
17
|
4 |
|
'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U', |
18
|
4 |
|
'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a', |
19
|
4 |
|
'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i', |
20
|
4 |
|
'ï'=>'i', 'ð'=>'o', 'ñ'=>'n', 'ò'=>'o', 'ó'=>'o', 'ô'=>'o', 'õ'=>'o', 'ö'=>'o', 'ø'=>'o', 'ù'=>'u', |
21
|
4 |
|
'ú'=>'u', 'û'=>'u', 'ü'=>'u', 'ý'=>'y', 'ý'=>'y', 'þ'=>'b', 'ÿ'=>'y', 'ƒ'=>'f', |
22
|
4 |
|
); |
23
|
|
|
|
24
|
4 |
|
$text = strtr($string, $alphabet); |
25
|
|
|
|
26
|
4 |
|
return $text; |
27
|
|
|
} |
28
|
|
|
|
29
|
32 |
|
private function isConvertibleToString($value) |
30
|
|
|
{ |
31
|
32 |
|
if(is_scalar($value) || is_null($value)) |
32
|
32 |
|
{ |
33
|
16 |
|
return true; |
34
|
|
|
} |
35
|
|
|
|
36
|
16 |
|
if(! is_object($value)) |
37
|
16 |
|
{ |
38
|
4 |
|
return false; |
39
|
|
|
} |
40
|
|
|
|
41
|
12 |
|
return $value instanceof ConvertibleToString || method_exists($value, "__toString"); |
42
|
|
|
} |
43
|
|
|
|
44
|
16 |
|
private function convertToString($value) |
|
|
|
|
45
|
|
|
{ |
46
|
16 |
|
if($this->isConvertibleToString($value)) |
47
|
16 |
|
{ |
48
|
10 |
|
return (string) $value; |
49
|
|
|
} |
50
|
|
|
|
51
|
6 |
|
return gettype($value); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|