Skip to content

Commit

Permalink
Added PhpCss\As\Vistor\Xpath::OPTION_USE_CONTEXT_SELF, limit the cont…
Browse files Browse the repository at this point in the history
…ext to the current node
  • Loading branch information
ThomasWeinert committed Apr 2, 2018
1 parent f8bc138 commit ae8b6da
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 8 deletions.
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
language: php

sudo: required
dist: trusty
group: edge

php:
- 5.6
- 7.0
- 7.0snapshot
- 7.1
- 7.1snapshot
- 7.2
- 7.2snapshot
- nightly

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

install: composer install

script: php phpunit.phar --configuration phpunit.xml.dist
script: php phpunit.phar tests

notifications:
webhooks:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![Latest Unstable Version](https://poser.pugx.org/carica/phpcss/v/unstable.svg)](https://packagist.org/packages/carica/phpcss)

* License: The MIT License
* Copyright: 2010-2014 PhpCss Team
* Copyright: 2010-2018 PhpCss Team
* Author: [Thomas Weinert](http://thomas.weinert.info) <[email protected]>

Thanks to Benjamin Eberlei, Bastian Feder and Jakob Westhoff for ideas and concepts.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
],
"config": {
"platform": {
"php": "5.6"
"php": "7.0"
}
},
"require" : {
"PHP" : ">=5.5"
"PHP" : ">=7.0"
},
"autoload": {
"psr-4": {"PhpCss\\": "src/PhpCss"},
Expand Down
22 changes: 22 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions phive.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpunit" version="6" installed="6.5.7" location="./tools/phpunit"/>
</phive>
7 changes: 7 additions & 0 deletions src/PhpCss/Ast/Visitor/Xpath.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ class Xpath extends Overload {
* start expressions in descendant-or-self context
*/
const OPTION_USE_CONTEXT_SELF = 32;
/**
* limit expressions to self context
*/
const OPTION_USE_CONTEXT_SELF_LIMIT = 64;

/**
* lowercase the element names (not the namespace prefixes)
*/
Expand Down Expand Up @@ -288,6 +293,8 @@ public function visitEnterSelectorSequence(Ast\Selector\Sequence $sequence) {
}
if ($this->hasOption(self::OPTION_USE_CONTEXT_DOCUMENT)) {
$this->add('//');
} elseif ($this->hasOption(self::OPTION_USE_CONTEXT_SELF_LIMIT)) {
$this->add('self::');
} elseif ($this->hasOption(self::OPTION_USE_CONTEXT_SELF)) {
$this->add('descendant-or-self::');
} else {
Expand Down
11 changes: 11 additions & 0 deletions tests/PhpCss/Ast/Visitor/XpathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,17 @@ public static function provideExamples() {
),
Ast\Visitor\Xpath::OPTION_USE_CONTEXT_SELF
),
'element, self context limit' => array(
'self::*[local-name() = "element"]',
new Ast\Selector\Group(
array(
new Ast\Selector\Sequence(
array(new Ast\Selector\Simple\Type('element'))
)
)
),
Ast\Visitor\Xpath::OPTION_USE_CONTEXT_SELF_LIMIT
),
'element, #id' => array(
'.//*[local-name() = "element"]|.//*[@id = "id"]',
new Ast\Selector\Group(
Expand Down

0 comments on commit ae8b6da

Please sign in to comment.