. */ namespace SP\Mvc\View\Components; use JsonSerializable; /** * Class SelectItem * * @package SP\Mvc\View\Components */ final class SelectItem implements JsonSerializable { /** * @var int */ protected $id; /** * @var string */ protected $name; /** * @var mixed */ protected $item; /** * @var bool */ protected $selected = false; /** * @var bool */ protected $skip = false; /** * SelectItem constructor. * * @param int $id * @param string $name * @param null $item */ public function __construct($id, $name, $item = null) { $this->id = is_numeric($id) ? (int)$id : $id; $this->name = (string)$name; $this->item = $item; } /** * @return int */ public function getId() { return $this->id; } /** * @return string */ public function getName() { return $this->name; } /** * @return bool */ public function isSelected() { return $this->selected; } /** * @param bool $selected */ public function setSelected($selected) { $this->selected = (bool)$selected; } /** * @param $property * * @return mixed */ public function getItemProperty($property) { return null !== $this->item && isset($this->item->{$property}) ? $this->item->{$property} : null; } /** * @return bool */ public function isSkip() { return $this->skip; } /** * @param bool $skip */ public function setSkip($skip) { $this->skip = (bool)$skip; } /** * @inheritDoc */ public function jsonSerialize() { return ['id' => (int)$this->id, 'name' => $this->name]; } }