update 1.0.8.0

Commits for version update
This commit is contained in:
Manish Verma
2016-10-17 12:02:27 +05:30
parent dec927987b
commit 76e85db070
9674 changed files with 495757 additions and 58922 deletions

View File

@@ -0,0 +1,126 @@
<?php namespace Maatwebsite\Excel\Classes;
use PHPExcel_Settings;
use Illuminate\Support\Facades\Config;
use PHPExcel_CachedObjectStorageFactory;
class Cache {
/**
* PHPExcel cache class
* @var string
*/
protected $class = 'PHPExcel_CachedObjectStorageFactory';
/**
* Available caching drivers
* @var array
*/
protected $available = array(
'memory' => 'cache_in_memory',
'gzip' => 'cache_in_memory_gzip',
'serialized' => 'cache_in_memory_serialized',
'igbinary' => 'cache_igbinary',
'discISAM' => 'cache_to_discISAM',
'apc' => 'cache_to_apc',
'memcache' => 'cache_to_memcache',
'temp' => 'cache_to_phpTemp',
'wincache' => 'cache_to_wincache',
'sqlite' => 'cache_to_sqlite',
'sqlite3' => 'cache_to_sqlite3'
);
/**
* The name of the config file
* @var string
*/
private $configName = 'excel.cache';
/**
* Cache constructor
*/
public function __construct()
{
// Get driver and settings from the config
$this->driver = Config::get($this->configName . '.driver', 'memory');
$this->settings = Config::get($this->configName . '.settings', array());
// Init if caching is enabled
if ($this->isEnabled())
$this->init();
}
/**
* Init the cache
* @return void
*/
public function init()
{
// Find the cache driver
$this->findDriver();
// Set the storage driver
PHPExcel_Settings::setCacheStorageMethod($this->method, $this->settings);
}
/**
* Set the right driver
* @return void
*/
public function findDriver()
{
$property = $this->detect();
$this->method = constant($this->class . '::' . $property);
}
/**
* Detect the caching driver
* @return string $driver
*/
protected function detect()
{
// Add additional settings
$this->addAdditionalSettings();
// return the driver
return isset($this->available[$this->driver]) ? $this->available[$this->driver] : reset($this->available);
}
/**
* Add additional settings for the current driver
* @return void
*/
protected function addAdditionalSettings()
{
switch ($this->driver)
{
case 'memcache':
// Add extra memcache settings
$this->settings = array_merge($this->settings, array(
'memcacheServer' => Config::get($this->configName . '.memcache.host', 'localhost'),
'memcachePort' => Config::get($this->configName . '.memcache.port', 11211)
));
break;
case 'discISAM':
// Add dir
$this->settings = array_merge($this->settings, array(
'dir' => Config::get($this->configName . '.dir', storage_path('cache')),
));
break;
}
}
/**
* Check if caching is enabled
* @return boolean
*/
public function isEnabled()
{
return Config::get($this->configName . '.enable', true) ? true : false;
}
}

View File

@@ -0,0 +1,274 @@
<?php namespace Maatwebsite\Excel\Classes;
use PHPExcel_IOFactory;
use Illuminate\Filesystem\Filesystem;
use Maatwebsite\Excel\Exceptions\LaravelExcelException;
class FormatIdentifier {
/**
* Available formats
*
* @var array
* @access protected
*/
protected $formats = array(
'Excel2007',
'Excel5',
'Excel2003XML',
'OOCalc',
'SYLK',
'Gnumeric',
'CSV',
'HTML',
'PDF'
);
/**
* Construct new format identifier
* @param Filesystem $filesystem
*/
public function __construct(Filesystem $filesystem)
{
$this->filesystem = $filesystem;
}
/**
* Get the file format by file
* @param $file
* @throws LaravelExcelException
* @return string $format
*/
public function getFormatByFile($file)
{
// get the file extension
$ext = $this->getExtension($file);
// get the file format
$format = $this->getFormatByExtension($ext);
// Check if the file can be read
if ($this->canRead($format, $file))
return $format;
// Do a last try to init the file with all available readers
return $this->lastResort($file, $format, $ext);
}
/**
* Identify file format
* @param $ext
* @return string $format
*/
public function getFormatByExtension($ext)
{
switch ($ext)
{
/*
|--------------------------------------------------------------------------
| Excel 2007
|--------------------------------------------------------------------------
*/
case 'xlsx':
case 'xlsm':
case 'xltx':
case 'xltm':
return 'Excel2007';
break;
/*
|--------------------------------------------------------------------------
| Excel5
|--------------------------------------------------------------------------
*/
case 'xls':
case 'xlt':
return 'Excel5';
break;
/*
|--------------------------------------------------------------------------
| OOCalc
|--------------------------------------------------------------------------
*/
case 'ods':
case 'ots':
return 'OOCalc';
break;
/*
|--------------------------------------------------------------------------
| SYLK
|--------------------------------------------------------------------------
*/
case 'slk':
return 'SYLK';
break;
/*
|--------------------------------------------------------------------------
| Excel2003XML
|--------------------------------------------------------------------------
*/
case 'xml':
return 'Excel2003XML';
break;
/*
|--------------------------------------------------------------------------
| Gnumeric
|--------------------------------------------------------------------------
*/
case 'gnumeric':
return 'Gnumeric';
break;
/*
|--------------------------------------------------------------------------
| HTML
|--------------------------------------------------------------------------
*/
case 'htm':
case 'html':
return 'HTML';
break;
/*
|--------------------------------------------------------------------------
| CSV
|--------------------------------------------------------------------------
*/
case 'csv':
case 'txt':
return 'CSV';
break;
/*
|--------------------------------------------------------------------------
| PDF
|--------------------------------------------------------------------------
*/
case 'pdf':
return 'PDF';
break;
}
}
/**
* Get the content type by file format
* @param string $format
* @return string $contentType
*/
public function getContentTypeByFormat($format)
{
switch ($format)
{
/*
|--------------------------------------------------------------------------
| Excel 2007
|--------------------------------------------------------------------------
*/
case 'Excel2007':
return 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet; charset=UTF-8';
break;
/*
|--------------------------------------------------------------------------
| Excel5
|--------------------------------------------------------------------------
*/
case 'Excel5':
return 'application/vnd.ms-excel; charset=UTF-8';
break;
/*
|--------------------------------------------------------------------------
| HTML
|--------------------------------------------------------------------------
*/
case 'HTML':
return 'HTML';
break;
/*
|--------------------------------------------------------------------------
| CSV
|--------------------------------------------------------------------------
*/
case 'CSV':
return 'application/csv; charset=UTF-8';
break;
/*
|--------------------------------------------------------------------------
| PDF
|--------------------------------------------------------------------------
*/
case 'PDF':
return'application/pdf; charset=UTF-8';
break;
}
}
/**
* Try every reader we have
* @param $file
* @param bool $wrongFormat
* @param string $ext
* @throws LaravelExcelException
* @return string $format
*/
protected function lastResort($file, $wrongFormat = false, $ext = 'xls')
{
// Loop through all available formats
foreach ($this->formats as $format)
{
// Check if the file could be read
if ($wrongFormat != $format && $this->canRead($format, $file))
return $format;
}
// Give up searching and throw an exception
throw new LaravelExcelException('[ERROR] Reader could not identify file format for file [' . $file . '] with extension [' . $ext . ']');
}
/**
* Check if we can read the file
* @param $format
* @param $file
* @return boolean
*/
protected function canRead($format, $file)
{
if ($format)
{
$reader = $this->initReader($format);
return $reader && $reader->canRead($file);
}
return false;
}
/**
* Init the reader based on the format
* @param string $format
* @return \PHPExcel_Reader_IReader
*/
protected function initReader($format)
{
return PHPExcel_IOFactory::createReader($format);
}
/**
* Get the file extension
* @param string $file
* @return string
*/
protected function getExtension($file)
{
return strtolower($this->filesystem->extension($file));
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,124 @@
<?php namespace Maatwebsite\Excel\Classes;
use PHPExcel as PHPOffice_PHPExcel;
use Illuminate\Support\Facades\Config;
/**
*
* Laravel wrapper for PHPExcel
*
* @category Laravel Excel
* @package maatwebsite/excel
* @copyright Copyright (c) 2013 - 2014 Maatwebsite (http://www.maatwebsite.nl)
* @copyright Original Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @author Maatwebsite <info@maatwebsite.nl>
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
*/
class PHPExcel extends PHPOffice_PHPExcel {
/**
* Allowed autofill properties
* @var array
*/
public $allowedProperties = array(
'creator',
'lastModifiedBy',
'description',
'subject',
'keywords',
'category',
'manager',
'company'
);
/**
* Create sheet and add it to this workbook
*
* @param int|null $iSheetIndex Index where sheet should go (0,1,..., or null for last)
* @param bool|string $title
* @throws \PHPExcel_Exception
* @return LaravelExcelWorksheet
*/
public function createSheet($iSheetIndex = null, $title = false)
{
// Init new Laravel Excel worksheet
$newSheet = new LaravelExcelWorksheet($this, $title);
// Add the sheet
$this->addSheet($newSheet, $iSheetIndex);
// Return the sheet
return $newSheet;
}
/**
* Check if the user change change the workbook property
* @param string $method
* @return boolean
*/
public function isChangeableProperty($method)
{
$name = lcfirst(str_replace('set', '', $method));
return in_array($name, $this->getAllowedProperties()) ? true : false;
}
/**
* Set default properties
* @param array $custom
* @return void
*/
public function setDefaultProperties($custom = [])
{
// Get the properties
$properties = $this->getProperties();
// Get fillable properties
foreach ($this->getAllowedProperties() as $prop)
{
// Get the method
$method = 'set' . ucfirst($prop);
// get the value
$value = in_array($prop, array_keys($custom)) ? $custom[$prop] : Config::get('excel.properties.' . $prop, null);
// set the property
call_user_func_array(array($properties, $method), array($value));
}
}
/**
* load info from parent obj
* @param \PHPExcel $object
* @return $this
*/
function cloneParent(\PHPExcel $object)
{
// Init new reflection object
$class = new \ReflectionClass(get_class($object));
// Loop through all properties
foreach($class->getProperties() as $property)
{
// Make the property public
$property->setAccessible(true);
// Set the found value to this sheet
$property->setValue(
$this,
$property->getValue($object)
);
}
return $this;
}
/**
* Return all allowed properties
* @return array
*/
public function getAllowedProperties()
{
return $this->allowedProperties;
}
}