* @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:----HKYvgHss7+RCG0orv1zD2nZ4jjr9skv1QmnxBwrUV6lT0ApR3fyTbu65HDslH2UQBG56VfB9ICcUntsu+TPndlcHmftA/UnHNn28KcdVuk5WHZvVePI89iJmes2KlqHOjdJygwvQJLMhD0nucmkKJeu5ZLRxjlv3noHDrvO4c7QcVgIS6qduNX5zzotH1OqYOFrUmGM9pg84x/o9BhHHWnurMW36UBpGRO2zsOvk+KQv+aqXvJToQeQROgkAc2gIF2JZj9nHylzaKrvPcyvuISeSVlP+nZO6zlH2xoFDIHldYlb6JdcRH9lqknQo9A7+/xAiMVOCqFJzuG6vXdw9c1V1GGjiPZlS6pstJa5Ifx+Ic1SdQb1oNlfzfWICJDMhH45cpqUvFdTEN4KIz6dxYU7Bs0cNqh0AjjV3z+drQ6MQe0rwHdv/CVYkOax3YvjWIcfSWZ8p1rWYVGdwT2jOed0j+YrDQpG434TsC4Solg1f0qvSW3NsHpxs0vbb3GjKyryVyptyuFz7Saktbxi0W3qmuYL1nqXieAGEjJNUJOhRGgU6HIQOe9mnWWEOZ6G5rxkupNdliy/1Bdv827V7/RVCjZ9OmGj/tmfi2SRHgqkOpaCQZWED5Fdhb/yTtVPFyJPhzDY4mnnayQUQ0afH2aqU6XN4dFQqAaLWOzxsZWo=----ATTACHMENT:----NzgxNjY4OTY0Njk1MzE1NSA2MTYwNzA5MjY0MTM0MzUgNjU3NDQ3NDE1MDIzMjgwOA==