From 9a9c04512e5dcb77c7fe5d850e3f2a0250cc160e Mon Sep 17 00:00:00 2001 From: emkael Date: Wed, 18 Jan 2017 20:07:16 +0100 Subject: * Motor Sport Magazine feed provider --- lib/querypath/src/QueryPath/CSS/SimpleSelector.php | 138 +++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 lib/querypath/src/QueryPath/CSS/SimpleSelector.php (limited to 'lib/querypath/src/QueryPath/CSS/SimpleSelector.php') diff --git a/lib/querypath/src/QueryPath/CSS/SimpleSelector.php b/lib/querypath/src/QueryPath/CSS/SimpleSelector.php new file mode 100644 index 0000000..3fcc796 --- /dev/null +++ b/lib/querypath/src/QueryPath/CSS/SimpleSelector.php @@ -0,0 +1,138 @@ +'; + case self::sibling: + return '~'; + case self::anotherSelector: + return ', '; + case self::anyDescendant: + return ' '; + } + } + + public function __construct() { + } + + public function notEmpty() { + return !empty($element) + && !empty($id) + && !empty($classes) + && !empty($combinator) + && !empty($attributes) + && !empty($pseudoClasses) + && !empty($pseudoElements) + ; + } + + public function __tostring() { + $buffer = array(); + try { + + if (!empty($this->ns)) { + $buffer[] = $this->ns; $buffer[] = '|'; + } + if (!empty($this->element)) $buffer[] = $this->element; + if (!empty($this->id)) $buffer[] = '#' . $this->id; + if (!empty($this->attributes)) { + foreach ($this->attributes as $attr) { + $buffer[] = '['; + if(!empty($attr['ns'])) $buffer[] = $attr['ns'] . '|'; + $buffer[] = $attr['name']; + if (!empty($attr['value'])) { + $buffer[] = self::attributeOperator($attr['op']); + $buffer[] = $attr['value']; + } + $buffer[] = ']'; + } + } + if (!empty($this->pseudoClasses)) { + foreach ($this->pseudoClasses as $ps) { + $buffer[] = ':' . $ps['name']; + if (isset($ps['value'])) { + $buffer[] = '(' . $ps['value'] . ')'; + } + } + } + foreach ($this->pseudoElements as $pe) { + $buffer[] = '::' . $pe; + } + + if (!empty($this->combinator)) { + $buffer[] = self::combinatorOperator($this->combinator); + } + + } + catch (\Exception $e) { + return $e->getMessage(); + } + + return implode('', $buffer); + } + +} -- cgit v1.2.3