From fa2878e530606e495787ac261c8aea805bd7d981 Mon Sep 17 00:00:00 2001 From: Ivan Lanin Date: Tue, 11 Mar 2014 03:01:12 +0700 Subject: [PATCH] Cleaning up code --- Classes/PHPWord/IOFactory.php | 4 ++-- Classes/PHPWord/Reader/Word2007.php | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Classes/PHPWord/IOFactory.php b/Classes/PHPWord/IOFactory.php index 649bcb06..7780a8ca 100755 --- a/Classes/PHPWord/IOFactory.php +++ b/Classes/PHPWord/IOFactory.php @@ -38,7 +38,7 @@ class PHPWord_IOFactory */ private static $_searchLocations = array( array('type' => 'IWriter', 'path' => 'PHPWord/Writer/{0}.php', 'class' => 'PHPWord_Writer_{0}'), - array( 'type' => 'IReader', 'path' => 'PHPWord/Reader/{0}.php', 'class' => 'PHPWord_Reader_{0}' ), + array('type' => 'IReader', 'path' => 'PHPWord/Reader/{0}.php', 'class' => 'PHPWord_Reader_{0}' ), ); /** @@ -140,7 +140,7 @@ class PHPWord_IOFactory } } - throw new PHPExcel_Reader_Exception("No $searchType found for type $readerType"); + throw new PHPWord_Exception("No $searchType found for type $readerType"); } /** diff --git a/Classes/PHPWord/Reader/Word2007.php b/Classes/PHPWord/Reader/Word2007.php index 5cc11566..c17d4074 100644 --- a/Classes/PHPWord/Reader/Word2007.php +++ b/Classes/PHPWord/Reader/Word2007.php @@ -48,8 +48,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord * Can the current PHPWord_Reader_IReader read the file? * * @param string $pFilename - * @return boolean - * @throws PHPWord_Exception + * @return bool */ public function canRead($pFilename) { @@ -117,6 +116,7 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord * Loads PHPWord from file * * @param string $pFilename + * @return PHPWord */ public function load($pFilename) { @@ -189,7 +189,8 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord $archive = "$dir/_rels/" . basename($rel["Target"]) . ".rels"; $relsDoc = simplexml_load_string($this->getFromZipArchive($zip, $archive)); $relsDoc->registerXPathNamespace("rel", "http://schemas.openxmlformats.org/package/2006//relationships"); - $xpath = self::array_item($relsDoc->xpath("rel:Relationship[@Type='" . "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']")); + $xpath = self::array_item($relsDoc->xpath("rel:Relationship[@Type='" . + "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles']")); $xmlDoc = simplexml_load_string($this->getFromZipArchive($zip, "{$rel['Target']}")); if ($xmlDoc->body) { $section = $word->createSection(); @@ -219,12 +220,18 @@ class PHPWord_Reader_Word2007 extends PHPWord_Reader_Abstract implements PHPWord break; } } - $zip->close(); return $word; } + /** + * Get array item + * + * @param array $array + * @param mixed $key + * @return mixed|null + */ private static function array_item($array, $key = 0) { return (isset($array[$key]) ? $array[$key] : null); }