|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Ariadne Component Library. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Muze <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace arc; |
|
13
|
|
|
|
|
14
|
|
|
class xml |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
2 |
|
public static function __callStatic( $name, $args ) |
|
18
|
|
|
{ |
|
19
|
2 |
|
return call_user_func_array( [ new xml\Writer(), $name ], $args ); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
2 |
|
public static function parse( $xml, $encoding = null ) |
|
23
|
|
|
{ |
|
24
|
2 |
|
$parser = new xml\Parser(); |
|
25
|
2 |
|
return $parser->parse( $xml, $encoding ); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
1 |
|
public static function css2XPath( $cssSelector ) |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
/* based on work by Tijs Verkoyen - http://blog.verkoyen.eu/blog/p/detail/css-selector-to-xpath-query/ */ |
|
31
|
|
|
$translateList = array( |
|
32
|
|
|
// E F: Matches any F element that is a descendant of an E element |
|
33
|
1 |
|
'/(\w+)\s+(?=([^"]*"[^"]*")*[^"]*$)(\w+)/' |
|
34
|
|
|
=> '\1//\3', |
|
35
|
|
|
// E > F: Matches any F element that is a child of an element E |
|
36
|
|
|
'/(\w+)\s*>\s*(\w+)/' |
|
37
|
|
|
=> '\1/\2', |
|
38
|
|
|
// E:first-child: Matches element E when E is the first child of its parent |
|
39
|
|
|
'/(\w+|\*):first-child/' |
|
40
|
|
|
=> '*[1]/self::\1', |
|
41
|
|
|
// E:checked or E:disabled or E:selected |
|
|
|
|
|
|
42
|
|
|
'/(\w+|\*):(checked|disabled|selected)/' |
|
43
|
|
|
=> '\1 [ @\2 ]', |
|
44
|
|
|
// E + F: Matches any F element immediately preceded by an element |
|
45
|
|
|
'/(\w+)\s*\+\s*(\w+)/' |
|
46
|
|
|
=> '\1/following-sibling::*[1]/self::\2', |
|
47
|
|
|
// E ~ F: Matches any F element preceded by an element |
|
48
|
|
|
'/(\w+)\s*\~\s*(\w+)/' |
|
49
|
|
|
=> '\1/following-sibling::*/self::\2', |
|
50
|
|
|
// E[foo]: Matches any E element with the "foo" attribute set (whatever the value) |
|
51
|
|
|
'/(\w+)\[([\w\-]+)]/' |
|
52
|
|
|
=> '\1 [ @\2 ]', |
|
53
|
1 |
|
// E[foo="warning"]: Matches any E element whose "foo" attribute value is exactly equal to "warning" |
|
54
|
|
|
'/(\w+)\[([\w\-]+)\=\"(.*)\"]/' |
|
55
|
|
|
=> '\1[ contains( concat( " ", normalize-space(@\2), " " ), concat( " ", "\3", " " ) ) ]', |
|
56
|
|
|
// .warning: HTML only. The same as *[class~="warning"] |
|
57
|
|
|
'/(^|\s)\.([\w\-]+)+/' |
|
58
|
|
|
=> '*[ contains( concat( " ", normalize-space(@class), " " ), concat( " ", "\2", " " ) ) ]', |
|
59
|
|
|
// div.warning: HTML only. The same as DIV[class~="warning"] |
|
60
|
|
|
'/(\w+|\*)\.([\w\-]+)+/' |
|
61
|
|
|
=> '\1[ contains( concat( " ", normalize-space(@class), " " ), concat( " ", "\2", " " ) ) ]', |
|
62
|
|
|
// E#myid: Matches any E element with id-attribute equal to "myid" |
|
63
|
|
|
'/(\w+)+\#([\w\-]+)/' |
|
64
|
1 |
|
=> '\1[ @id = "\2" ]', |
|
65
|
|
|
// #myid: Matches any E element with id-attribute equal to "myid" |
|
66
|
|
|
'/\#([\w\-]+)/' |
|
67
|
|
|
=> '*[ @id = "\1" ]' |
|
68
|
|
|
); |
|
69
|
|
|
|
|
70
|
|
|
$cssSelectors = array_keys($translateList); |
|
71
|
|
|
$xPathQueries = array_values($translateList); |
|
72
|
|
|
do { |
|
73
|
|
|
$continue = false; |
|
|
|
|
|
|
74
|
|
|
$cssSelector = (string) preg_replace($cssSelectors, $xPathQueries, $cssSelector); |
|
75
|
|
|
foreach ( $cssSelectors as $selector ) { |
|
76
|
|
|
if ( preg_match($selector, $cssSelector) ) { |
|
77
|
|
|
$continue = true; |
|
78
|
|
|
break; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
} while ( $continue ); |
|
82
|
|
|
return '//'.$cssSelector; |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|
This check looks for method names that are not written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes
databaseConnectionSeeker.