diff --git a/wire/core/Selector.php b/wire/core/Selector.php index a3aede85..4eee4755 100644 --- a/wire/core/Selector.php +++ b/wire/core/Selector.php @@ -172,7 +172,7 @@ abstract class Selector extends WireData { if($forceString === 1) { $value = reset($value); } else { - $value = implode('|', $value); + $value = $this->wire('sanitizer')->selectorValue($value); } } return $value; @@ -257,7 +257,7 @@ abstract class Selector extends WireData { public function getValue($type = '') { $value = $this->value; if($type == 'string') { - if(is_array($value)) $value = implode('|', $value); + if(is_array($value)) $value = $this->wire('sanitizer')->selectorValue($value); } else if($type == 'array') { if(!is_array($value)) $value = array($value); } else if($this->quote == '[') { @@ -410,21 +410,51 @@ abstract class Selector extends WireData { * */ public function __toString() { + $openingQuote = $this->quote; $closingQuote = $openingQuote; + if($openingQuote) { if($openingQuote == '[') $closingQuote = ']'; else if($openingQuote == '{') $closingQuote = '}'; else if($openingQuote == '(') $closingQuote = ')'; } - $str = ($this->not ? '!' : '') . + + $value = $this->value(); + if($openingQuote) $value = trim($value, $openingQuote . $closingQuote); + $value = $openingQuote . $value . $closingQuote; + + $str = + ($this->not ? '!' : '') . (is_null($this->group) ? '' : $this->group . '@') . (is_array($this->field) ? implode('|', $this->field) : $this->field) . - $this->operator() . - (is_array($this->value) ? implode("|", $this->value) : $openingQuote . $this->value . $closingQuote); + $this->operator() . $value; + return $str; } + /** + * Debug info + * + * #pw-internal + * + * @return array + * + */ + public function __debugInfo() { + $info = array( + 'field' => $this->field, + 'operator' => $this->operator, + 'value' => $this->value, + ); + if($this->not) $info['not'] = true; + if($this->forceMatch) $info['forceMatch'] = true; + if($this->group) $info['group'] = $this->group; + if($this->quote) $info['quote'] = $this->quote; + $info['string'] = $this->__toString(); + return $info; + } + /** * Add all individual selector types to the runtime Selectors * diff --git a/wire/core/Selectors.php b/wire/core/Selectors.php index b71d7c49..adcd21f1 100644 --- a/wire/core/Selectors.php +++ b/wire/core/Selectors.php @@ -1289,6 +1289,17 @@ class Selectors extends WireArray { return $all ? $matches : $selector; } + + public function __debugInfo() { + $info = parent::__debugInfo(); + $info['string'] = $this->__toString(); + return $info; + } + + public function debugInfoItem($item) { + if($item instanceof Selector) return $item->__debugInfo(); + return parent::debugInfoItem($item); + } /** * See if the given $selector specifies the given $field somewhere diff --git a/wire/core/WireArray.php b/wire/core/WireArray.php index 515e8ef1..f4be13d2 100644 --- a/wire/core/WireArray.php +++ b/wire/core/WireArray.php @@ -2431,32 +2431,49 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count * */ public function __debugInfo() { + $info = parent::__debugInfo(); $info['count'] = $this->count(); + if(count($this->data)) { $info['items'] = array(); foreach($this->data as $key => $value) { - if(is_object($value)) { - if($value instanceof Page) { - $value = '/' . ltrim($value->path(), '/'); - } else if($value instanceof WireData) { - $_value = $value; - $value = $value->get('name'); - if(!$value) $value = $_value->get('id'); - if(!$value) $value = $_value->className(); - } else { - // keep $value as it is - } - } - $info['items'][$key] = $value; + $info['items'][$key] = $this->debugInfoItem($value); } } + if(count($this->extraData)) $info['extraData'] = $this->extraData; if(count($this->itemsAdded)) $info['itemsAdded'] = $this->itemsAdded; if(count($this->itemsRemoved)) $info['itemsRemoved'] = $this->itemsRemoved; + return $info; } + /** + * Return debug info for one item from this WireArray + * + * #pw-internal + * + * @param mixed $item + * @return mixed|null|string + * + */ + public function debugInfoItem($item) { + if(is_object($item)) { + if($item instanceof Page) { + $item = '/' . ltrim($item->path(), '/'); + } else if($item instanceof WireData) { + $_item = $item; + $item = $item->get('name'); + if(!$item) $item = $_item->get('id'); + if(!$item) $item = $_item->className(); + } else { + // keep $value as it is + } + } + return $item; + } + /** * Static method caller, primarily for support of WireArray::new() method *