X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Flib%2FDrupal%2FComponent%2FGettext%2FPoStreamWriter.php;h=a441a3bf221a3a3caf6e29a78d268bf02c3de4d6;hb=1c1cb0980bfa6caf0c24cce671b6bb541dc87583;hp=f5ffc85f9718e47b29032d21e451678efa346033;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/web/core/lib/Drupal/Component/Gettext/PoStreamWriter.php b/web/core/lib/Drupal/Component/Gettext/PoStreamWriter.php index f5ffc85f9..a441a3bf2 100644 --- a/web/core/lib/Drupal/Component/Gettext/PoStreamWriter.php +++ b/web/core/lib/Drupal/Component/Gettext/PoStreamWriter.php @@ -12,21 +12,28 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface { * * @var string */ - private $_uri; + protected $uri; /** * The Gettext PO header. * * @var \Drupal\Component\Gettext\PoHeader */ - private $_header; + protected $header; /** * File handle of the current PO stream. * * @var resource */ - private $_fd; + protected $fd; + + /** + * The language code of this writer. + * + * @var string + */ + protected $langcode; /** * Gets the PO header of the current stream. @@ -35,7 +42,7 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface { * The Gettext PO header. */ public function getHeader() { - return $this->_header; + return $this->header; } /** @@ -45,7 +52,7 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface { * The Gettext PO header to set. */ public function setHeader(PoHeader $header) { - $this->_header = $header; + $this->header = $header; } /** @@ -55,7 +62,7 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface { * The language code. */ public function getLangcode() { - return $this->_langcode; + return $this->langcode; } /** @@ -65,7 +72,7 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface { * The language code. */ public function setLangcode($langcode) { - $this->_langcode = $langcode; + $this->langcode = $langcode; } /** @@ -73,7 +80,7 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface { */ public function open() { // Open in write mode. Will overwrite the stream if it already exists. - $this->_fd = fopen($this->getURI(), 'w'); + $this->fd = fopen($this->getURI(), 'w'); // Write the header at the start. $this->writeHeader(); } @@ -81,15 +88,15 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface { /** * Implements Drupal\Component\Gettext\PoStreamInterface::close(). * - * @throws Exception + * @throws \Exception * If the stream is not open. */ public function close() { - if ($this->_fd) { - fclose($this->_fd); + if ($this->fd) { + fclose($this->fd); } else { - throw new Exception('Cannot close stream that is not open.'); + throw new \Exception('Cannot close stream that is not open.'); } } @@ -100,13 +107,13 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface { * Piece of string to write to the stream. If the value is not directly a * string, casting will happen in writing. * - * @throws Exception + * @throws \Exception * If writing the data is not possible. */ private function write($data) { - $result = fputs($this->_fd, $data); - if ($result === FALSE) { - throw new Exception('Unable to write data: ' . substr($data, 0, 20)); + $result = fwrite($this->fd, $data); + if ($result === FALSE || $result != strlen($data)) { + throw new \Exception('Unable to write data: ' . substr($data, 0, 20)); } } @@ -114,7 +121,7 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface { * Write the PO header to the stream. */ private function writeHeader() { - $this->write($this->_header); + $this->write($this->header); } /** @@ -137,21 +144,21 @@ class PoStreamWriter implements PoWriterInterface, PoStreamInterface { /** * Implements Drupal\Component\Gettext\PoStreamInterface::getURI(). * - * @throws Exception + * @throws \Exception * If the URI is not set. */ public function getURI() { - if (empty($this->_uri)) { - throw new Exception('No URI set.'); + if (empty($this->uri)) { + throw new \Exception('No URI set.'); } - return $this->_uri; + return $this->uri; } /** * {@inheritdoc} */ public function setURI($uri) { - $this->_uri = $uri; + $this->uri = $uri; } }