mirror of
https://github.com/processwire/processwire.git
synced 2025-08-10 16:54:44 +02:00
Update wireEmpty() function so that it also returns false when giving a NullPage or NullField object. Add WireNull interface for future Null objects.
This commit is contained in:
@@ -1087,6 +1087,7 @@ function wireCount($value) {
|
|||||||
*
|
*
|
||||||
* - It returns true for Countable objects that have 0 items.
|
* - It returns true for Countable objects that have 0 items.
|
||||||
* - It considers whitespace-only strings to be empty.
|
* - It considers whitespace-only strings to be empty.
|
||||||
|
* - It considers WireNull objects (like NullPage or any others) to be empty (3.0.149+).
|
||||||
* - You cannot pass it an undefined variable without triggering a PHP warning.
|
* - You cannot pass it an undefined variable without triggering a PHP warning.
|
||||||
*
|
*
|
||||||
* ~~~~~
|
* ~~~~~
|
||||||
@@ -1117,6 +1118,7 @@ function wireEmpty($value) {
|
|||||||
if(empty($value)) return true;
|
if(empty($value)) return true;
|
||||||
if(is_object($value)) {
|
if(is_object($value)) {
|
||||||
if($value instanceof \Countable && !count($value)) return true;
|
if($value instanceof \Countable && !count($value)) return true;
|
||||||
|
if($value instanceof WireNull) return true; // 3.0.149+
|
||||||
} else if(is_string($value)) {
|
} else if(is_string($value)) {
|
||||||
if(!strlen(trim($value))) return true;
|
if(!strlen(trim($value))) return true;
|
||||||
}
|
}
|
||||||
|
@@ -327,6 +327,12 @@ interface WirePageEditor {
|
|||||||
public function getPage();
|
public function getPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface shared by all ProcessWire Null objects
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
interface WireNull { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface that indicates the object supports its items being paginated
|
* Interface that indicates the object supports its items being paginated
|
||||||
*
|
*
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class NullField extends Field {
|
class NullField extends Field implements WireNull {
|
||||||
public function get($key) {
|
public function get($key) {
|
||||||
if($key == 'id') return 0;
|
if($key == 'id') return 0;
|
||||||
if($key == 'name') return '';
|
if($key == 'name') return '';
|
||||||
|
@@ -32,7 +32,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class NullPage extends Page {
|
class NullPage extends Page implements WireNull {
|
||||||
/**
|
/**
|
||||||
* #pw-internal
|
* #pw-internal
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user