ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
PHPExcel_IOFactory Class Reference
+ Collaboration diagram for PHPExcel_IOFactory:

Static Public Member Functions

static getSearchLocations ()
 Get search locations. More...
 
static setSearchLocations ($value)
 Set search locations. More...
 
static addSearchLocation ($type='', $location='', $classname='')
 Add search location. More...
 
static createWriter (PHPExcel $phpExcel, $writerType='')
 Create PHPExcel_Writer_IWriter. More...
 
static createReader ($readerType='')
 Create PHPExcel_Reader_IReader. More...
 
static load ($pFilename)
 Loads PHPExcel from file using automatic PHPExcel_Reader_IReader resolution. More...
 
static identify ($pFilename)
 Identify file type using automatic PHPExcel_Reader_IReader resolution. More...
 
static createReaderForFile ($pFilename)
 Create PHPExcel_Reader_IReader for file using automatic PHPExcel_Reader_IReader resolution. More...
 

Private Member Functions

 __construct ()
 Private constructor for PHPExcel_IOFactory. More...
 

Static Private Attributes

static $_searchLocations
 
static $_autoResolveClasses
 

Detailed Description

Definition at line 45 of file IOFactory.php.

Constructor & Destructor Documentation

◆ __construct()

PHPExcel_IOFactory::__construct ( )
private

Private constructor for PHPExcel_IOFactory.

Definition at line 80 of file IOFactory.php.

80 { }

Member Function Documentation

◆ addSearchLocation()

static PHPExcel_IOFactory::addSearchLocation (   $type = '',
  $location = '',
  $classname = '' 
)
static

Add search location.

public

Parameters
string$typeExample: IWriter
string$locationExample: PHPExcel/Writer/{0}.php
string$classnameExample: PHPExcel_Writer_{0}

Definition at line 118 of file IOFactory.php.

References $location, $type, and array.

118  {
119  self::$_searchLocations[] = array( 'type' => $type, 'path' => $location, 'class' => $classname );
120  } // function addSearchLocation()
$type
$location
Definition: buildRTE.php:44
Create styles array
The data for the language used.

◆ createReader()

static PHPExcel_IOFactory::createReader (   $readerType = '')
static

Create PHPExcel_Reader_IReader.

public

Parameters
string$readerTypeExample: Excel2007
Returns
PHPExcel_Reader_IReader
Exceptions
PHPExcel_Reader_Exception

Definition at line 161 of file IOFactory.php.

161  {
162  // Search type
163  $searchType = 'IReader';
164 
165  // Include class
166  foreach (self::$_searchLocations as $searchLocation) {
167  if ($searchLocation['type'] == $searchType) {
168  $className = str_replace('{0}', $readerType, $searchLocation['class']);
169 
170  $instance = new $className();
171  if ($instance !== NULL) {
172  return $instance;
173  }
174  }
175  }
176 
177  // Nothing found...
178  throw new PHPExcel_Reader_Exception("No $searchType found for type $readerType");
179  } // function createReader()

◆ createReaderForFile()

static PHPExcel_IOFactory::createReaderForFile (   $pFilename)
static

Create PHPExcel_Reader_IReader for file using automatic PHPExcel_Reader_IReader resolution.

public

Parameters
string$pFilenameThe name of the spreadsheet file
Returns
PHPExcel_Reader_IReader
Exceptions
PHPExcel_Reader_Exception

Definition at line 221 of file IOFactory.php.

References $reader.

221  {
222 
223  // First, lucky guess by inspecting file extension
224  $pathinfo = pathinfo($pFilename);
225 
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  }
264 
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  }
273 
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()

◆ createWriter()

static PHPExcel_IOFactory::createWriter ( PHPExcel  $phpExcel,
  $writerType = '' 
)
static

Create PHPExcel_Writer_IWriter.

public

Parameters
PHPExcel$phpExcel
string$writerTypeExample: Excel2007
Returns
PHPExcel_Writer_IWriter
Exceptions
PHPExcel_Reader_Exception

Definition at line 132 of file IOFactory.php.

Referenced by ilExcel\sendToClient(), ilExcel\writeToFile(), and ilExcel\writeToTmpFile().

132  {
133  // Search type
134  $searchType = 'IWriter';
135 
136  // Include class
137  foreach (self::$_searchLocations as $searchLocation) {
138  if ($searchLocation['type'] == $searchType) {
139  $className = str_replace('{0}', $writerType, $searchLocation['class']);
140 
141  $instance = new $className($phpExcel);
142  if ($instance !== NULL) {
143  return $instance;
144  }
145  }
146  }
147 
148  // Nothing found...
149  throw new PHPExcel_Reader_Exception("No $searchType found for type $writerType");
150  } // function createWriter()
+ Here is the caller graph for this function:

◆ getSearchLocations()

static PHPExcel_IOFactory::getSearchLocations ( )
static

Get search locations.

public

Returns
array

Definition at line 89 of file IOFactory.php.

89  {
90  return self::$_searchLocations;
91  } // function getSearchLocations()

◆ identify()

static PHPExcel_IOFactory::identify (   $pFilename)
static

Identify file type using automatic PHPExcel_Reader_IReader resolution.

public

Parameters
string$pFilenameThe name of the spreadsheet file to identify
Returns
string
Exceptions
PHPExcel_Reader_Exception

Definition at line 204 of file IOFactory.php.

References $reader.

204  {
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()

◆ load()

static PHPExcel_IOFactory::load (   $pFilename)
static

Loads PHPExcel from file using automatic PHPExcel_Reader_IReader resolution.

public

Parameters
string$pFilenameThe name of the spreadsheet file
Returns
PHPExcel
Exceptions
PHPExcel_Reader_Exception

Definition at line 190 of file IOFactory.php.

References $reader.

Referenced by ilExcel\loadFromFile().

190  {
191  $reader = self::createReaderForFile($pFilename);
192  return $reader->load($pFilename);
193  } // function load()
+ Here is the caller graph for this function:

◆ setSearchLocations()

static PHPExcel_IOFactory::setSearchLocations (   $value)
static

Set search locations.

public

Parameters
array$value
Exceptions
PHPExcel_Reader_Exception

Definition at line 101 of file IOFactory.php.

101  {
102  if (is_array($value)) {
103  self::$_searchLocations = $value;
104  } else {
105  throw new PHPExcel_Reader_Exception('Invalid parameter passed.');
106  }
107  } // function setSearchLocations()

Field Documentation

◆ $_autoResolveClasses

PHPExcel_IOFactory::$_autoResolveClasses
staticprivate
Initial value:
'Excel2007',
'Excel5',
'Excel2003XML',
'OOCalc',
'SYLK',
'Gnumeric',
'HTML',
'CSV',
)

Definition at line 66 of file IOFactory.php.

◆ $_searchLocations

PHPExcel_IOFactory::$_searchLocations
staticprivate
Initial value:
array( 'type' => 'IWriter', 'path' => 'PHPExcel/Writer/{0}.php', 'class' => 'PHPExcel_Writer_{0}' ),
array( 'type' => 'IReader', 'path' => 'PHPExcel/Reader/{0}.php', 'class' => 'PHPExcel_Reader_{0}' )
)

Definition at line 54 of file IOFactory.php.


The documentation for this class was generated from the following file: