id = $this->assignFromArray('id', $data); } catch (\ErrorException $ex) { throw new \ErrorException(\sprintf(self::NO_ID, \get_class($this))); } } /* Get the ID. */ public function getId() { return $this->id; } public function __toString() { return $this->id; } /** * Helper method to safely retrieve an object * from an array. */ protected function assignFromArray($key, $array, $required = false) { if ($required) { if ($key === '') { throw new \ErrorException(self::NO_KEY); } if (!isset($array[$key]) || $array[$key] === '') { throw new \ErrorException(\sprintf(self::BAD_KEY, $key, \get_class($this))); } } return $array[$key]; } }