public function close() { if (!$this->closed) { $this->writer->endElement($this); $this->closed = true; } else { throw new \Exception("Element {$this->name} is already closed"); } }