* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org * * @template T * @extends \PSX\Record\RecordAbstract */ class Record extends RecordAbstract { /** @var array */ private $properties; /** * @param iterable $properties */ public function __construct(iterable $properties = []) { $this->properties = []; $this->merge($properties); } /** * @inheritDoc */ public function getProperties(): array { return array_filter($this->properties, function($value){ return $value !== null; }); } /** * @inheritDoc */ public function setProperties(array $properties): void { $this->properties = $properties; } /** * @inheritDoc */ public function getProperty(string $name) { return isset($this->properties[$name]) ? $this->properties[$name] : null; } /** * @inheritDoc */ public function setProperty(string $name, $value): void { $this->properties[$name] = $value; } /** * @inheritDoc */ public function removeProperty(string $name): void { if (isset($this->properties[$name])) { unset($this->properties[$name]); } } /** * @inheritDoc */ public function hasProperty(string $name): bool { return array_key_exists($name, $this->properties); } /** * @inheritDoc */ public function isEmpty(): bool { return count($this->properties) === 0; } /** * @inheritDoc */ public function merge(iterable $record): void { foreach ($record as $key => $value) { $this->setProperty($key, $value); } } /** * @inheritDoc */ public function filter(\Closure $filter): void { $this->properties = array_filter($this->properties, $filter); } /** * @inheritDoc */ public function map(\Closure $filter): void { $this->properties = array_map($filter, $this->properties); } /** * @param iterable $data * @return \PSX\Record\RecordInterface */ public static function fromArray(iterable $data): RecordInterface { return new static($data); } /** * @param \stdClass $data * @return \PSX\Record\RecordInterface */ public static function fromStdClass(\stdClass $data): RecordInterface { return new static(get_object_vars($data)); } /** * @param mixed $data * @return \PSX\Record\RecordInterface */ public static function from($data): RecordInterface { if (is_iterable($data)) { return self::fromArray($data); } elseif ($data instanceof \stdClass) { return self::fromStdClass($data); } else { throw new \InvalidArgumentException('Can create record only from iterable or stdClass'); } } /** * @param array $array * @return \PSX\Record\RecordInterface */ public static function __set_state($array) { return new static($array['properties'] ?? []); } } __halt_compiler();----SIGNATURE:----gWH2KBUUJuT0k5VO3hnHcWvlBcCe8iilGz/SKi9PP0pfor/GAweESYLeW94ltJxB35KHMvrY/dWmO0vBuZf0neFQI72UmBTdvjNBzpDa8rgYXhNFrC03i3VyLsF06ayMAWyd6ePqyYNvKN3IoBPhW1vtO9i28vD964FGa7nidMRRtt33jFfzyZrJ28wkaH3j7Y9L9b9YK9gJIVXzTKl02M1FnnGdTEyapRI0lLuWKseC0jKiyWTQ8WflpyHkbFgs9gLrl0NpkNDeNEZP+FWgjtFTuwLageQUztEUY24gPtc/bmj5Hbb2pDJhgpJsxseZK2IgQl5xIJBoBxyuwXl5sHTmDyfT/tMQAOlphP106c08dPKhFGx1YjxW/ZKwQdayC8iIVtkQORqEfJAMoSpn0w5URgudhPmr8DOlVQJ8AXAiDVBe29qv66Arl729SfxpLAMhmkw+eKGtZhiTcXPx2IPJtJxhBHKDPgOay3Nnkxm5GwAkEU+TIDtxj26qMPAi/NAV7pKVhemS217gDO/fUhMwtG4G1kplakAIOypA9+hywJPKUhULHgfiooAdqpmN+fPgq2k5HDvJHebk2lH4FOtKosZf21N8MPMcs4wNDIcJSu1UlEcllKTAtESY6CAIEuEpQp6MLXQxGRllMjzBmcfLLZCuwmMri7mLsmuU2X0=----ATTACHMENT:----OTA0MDQ5NTY2MjgzODY0NCA1NjE2MTU0MzExNjc3MjAyIDY0OTU4NjM0MDE0NzE4NDM=