Skip to content

Commit ae8b6da

Browse files
committed
Added PhpCss\As\Vistor\Xpath::OPTION_USE_CONTEXT_SELF, limit the context to the current node
1 parent f8bc138 commit ae8b6da

File tree

7 files changed

+55
-8
lines changed

7 files changed

+55
-8
lines changed

.travis.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
language: php
22

3+
sudo: required
4+
dist: trusty
5+
group: edge
6+
37
php:
4-
- 5.6
58
- 7.0
6-
- 7.0snapshot
79
- 7.1
810
- 7.1snapshot
11+
- 7.2
12+
- 7.2snapshot
913
- nightly
1014

1115
matrix:
@@ -15,12 +19,11 @@ matrix:
1519
before_install:
1620
- composer self-update
1721
- composer clear-cache
18-
- if [ $(phpenv version-name) = "5.6" ]; then wget https://phar.phpunit.de/phpunit-5.7.phar -O phpunit.phar; fi
19-
- if [ $(phpenv version-name) != "5.6" ]; then wget https://phar.phpunit.de/phpunit.phar; fi
22+
- wget -O phpunit.phar https://phar.phpunit.de/phpunit-6.phar
2023

2124
install: composer install
2225

23-
script: php phpunit.phar --configuration phpunit.xml.dist
26+
script: php phpunit.phar tests
2427

2528
notifications:
2629
webhooks:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[![Latest Unstable Version](https://poser.pugx.org/carica/phpcss/v/unstable.svg)](https://packagist.org/packages/carica/phpcss)
88

99
* License: The MIT License
10-
* Copyright: 2010-2014 PhpCss Team
10+
* Copyright: 2010-2018 PhpCss Team
1111
* Author: [Thomas Weinert](http://thomas.weinert.info) <thomas@weinert.info>
1212

1313
Thanks to Benjamin Eberlei, Bastian Feder and Jakob Westhoff for ideas and concepts.

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
],
1212
"config": {
1313
"platform": {
14-
"php": "5.6"
14+
"php": "7.0"
1515
}
1616
},
1717
"require" : {
18-
"PHP" : ">=5.5"
18+
"PHP" : ">=7.0"
1919
},
2020
"autoload": {
2121
"psr-4": {"PhpCss\\": "src/PhpCss"},

composer.lock

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phive.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phive xmlns="https://phar.io/phive">
3+
<phar name="phpunit" version="6" installed="6.5.7" location="./tools/phpunit"/>
4+
</phive>

src/PhpCss/Ast/Visitor/Xpath.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ class Xpath extends Overload {
4343
* start expressions in descendant-or-self context
4444
*/
4545
const OPTION_USE_CONTEXT_SELF = 32;
46+
/**
47+
* limit expressions to self context
48+
*/
49+
const OPTION_USE_CONTEXT_SELF_LIMIT = 64;
50+
4651
/**
4752
* lowercase the element names (not the namespace prefixes)
4853
*/
@@ -288,6 +293,8 @@ public function visitEnterSelectorSequence(Ast\Selector\Sequence $sequence) {
288293
}
289294
if ($this->hasOption(self::OPTION_USE_CONTEXT_DOCUMENT)) {
290295
$this->add('//');
296+
} elseif ($this->hasOption(self::OPTION_USE_CONTEXT_SELF_LIMIT)) {
297+
$this->add('self::');
291298
} elseif ($this->hasOption(self::OPTION_USE_CONTEXT_SELF)) {
292299
$this->add('descendant-or-self::');
293300
} else {

tests/PhpCss/Ast/Visitor/XpathTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,17 @@ public static function provideExamples() {
133133
),
134134
Ast\Visitor\Xpath::OPTION_USE_CONTEXT_SELF
135135
),
136+
'element, self context limit' => array(
137+
'self::*[local-name() = "element"]',
138+
new Ast\Selector\Group(
139+
array(
140+
new Ast\Selector\Sequence(
141+
array(new Ast\Selector\Simple\Type('element'))
142+
)
143+
)
144+
),
145+
Ast\Visitor\Xpath::OPTION_USE_CONTEXT_SELF_LIMIT
146+
),
136147
'element, #id' => array(
137148
'.//*[local-name() = "element"]|.//*[@id = "id"]',
138149
new Ast\Selector\Group(

0 commit comments

Comments
 (0)