name = trim(str_replace("\n", ' ', $name)); if (strlen($this->name) < 1) { throw new Exception(sprintf('Ini parser error: empty section identifier')); } } /** * @param Directive $directive */ public function addDirective(Directive $directive) { $this->directives[$directive->getKey()] = $directive; } /** * @param string $key */ public function removeDirective($key) { unset ($this->directives[$key]); } /** * @param string $key * * @return bool */ public function hasDirective($key) { return isset($this->directives[$key]); } /** * @param $key string * * @return Directive */ public function getDirective($key) { return $this->directives[$key]; } /** * @return string */ public function getName() { return $this->name; } /** * @return string */ public function render() { $dirs = ''; $i = 0; foreach ($this->directives as $directive) { $dirs .= (($i++ > 0 && ! empty($directive->commentsPre)) ? PHP_EOL : '') . $directive->render() . PHP_EOL; } $cms = ''; if (! empty($this->commentsPre)) { foreach ($this->commentsPre as $comment) { $comments[] = $comment->render(); } $cms = implode(PHP_EOL, $comments) . PHP_EOL; } $post = ''; if (isset($this->commentPost)) { $post = ' ' . $this->commentPost->render(); } return $cms . sprintf('[%s]', $this->name) . $post . PHP_EOL . $dirs; } }