← All changes
|
vendor/phpoffice/phpexcel/Classes/PHPExcel/IOFactory.php
+237
-238
3.1.1
→
3.0.10
View file →
| @@ -1,19 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | - | |
| 3 | -/** PHPExcel root directory */ | |
| 4 | -if (!defined('PHPEXCEL_ROOT')) { | |
| 5 | - /** | |
| 6 | - * @ignore | |
| 7 | - */ | |
| 8 | - define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../'); | |
| 9 | - require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); | |
| 10 | -} | |
| 11 | - | |
| 12 | 2 | /** |
| 13 | - * PHPExcel_IOFactory | |
| 3 | + * PHPExcel | |
| 14 | 4 | * |
| 15 | - * Copyright (c) 2006 - 2015 PHPExcel | |
| 5 | + * Copyright (c) 2006 - 2014 PHPExcel | |
| 16 | 6 | * |
| 17 | 7 | * This library is free software; you can redistribute it and/or |
| 18 | 8 | * modify it under the terms of the GNU Lesser General Public |
| 19 | 9 | * License as published by the Free Software Foundation; either |
| @@ -29,261 +19,270 @@ | ||
| 29 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 30 | 20 | * |
| 31 | 21 | * @category PHPExcel |
| 32 | 22 | * @package PHPExcel |
| 33 | - * @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 34 | - * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL | |
| 23 | + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 24 | + * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL | |
| 35 | 25 | * @version ##VERSION##, ##DATE## |
| 36 | 26 | */ |
| 27 | + | |
| 28 | + | |
| 29 | +/** PHPExcel root directory */ | |
| 30 | +if (!defined('PHPEXCEL_ROOT')) { | |
| 31 | + /** | |
| 32 | + * @ignore | |
| 33 | + */ | |
| 34 | + define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../'); | |
| 35 | + require(PHPEXCEL_ROOT . 'PHPExcel/Autoloader.php'); | |
| 36 | +} | |
| 37 | + | |
| 38 | +/** | |
| 39 | + * PHPExcel_IOFactory | |
| 40 | + * | |
| 41 | + * @category PHPExcel | |
| 42 | + * @package PHPExcel | |
| 43 | + * @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel) | |
| 44 | + */ | |
| 37 | 45 | class PHPExcel_IOFactory |
| 38 | 46 | { |
| 39 | - /** | |
| 40 | - * Search locations | |
| 41 | - * | |
| 42 | - * @var array | |
| 43 | - * @access private | |
| 44 | - * @static | |
| 45 | - */ | |
| 46 | - private static $searchLocations = array( | |
| 47 | - array( 'type' => 'IWriter', 'path' => 'PHPExcel/Writer/{0}.php', 'class' => 'PHPExcel_Writer_{0}' ), | |
| 48 | - array( 'type' => 'IReader', 'path' => 'PHPExcel/Reader/{0}.php', 'class' => 'PHPExcel_Reader_{0}' ) | |
| 49 | - ); | |
| 47 | + /** | |
| 48 | + * Search locations | |
| 49 | + * | |
| 50 | + * @var array | |
| 51 | + * @access private | |
| 52 | + * @static | |
| 53 | + */ | |
| 54 | + private static $_searchLocations = array( | |
| 55 | + array( 'type' => 'IWriter', 'path' => 'PHPExcel/Writer/{0}.php', 'class' => 'PHPExcel_Writer_{0}' ), | |
| 56 | + array( 'type' => 'IReader', 'path' => 'PHPExcel/Reader/{0}.php', 'class' => 'PHPExcel_Reader_{0}' ) | |
| 57 | + ); | |
| 50 | 58 | |
| 51 | - /** | |
| 52 | - * Autoresolve classes | |
| 53 | - * | |
| 54 | - * @var array | |
| 55 | - * @access private | |
| 56 | - * @static | |
| 57 | - */ | |
| 58 | - private static $autoResolveClasses = array( | |
| 59 | - 'Excel2007', | |
| 60 | - 'Excel5', | |
| 61 | - 'Excel2003XML', | |
| 62 | - 'OOCalc', | |
| 63 | - 'SYLK', | |
| 64 | - 'Gnumeric', | |
| 65 | - 'HTML', | |
| 66 | - 'CSV', | |
| 67 | - ); | |
| 59 | + /** | |
| 60 | + * Autoresolve classes | |
| 61 | + * | |
| 62 | + * @var array | |
| 63 | + * @access private | |
| 64 | + * @static | |
| 65 | + */ | |
| 66 | + private static $_autoResolveClasses = array( | |
| 67 | + 'Excel2007', | |
| 68 | + 'Excel5', | |
| 69 | + 'Excel2003XML', | |
| 70 | + 'OOCalc', | |
| 71 | + 'SYLK', | |
| 72 | + 'Gnumeric', | |
| 73 | + 'HTML', | |
| 74 | + 'CSV', | |
| 75 | + ); | |
| 68 | 76 | |
| 69 | 77 | /** |
| 70 | - * Private constructor for PHPExcel_IOFactory | |
| 78 | + * Private constructor for PHPExcel_IOFactory | |
| 71 | 79 | */ |
| 72 | - private function __construct() | |
| 73 | - { | |
| 74 | - } | |
| 80 | + private function __construct() { } | |
| 75 | 81 | |
| 76 | 82 | /** |
| 77 | 83 | * Get search locations |
| 78 | 84 | * |
| 79 | - * @static | |
| 80 | - * @access public | |
| 81 | - * @return array | |
| 85 | + * @static | |
| 86 | + * @access public | |
| 87 | + * @return array | |
| 82 | 88 | */ |
| 83 | - public static function getSearchLocations() | |
| 84 | - { | |
| 85 | - return self::$searchLocations; | |
| 86 | - } | |
| 89 | + public static function getSearchLocations() { | |
| 90 | + return self::$_searchLocations; | |
| 91 | + } // function getSearchLocations() | |
| 87 | 92 | |
| 88 | - /** | |
| 89 | - * Set search locations | |
| 90 | - * | |
| 91 | - * @static | |
| 92 | - * @access public | |
| 93 | - * @param array $value | |
| 94 | - * @throws PHPExcel_Reader_Exception | |
| 95 | - */ | |
| 96 | - public static function setSearchLocations($value) | |
| 97 | - { | |
| 98 | - if (is_array($value)) { | |
| 99 | - self::$searchLocations = $value; | |
| 100 | - } else { | |
| 101 | - throw new PHPExcel_Reader_Exception('Invalid parameter passed.'); | |
| 102 | - } | |
| 103 | - } | |
| 93 | + /** | |
| 94 | + * Set search locations | |
| 95 | + * | |
| 96 | + * @static | |
| 97 | + * @access public | |
| 98 | + * @param array $value | |
| 99 | + * @throws PHPExcel_Reader_Exception | |
| 100 | + */ | |
| 101 | + public static function setSearchLocations($value) { | |
| 102 | + if (is_array($value)) { | |
| 103 | + self::$_searchLocations = $value; | |
| 104 | + } else { | |
| 105 | + throw new PHPExcel_Reader_Exception('Invalid parameter passed.'); | |
| 106 | + } | |
| 107 | + } // function setSearchLocations() | |
| 104 | 108 | |
| 105 | - /** | |
| 106 | - * Add search location | |
| 107 | - * | |
| 108 | - * @static | |
| 109 | - * @access public | |
| 110 | - * @param string $type Example: IWriter | |
| 111 | - * @param string $location Example: PHPExcel/Writer/{0}.php | |
| 112 | - * @param string $classname Example: PHPExcel_Writer_{0} | |
| 113 | - */ | |
| 114 | - public static function addSearchLocation($type = '', $location = '', $classname = '') | |
| 115 | - { | |
| 116 | - self::$searchLocations[] = array( 'type' => $type, 'path' => $location, 'class' => $classname ); | |
| 117 | - } | |
| 109 | + /** | |
| 110 | + * Add search location | |
| 111 | + * | |
| 112 | + * @static | |
| 113 | + * @access public | |
| 114 | + * @param string $type Example: IWriter | |
| 115 | + * @param string $location Example: PHPExcel/Writer/{0}.php | |
| 116 | + * @param string $classname Example: PHPExcel_Writer_{0} | |
| 117 | + */ | |
| 118 | + public static function addSearchLocation($type = '', $location = '', $classname = '') { | |
| 119 | + self::$_searchLocations[] = array( 'type' => $type, 'path' => $location, 'class' => $classname ); | |
| 120 | + } // function addSearchLocation() | |
| 118 | 121 | |
| 119 | - /** | |
| 120 | - * Create PHPExcel_Writer_IWriter | |
| 121 | - * | |
| 122 | - * @static | |
| 123 | - * @access public | |
| 124 | - * @param PHPExcel $phpExcel | |
| 125 | - * @param string $writerType Example: Excel2007 | |
| 126 | - * @return PHPExcel_Writer_IWriter | |
| 127 | - * @throws PHPExcel_Reader_Exception | |
| 128 | - */ | |
| 129 | - public static function createWriter(PHPExcel $phpExcel, $writerType = '') | |
| 130 | - { | |
| 131 | - // Search type | |
| 132 | - $searchType = 'IWriter'; | |
| 122 | + /** | |
| 123 | + * Create PHPExcel_Writer_IWriter | |
| 124 | + * | |
| 125 | + * @static | |
| 126 | + * @access public | |
| 127 | + * @param PHPExcel $phpExcel | |
| 128 | + * @param string $writerType Example: Excel2007 | |
| 129 | + * @return PHPExcel_Writer_IWriter | |
| 130 | + * @throws PHPExcel_Reader_Exception | |
| 131 | + */ | |
| 132 | + public static function createWriter(PHPExcel $phpExcel, $writerType = '') { | |
| 133 | + // Search type | |
| 134 | + $searchType = 'IWriter'; | |
| 133 | 135 | |
| 134 | - // Include class | |
| 135 | - foreach (self::$searchLocations as $searchLocation) { | |
| 136 | - if ($searchLocation['type'] == $searchType) { | |
| 137 | - $className = str_replace('{0}', $writerType, $searchLocation['class']); | |
| 136 | + // Include class | |
| 137 | + foreach (self::$_searchLocations as $searchLocation) { | |
| 138 | + if ($searchLocation['type'] == $searchType) { | |
| 139 | + $className = str_replace('{0}', $writerType, $searchLocation['class']); | |
| 138 | 140 | |
| 139 | - $instance = new $className($phpExcel); | |
| 140 | - if ($instance !== null) { | |
| 141 | - return $instance; | |
| 142 | - } | |
| 143 | - } | |
| 144 | - } | |
| 141 | + $instance = new $className($phpExcel); | |
| 142 | + if ($instance !== NULL) { | |
| 143 | + return $instance; | |
| 144 | + } | |
| 145 | + } | |
| 146 | + } | |
| 145 | 147 | |
| 146 | - // Nothing found... | |
| 147 | - throw new PHPExcel_Reader_Exception("No $searchType found for type $writerType"); | |
| 148 | - } | |
| 148 | + // Nothing found... | |
| 149 | + throw new PHPExcel_Reader_Exception("No $searchType found for type $writerType"); | |
| 150 | + } // function createWriter() | |
| 149 | 151 | |
| 150 | - /** | |
| 151 | - * Create PHPExcel_Reader_IReader | |
| 152 | - * | |
| 153 | - * @static | |
| 154 | - * @access public | |
| 155 | - * @param string $readerType Example: Excel2007 | |
| 156 | - * @return PHPExcel_Reader_IReader | |
| 157 | - * @throws PHPExcel_Reader_Exception | |
| 158 | - */ | |
| 159 | - public static function createReader($readerType = '') | |
| 160 | - { | |
| 161 | - // Search type | |
| 162 | - $searchType = 'IReader'; | |
| 152 | + /** | |
| 153 | + * Create PHPExcel_Reader_IReader | |
| 154 | + * | |
| 155 | + * @static | |
| 156 | + * @access public | |
| 157 | + * @param string $readerType Example: Excel2007 | |
| 158 | + * @return PHPExcel_Reader_IReader | |
| 159 | + * @throws PHPExcel_Reader_Exception | |
| 160 | + */ | |
| 161 | + public static function createReader($readerType = '') { | |
| 162 | + // Search type | |
| 163 | + $searchType = 'IReader'; | |
| 163 | 164 | |
| 164 | - // Include class | |
| 165 | - foreach (self::$searchLocations as $searchLocation) { | |
| 166 | - if ($searchLocation['type'] == $searchType) { | |
| 167 | - $className = str_replace('{0}', $readerType, $searchLocation['class']); | |
| 165 | + // Include class | |
| 166 | + foreach (self::$_searchLocations as $searchLocation) { | |
| 167 | + if ($searchLocation['type'] == $searchType) { | |
| 168 | + $className = str_replace('{0}', $readerType, $searchLocation['class']); | |
| 168 | 169 | |
| 169 | - $instance = new $className(); | |
| 170 | - if ($instance !== null) { | |
| 171 | - return $instance; | |
| 172 | - } | |
| 173 | - } | |
| 174 | - } | |
| 170 | + $instance = new $className(); | |
| 171 | + if ($instance !== NULL) { | |
| 172 | + return $instance; | |
| 173 | + } | |
| 174 | + } | |
| 175 | + } | |
| 175 | 176 | |
| 176 | - // Nothing found... | |
| 177 | - throw new PHPExcel_Reader_Exception("No $searchType found for type $readerType"); | |
| 178 | - } | |
| 177 | + // Nothing found... | |
| 178 | + throw new PHPExcel_Reader_Exception("No $searchType found for type $readerType"); | |
| 179 | + } // function createReader() | |
| 179 | 180 | |
| 180 | - /** | |
| 181 | - * Loads PHPExcel from file using automatic PHPExcel_Reader_IReader resolution | |
| 182 | - * | |
| 183 | - * @static | |
| 184 | - * @access public | |
| 185 | - * @param string $pFilename The name of the spreadsheet file | |
| 186 | - * @return PHPExcel | |
| 187 | - * @throws PHPExcel_Reader_Exception | |
| 188 | - */ | |
| 189 | - public static function load($pFilename) | |
| 190 | - { | |
| 191 | - $reader = self::createReaderForFile($pFilename); | |
| 192 | - return $reader->load($pFilename); | |
| 193 | - } | |
| 181 | + /** | |
| 182 | + * Loads PHPExcel from file using automatic PHPExcel_Reader_IReader resolution | |
| 183 | + * | |
| 184 | + * @static | |
| 185 | + * @access public | |
| 186 | + * @param string $pFilename The name of the spreadsheet file | |
| 187 | + * @return PHPExcel | |
| 188 | + * @throws PHPExcel_Reader_Exception | |
| 189 | + */ | |
| 190 | + public static function load($pFilename) { | |
| 191 | + $reader = self::createReaderForFile($pFilename); | |
| 192 | + return $reader->load($pFilename); | |
| 193 | + } // function load() | |
| 194 | 194 | |
| 195 | - /** | |
| 196 | - * Identify file type using automatic PHPExcel_Reader_IReader resolution | |
| 197 | - * | |
| 198 | - * @static | |
| 199 | - * @access public | |
| 200 | - * @param string $pFilename The name of the spreadsheet file to identify | |
| 201 | - * @return string | |
| 202 | - * @throws PHPExcel_Reader_Exception | |
| 203 | - */ | |
| 204 | - public static function identify($pFilename) | |
| 205 | - { | |
| 206 | - $reader = self::createReaderForFile($pFilename); | |
| 207 | - $className = get_class($reader); | |
| 208 | - $classType = explode('_', $className); | |
| 209 | - unset($reader); | |
| 210 | - return array_pop($classType); | |
| 211 | - } | |
| 195 | + /** | |
| 196 | + * Identify file type using automatic PHPExcel_Reader_IReader resolution | |
| 197 | + * | |
| 198 | + * @static | |
| 199 | + * @access public | |
| 200 | + * @param string $pFilename The name of the spreadsheet file to identify | |
| 201 | + * @return string | |
| 202 | + * @throws PHPExcel_Reader_Exception | |
| 203 | + */ | |
| 204 | + public static function identify($pFilename) { | |
| 205 | + $reader = self::createReaderForFile($pFilename); | |
| 206 | + $className = get_class($reader); | |
| 207 | + $classType = explode('_',$className); | |
| 208 | + unset($reader); | |
| 209 | + return array_pop($classType); | |
| 210 | + } // function identify() | |
| 212 | 211 | |
| 213 | - /** | |
| 214 | - * Create PHPExcel_Reader_IReader for file using automatic PHPExcel_Reader_IReader resolution | |
| 215 | - * | |
| 216 | - * @static | |
| 217 | - * @access public | |
| 218 | - * @param string $pFilename The name of the spreadsheet file | |
| 219 | - * @return PHPExcel_Reader_IReader | |
| 220 | - * @throws PHPExcel_Reader_Exception | |
| 221 | - */ | |
| 222 | - public static function createReaderForFile($pFilename) | |
| 223 | - { | |
| 224 | - // First, lucky guess by inspecting file extension | |
| 225 | - $pathinfo = pathinfo($pFilename); | |
| 212 | + /** | |
| 213 | + * Create PHPExcel_Reader_IReader for file using automatic PHPExcel_Reader_IReader resolution | |
| 214 | + * | |
| 215 | + * @static | |
| 216 | + * @access public | |
| 217 | + * @param string $pFilename The name of the spreadsheet file | |
| 218 | + * @return PHPExcel_Reader_IReader | |
| 219 | + * @throws PHPExcel_Reader_Exception | |
| 220 | + */ | |
| 221 | + public static function createReaderForFile($pFilename) { | |
| 226 | 222 | |
| 227 | - $extensionType = null; | |
| 228 | - if (isset($pathinfo['extension'])) { | |
| 229 | - switch (strtolower($pathinfo['extension'])) { | |
| 230 | - case 'xlsx': // Excel (OfficeOpenXML) Spreadsheet | |
| 231 | - case 'xlsm': // Excel (OfficeOpenXML) Macro Spreadsheet (macros will be discarded) | |
| 232 | - case 'xltx': // Excel (OfficeOpenXML) Template | |
| 233 | - case 'xltm': // Excel (OfficeOpenXML) Macro Template (macros will be discarded) | |
| 234 | - $extensionType = 'Excel2007'; | |
| 235 | - break; | |
| 236 | - case 'xls': // Excel (BIFF) Spreadsheet | |
| 237 | - case 'xlt': // Excel (BIFF) Template | |
| 238 | - $extensionType = 'Excel5'; | |
| 239 | - break; | |
| 240 | - case 'ods': // Open/Libre Offic Calc | |
| 241 | - case 'ots': // Open/Libre Offic Calc Template | |
| 242 | - $extensionType = 'OOCalc'; | |
| 243 | - break; | |
| 244 | - case 'slk': | |
| 245 | - $extensionType = 'SYLK'; | |
| 246 | - break; | |
| 247 | - case 'xml': // Excel 2003 SpreadSheetML | |
| 248 | - $extensionType = 'Excel2003XML'; | |
| 249 | - break; | |
| 250 | - case 'gnumeric': | |
| 251 | - $extensionType = 'Gnumeric'; | |
| 252 | - break; | |
| 253 | - case 'htm': | |
| 254 | - case 'html': | |
| 255 | - $extensionType = 'HTML'; | |
| 256 | - break; | |
| 257 | - case 'csv': | |
| 258 | - // Do nothing | |
| 259 | - // We must not try to use CSV reader since it loads | |
| 260 | - // all files including Excel files etc. | |
| 261 | - break; | |
| 262 | - default: | |
| 263 | - break; | |
| 264 | - } | |
| 223 | + // First, lucky guess by inspecting file extension | |
| 224 | + $pathinfo = pathinfo($pFilename); | |
| 265 | 225 | |
| 266 | - if ($extensionType !== null) { | |
| 267 | - $reader = self::createReader($extensionType); | |
| 268 | - // Let's see if we are lucky | |
| 269 | - if (isset($reader) && $reader->canRead($pFilename)) { | |
| 270 | - return $reader; | |
| 271 | - } | |
| 272 | - } | |
| 273 | - } | |
| 226 | + $extensionType = NULL; | |
| 227 | + if (isset($pathinfo['extension'])) { | |
| 228 | + switch (strtolower($pathinfo['extension'])) { | |
| 229 | + case 'xlsx': // Excel (OfficeOpenXML) Spreadsheet | |
| 230 | + case 'xlsm': // Excel (OfficeOpenXML) Macro Spreadsheet (macros will be discarded) | |
| 231 | + case 'xltx': // Excel (OfficeOpenXML) Template | |
| 232 | + case 'xltm': // Excel (OfficeOpenXML) Macro Template (macros will be discarded) | |
| 233 | + $extensionType = 'Excel2007'; | |
| 234 | + break; | |
| 235 | + case 'xls': // Excel (BIFF) Spreadsheet | |
| 236 | + case 'xlt': // Excel (BIFF) Template | |
| 237 | + $extensionType = 'Excel5'; | |
| 238 | + break; | |
| 239 | + case 'ods': // Open/Libre Offic Calc | |
| 240 | + case 'ots': // Open/Libre Offic Calc Template | |
| 241 | + $extensionType = 'OOCalc'; | |
| 242 | + break; | |
| 243 | + case 'slk': | |
| 244 | + $extensionType = 'SYLK'; | |
| 245 | + break; | |
| 246 | + case 'xml': // Excel 2003 SpreadSheetML | |
| 247 | + $extensionType = 'Excel2003XML'; | |
| 248 | + break; | |
| 249 | + case 'gnumeric': | |
| 250 | + $extensionType = 'Gnumeric'; | |
| 251 | + break; | |
| 252 | + case 'htm': | |
| 253 | + case 'html': | |
| 254 | + $extensionType = 'HTML'; | |
| 255 | + break; | |
| 256 | + case 'csv': | |
| 257 | + // Do nothing | |
| 258 | + // We must not try to use CSV reader since it loads | |
| 259 | + // all files including Excel files etc. | |
| 260 | + break; | |
| 261 | + default: | |
| 262 | + break; | |
| 263 | + } | |
| 274 | 264 | |
| 275 | - // If we reach here then "lucky guess" didn't give any result | |
| 276 | - // Try walking through all the options in self::$autoResolveClasses | |
| 277 | - foreach (self::$autoResolveClasses as $autoResolveClass) { | |
| 278 | - // Ignore our original guess, we know that won't work | |
| 279 | - if ($autoResolveClass !== $extensionType) { | |
| 280 | - $reader = self::createReader($autoResolveClass); | |
| 281 | - if ($reader->canRead($pFilename)) { | |
| 282 | - return $reader; | |
| 283 | - } | |
| 284 | - } | |
| 285 | - } | |
| 265 | + if ($extensionType !== NULL) { | |
| 266 | + $reader = self::createReader($extensionType); | |
| 267 | + // Let's see if we are lucky | |
| 268 | + if (isset($reader) && $reader->canRead($pFilename)) { | |
| 269 | + return $reader; | |
| 270 | + } | |
| 271 | + } | |
| 272 | + } | |
| 286 | 273 | |
| 287 | - throw new PHPExcel_Reader_Exception('Unable to identify a reader for this file'); | |
| 288 | - } | |
| 274 | + // If we reach here then "lucky guess" didn't give any result | |
| 275 | + // Try walking through all the options in self::$_autoResolveClasses | |
| 276 | + foreach (self::$_autoResolveClasses as $autoResolveClass) { | |
| 277 | + // Ignore our original guess, we know that won't work | |
| 278 | + if ($autoResolveClass !== $extensionType) { | |
| 279 | + $reader = self::createReader($autoResolveClass); | |
| 280 | + if ($reader->canRead($pFilename)) { | |
| 281 | + return $reader; | |
| 282 | + } | |
| 283 | + } | |
| 284 | + } | |
| 285 | + | |
| 286 | + throw new PHPExcel_Reader_Exception('Unable to identify a reader for this file'); | |
| 287 | + } // function createReaderForFile() | |
| 289 | 288 | } |