This repository has been archived by the owner on May 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParser.php
91 lines (77 loc) · 2.02 KB
/
Parser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
namespace Gos\Component\Parser;
use Behat\Transliterator\Transliterator;
use Symfony\Component\Yaml\Parser as YamlParser;
class Parser
{
/**
* @param $filePath
* @param string $path
*
* @return mixed
*/
public static function yaml($filePath, $path = null)
{
$parser = new YamlParser();
$buffer = $parser->parse(file_get_contents($filePath));
if (null === $path) {
return $buffer;
}
foreach (explode('.', $path) as $path) {
$buffer = $buffer[$path];
}
return $buffer;
}
/**
* @param $string
* Camelize a string
* @return string
*/
public static function camelize($string)
{
/**
* This is a part of symfony2 | We duplicate it to avoid symfony2 dependency, if he is split, we will use it
* as dependency like Doctrine::Urlize with Behat
*/
return strtr(ucwords(strtr($string, ['_' => ' ', '.' => '_ ', '\\' => '_ '])), [' ' => '']);
}
/**
* @param $string
* Transliterate string to valide slug
* @return string
*/
public static function urlize($string)
{
return Transliterator::urlize($string);
}
/**
* @param string $string
* Split string with _
* @return string
*/
public static function underscore($string, $convertSpace = false)
{
$lookingFor = [
'/([A-Z]+)([A-Z][a-z])/',
'/([a-z\d])([A-Z])/',
];
$by = [
'\\1_\\2',
'\\1_\\2'
];
if (true === $convertSpace) {
$lookingFor[] = '/\s+/';
$by[] = '_';
}
return strtolower(preg_replace($lookingFor, $by, strtr($string, '_', '.')));
}
/**
* @param string $string
* Delete string accent
* @return string
*/
public static function unaccent($string)
{
return Transliterator::unaccent($string);
}
}