mirror of
https://github.com/processwire/processwire.git
synced 2025-08-17 12:10:45 +02:00
Improve __debugInfo() in Selector and Selectors classes
This commit is contained in:
@@ -172,7 +172,7 @@ abstract class Selector extends WireData {
|
|||||||
if($forceString === 1) {
|
if($forceString === 1) {
|
||||||
$value = reset($value);
|
$value = reset($value);
|
||||||
} else {
|
} else {
|
||||||
$value = implode('|', $value);
|
$value = $this->wire('sanitizer')->selectorValue($value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $value;
|
return $value;
|
||||||
@@ -257,7 +257,7 @@ abstract class Selector extends WireData {
|
|||||||
public function getValue($type = '') {
|
public function getValue($type = '') {
|
||||||
$value = $this->value;
|
$value = $this->value;
|
||||||
if($type == 'string') {
|
if($type == 'string') {
|
||||||
if(is_array($value)) $value = implode('|', $value);
|
if(is_array($value)) $value = $this->wire('sanitizer')->selectorValue($value);
|
||||||
} else if($type == 'array') {
|
} else if($type == 'array') {
|
||||||
if(!is_array($value)) $value = array($value);
|
if(!is_array($value)) $value = array($value);
|
||||||
} else if($this->quote == '[') {
|
} else if($this->quote == '[') {
|
||||||
@@ -410,21 +410,51 @@ abstract class Selector extends WireData {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __toString() {
|
public function __toString() {
|
||||||
|
|
||||||
$openingQuote = $this->quote;
|
$openingQuote = $this->quote;
|
||||||
$closingQuote = $openingQuote;
|
$closingQuote = $openingQuote;
|
||||||
|
|
||||||
if($openingQuote) {
|
if($openingQuote) {
|
||||||
if($openingQuote == '[') $closingQuote = ']';
|
if($openingQuote == '[') $closingQuote = ']';
|
||||||
else if($openingQuote == '{') $closingQuote = '}';
|
else 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_null($this->group) ? '' : $this->group . '@') .
|
||||||
(is_array($this->field) ? implode('|', $this->field) : $this->field) .
|
(is_array($this->field) ? implode('|', $this->field) : $this->field) .
|
||||||
$this->operator() .
|
$this->operator() . $value;
|
||||||
(is_array($this->value) ? implode("|", $this->value) : $openingQuote . $this->value . $closingQuote);
|
|
||||||
return $str;
|
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
|
* Add all individual selector types to the runtime Selectors
|
||||||
*
|
*
|
||||||
|
@@ -1290,6 +1290,17 @@ class Selectors extends WireArray {
|
|||||||
return $all ? $matches : $selector;
|
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
|
* See if the given $selector specifies the given $field somewhere
|
||||||
*
|
*
|
||||||
|
@@ -2431,30 +2431,47 @@ class WireArray extends Wire implements \IteratorAggregate, \ArrayAccess, \Count
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function __debugInfo() {
|
public function __debugInfo() {
|
||||||
|
|
||||||
$info = parent::__debugInfo();
|
$info = parent::__debugInfo();
|
||||||
$info['count'] = $this->count();
|
$info['count'] = $this->count();
|
||||||
|
|
||||||
if(count($this->data)) {
|
if(count($this->data)) {
|
||||||
$info['items'] = array();
|
$info['items'] = array();
|
||||||
foreach($this->data as $key => $value) {
|
foreach($this->data as $key => $value) {
|
||||||
if(is_object($value)) {
|
$info['items'][$key] = $this->debugInfoItem($value);
|
||||||
if($value instanceof Page) {
|
}
|
||||||
$value = '/' . ltrim($value->path(), '/');
|
}
|
||||||
} else if($value instanceof WireData) {
|
|
||||||
$_value = $value;
|
if(count($this->extraData)) $info['extraData'] = $this->extraData;
|
||||||
$value = $value->get('name');
|
if(count($this->itemsAdded)) $info['itemsAdded'] = $this->itemsAdded;
|
||||||
if(!$value) $value = $_value->get('id');
|
if(count($this->itemsRemoved)) $info['itemsRemoved'] = $this->itemsRemoved;
|
||||||
if(!$value) $value = $_value->className();
|
|
||||||
|
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 {
|
} else {
|
||||||
// keep $value as it is
|
// keep $value as it is
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$info['items'][$key] = $value;
|
return $item;
|
||||||
}
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user