1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236:
<?php
/**
* Null Object
*
* @author Whizark <contact@whizark.com>
* @see http://whizark.com
* @copyright Copyright (C) 2015 Whizark.
* @license MIT
*/
namespace Ecailles\NullObject;
/**
* Class NullObject
*
* @package Ecailles\NullObject
*/
class NullObject implements \ArrayAccess, \Countable, \Iterator, \JsonSerializable
{
/**
* The constructor.
*/
public function __construct()
{
// do nothing.
}
/**
* Does nothing when invoking an inaccessible method in a static context.
*
* @param string $name The name of the method being called.
* @param mixed[] $arguments The arguments of the method being called.
*
* @return NullObject Always returns a new instance of static.
*/
public static function __callStatic($name, $arguments)
{
return new static();
}
/**
* Invokes this class as a function.
*
* @return NullObject Always returns $this.
*/
public function __invoke()
{
return $this;
}
/**
* Does nothing when invoking an inaccessible method in an object context.
*
* @param string $name The name of the method being called.
* @param mixed[] $arguments The arguments of the method being called.
*
* @return NullObject Always returns $this.
*/
public function __call($name, $arguments)
{
return $this;
}
/**
* Returns the value when reading data from an inaccessible property.
*
* @param string $name The property name.
*
* @return NullObject Always returns $this.
*/
public function __get($name)
{
return $this;
}
/**
* Does nothing when writing data to an inaccessible property.
*
* @param string $name The property name to set the value to.
* @param mixed $value The value to set.
*/
public function __set($name, $value)
{
// do nothing.
}
/**
* Returns a string representation of this object.
*
* @return string Always returns the string representation of null.
*/
public function __toString()
{
return (string) null;
}
/**
* Does nothing with a clone operation.
*/
public function __clone()
{
// do nothing.
}
/**
* Returns the names of variables of this object that should be serialized.
*
* @return array Always returns an empty array.
*/
public function __sleep()
{
return [];
}
/**
* Reconstructs resources that this object may have when unserializing.
*
* @return NullObject Always returns $this.
*/
public function __wakeup()
{
return $this;
}
/**
* Returns data which should be serialized to JSON.
*
* @return \stdClass Always returns \stdClass.
*/
public function jsonSerialize()
{
return new \stdClass();
}
/**
* Returns the current element.
*
* @return NullObject Always returns $this.
*/
public function current()
{
return $this;
}
/**
* Moves forward to next element.
*/
public function next()
{
// do nothing.
}
/**
* Returns the key of the current element.
*
* @return NullObject Always returns $this.
*/
public function key()
{
return $this;
}
/**
* Checks if current position is valid.
*
* @return bool Always returns false.
*/
public function valid()
{
return false;
}
/**
* Rewinds the Iterator to the first element.
*/
public function rewind()
{
// do nothing.
}
/**
* Returns whether an offset exists.
*
* @param mixed $offset The offset to check for.
*
* @return bool Always returns false.
*/
public function offsetExists($offset)
{
return false;
}
/**
* Retrieves the value of an offset.
*
* @param mixed $offset The offset to retrieve.
*
* @return NullObject Always returns $this.
*/
public function offsetGet($offset)
{
return $this;
}
/**
* Sets a value to an offset.
*
* @param mixed $offset The offset to assign the value to.
* @param mixed $value The value to set.
*/
public function offsetSet($offset, $value)
{
// do nothing.
}
/**
* Unsets an offset.
*
* @param mixed $offset The offset to unset.
*/
public function offsetUnset($offset)
{
// do nothing.
}
/**
* Returns the number of the elements of an object.
*
* @return int Always returns 0.
*/
public function count()
{
return 0;
}
}