More PSR-2 goodness.... getting there slowly

This commit is contained in:
MarkBaker 2015-05-13 00:40:55 +01:00
parent a86cbaa230
commit f7296f58b4
5 changed files with 4118 additions and 4141 deletions

View File

@ -3949,4 +3949,3 @@ class PHPExcel_Calculation {
} // function listFunctionNames() } // function listFunctionNames()
} // class PHPExcel_Calculation } // class PHPExcel_Calculation

View File

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_Shared_CodePage
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,15 +25,6 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
/**
* PHPExcel_Shared_CodePage
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_CodePage class PHPExcel_Shared_CodePage
{ {
/** /**
@ -102,5 +94,4 @@ class PHPExcel_Shared_CodePage
throw new PHPExcel_Exception('Unknown codepage: ' . $codePage); throw new PHPExcel_Exception('Unknown codepage: ' . $codePage);
} }
} }

View File

@ -1,7 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_Shared_Date
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -25,15 +25,6 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
/**
* PHPExcel_Shared_Date
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_Date class PHPExcel_Shared_Date
{ {
/** constants */ /** constants */
@ -47,7 +38,8 @@ class PHPExcel_Shared_Date
* @public * @public
* @var string[] * @var string[]
*/ */
public static $_monthNames = array( 'Jan' => 'January', public static $monthNames = array(
'Jan' => 'January',
'Feb' => 'February', 'Feb' => 'February',
'Mar' => 'March', 'Mar' => 'March',
'Apr' => 'April', 'Apr' => 'April',
@ -68,7 +60,8 @@ class PHPExcel_Shared_Date
* @public * @public
* @var string[] * @var string[]
*/ */
public static $_numberSuffixes = array( 'st', public static $numberSuffixes = array(
'st',
'nd', 'nd',
'rd', 'rd',
'th', 'th',
@ -80,7 +73,7 @@ class PHPExcel_Shared_Date
* @private * @private
* @var int * @var int
*/ */
protected static $_excelBaseDate = self::CALENDAR_WINDOWS_1900; protected static $excelBaseDate = self::CALENDAR_WINDOWS_1900;
/** /**
* Set the Excel calendar (Windows 1900 or Mac 1904) * Set the Excel calendar (Windows 1900 or Mac 1904)
@ -88,14 +81,15 @@ class PHPExcel_Shared_Date
* @param integer $baseDate Excel base date (1900 or 1904) * @param integer $baseDate Excel base date (1900 or 1904)
* @return boolean Success or failure * @return boolean Success or failure
*/ */
public static function setExcelCalendar($baseDate) { public static function setExcelCalendar($baseDate)
{
if (($baseDate == self::CALENDAR_WINDOWS_1900) || if (($baseDate == self::CALENDAR_WINDOWS_1900) ||
($baseDate == self::CALENDAR_MAC_1904)) { ($baseDate == self::CALENDAR_MAC_1904)) {
self::$_excelBaseDate = $baseDate; self::$excelBaseDate = $baseDate;
return TRUE; return true;
}
return false;
} }
return FALSE;
} // function setExcelCalendar()
/** /**
@ -103,9 +97,10 @@ class PHPExcel_Shared_Date
* *
* @return integer Excel base date (1900 or 1904) * @return integer Excel base date (1900 or 1904)
*/ */
public static function getExcelCalendar() { public static function getExcelCalendar()
return self::$_excelBaseDate; {
} // function getExcelCalendar() return self::$excelBaseDate;
}
/** /**
@ -117,20 +112,21 @@ class PHPExcel_Shared_Date
* @param string $timezone The timezone for finding the adjustment from UST * @param string $timezone The timezone for finding the adjustment from UST
* @return long PHP serialized date/time * @return long PHP serialized date/time
*/ */
public static function ExcelToPHP($dateValue = 0, $adjustToTimezone = FALSE, $timezone = NULL) { public static function ExcelToPHP($dateValue = 0, $adjustToTimezone = false, $timezone = null)
if (self::$_excelBaseDate == self::CALENDAR_WINDOWS_1900) { {
$my_excelBaseDate = 25569; if (self::$excelBaseDate == self::CALENDAR_WINDOWS_1900) {
$myexcelBaseDate = 25569;
// Adjust for the spurious 29-Feb-1900 (Day 60) // Adjust for the spurious 29-Feb-1900 (Day 60)
if ($dateValue < 60) { if ($dateValue < 60) {
--$my_excelBaseDate; --$myexcelBaseDate;
} }
} else { } else {
$my_excelBaseDate = 24107; $myexcelBaseDate = 24107;
} }
// Perform conversion // Perform conversion
if ($dateValue >= 1) { if ($dateValue >= 1) {
$utcDays = $dateValue - $my_excelBaseDate; $utcDays = $dateValue - $myexcelBaseDate;
$returnValue = round($utcDays * 86400); $returnValue = round($utcDays * 86400);
if (($returnValue <= PHP_INT_MAX) && ($returnValue >= -PHP_INT_MAX)) { if (($returnValue <= PHP_INT_MAX) && ($returnValue >= -PHP_INT_MAX)) {
$returnValue = (integer) $returnValue; $returnValue = (integer) $returnValue;
@ -146,9 +142,8 @@ class PHPExcel_Shared_Date
PHPExcel_Shared_TimeZone::getTimezoneAdjustment($timezone, $returnValue) : PHPExcel_Shared_TimeZone::getTimezoneAdjustment($timezone, $returnValue) :
0; 0;
// Return
return $returnValue + $timezoneAdjustment; return $returnValue + $timezoneAdjustment;
} // function ExcelToPHP() }
/** /**
@ -157,7 +152,8 @@ class PHPExcel_Shared_Date
* @param integer $dateValue Excel date/time value * @param integer $dateValue Excel date/time value
* @return DateTime PHP date/time object * @return DateTime PHP date/time object
*/ */
public static function ExcelToPHPObject($dateValue = 0) { public static function ExcelToPHPObject($dateValue = 0)
{
$dateTime = self::ExcelToPHP($dateValue); $dateTime = self::ExcelToPHP($dateValue);
$days = floor($dateTime / 86400); $days = floor($dateTime / 86400);
$time = round((($dateTime / 86400) - $days) * 86400); $time = round((($dateTime / 86400) - $days) * 86400);
@ -169,7 +165,7 @@ class PHPExcel_Shared_Date
$dateObj->setTime($hours,$minutes,$seconds); $dateObj->setTime($hours,$minutes,$seconds);
return $dateObj; return $dateObj;
} // function ExcelToPHPObject() }
/** /**
@ -182,10 +178,11 @@ class PHPExcel_Shared_Date
* @return mixed Excel date/time value * @return mixed Excel date/time value
* or boolean FALSE on failure * or boolean FALSE on failure
*/ */
public static function PHPToExcel($dateValue = 0, $adjustToTimezone = FALSE, $timezone = NULL) { public static function PHPToExcel($dateValue = 0, $adjustToTimezone = false, $timezone = null)
{
$saveTimeZone = date_default_timezone_get(); $saveTimeZone = date_default_timezone_get();
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
$retValue = FALSE; $retValue = false;
if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) { if ((is_object($dateValue)) && ($dateValue instanceof DateTime)) {
$retValue = self::FormattedPHPToExcel( $dateValue->format('Y'), $dateValue->format('m'), $dateValue->format('d'), $retValue = self::FormattedPHPToExcel( $dateValue->format('Y'), $dateValue->format('m'), $dateValue->format('d'),
$dateValue->format('H'), $dateValue->format('i'), $dateValue->format('s') $dateValue->format('H'), $dateValue->format('i'), $dateValue->format('s')
@ -198,7 +195,7 @@ class PHPExcel_Shared_Date
date_default_timezone_set($saveTimeZone); date_default_timezone_set($saveTimeZone);
return $retValue; return $retValue;
} // function PHPToExcel() }
/** /**
@ -212,18 +209,21 @@ class PHPExcel_Shared_Date
* @param long $seconds * @param long $seconds
* @return long Excel date/time value * @return long Excel date/time value
*/ */
public static function FormattedPHPToExcel($year, $month, $day, $hours=0, $minutes=0, $seconds=0) { public static function FormattedPHPToExcel($year, $month, $day, $hours = 0, $minutes = 0, $seconds = 0)
if (self::$_excelBaseDate == self::CALENDAR_WINDOWS_1900) { {
if (self::$excelBaseDate == self::CALENDAR_WINDOWS_1900) {
// //
// Fudge factor for the erroneous fact that the year 1900 is treated as a Leap Year in MS Excel // Fudge factor for the erroneous fact that the year 1900 is treated as a Leap Year in MS Excel
// This affects every date following 28th February 1900 // This affects every date following 28th February 1900
// //
$excel1900isLeapYear = TRUE; $excel1900isLeapYear = true;
if (($year == 1900) && ($month <= 2)) { $excel1900isLeapYear = FALSE; } if (($year == 1900) && ($month <= 2)) {
$my_excelBaseDate = 2415020; $excel1900isLeapYear = false;
}
$myexcelBaseDate = 2415020;
} else { } else {
$my_excelBaseDate = 2416481; $myexcelBaseDate = 2416481;
$excel1900isLeapYear = FALSE; $excel1900isLeapYear = false;
} }
// Julian base date Adjustment // Julian base date Adjustment
@ -237,12 +237,12 @@ class PHPExcel_Shared_Date
// Calculate the Julian Date, then subtract the Excel base date (JD 2415020 = 31-Dec-1899 Giving Excel Date of 0) // Calculate the Julian Date, then subtract the Excel base date (JD 2415020 = 31-Dec-1899 Giving Excel Date of 0)
$century = substr($year,0,2); $century = substr($year,0,2);
$decade = substr($year,2,2); $decade = substr($year,2,2);
$excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $my_excelBaseDate + $excel1900isLeapYear; $excelDate = floor((146097 * $century) / 4) + floor((1461 * $decade) / 4) + floor((153 * $month + 2) / 5) + $day + 1721119 - $myexcelBaseDate + $excel1900isLeapYear;
$excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400; $excelTime = (($hours * 3600) + ($minutes * 60) + $seconds) / 86400;
return (float) $excelDate + $excelTime; return (float) $excelDate + $excelTime;
} // function FormattedPHPToExcel() }
/** /**
@ -251,13 +251,14 @@ class PHPExcel_Shared_Date
* @param PHPExcel_Cell $pCell * @param PHPExcel_Cell $pCell
* @return boolean * @return boolean
*/ */
public static function isDateTime(PHPExcel_Cell $pCell) { public static function isDateTime(PHPExcel_Cell $pCell)
{
return self::isDateTimeFormat( return self::isDateTimeFormat(
$pCell->getWorksheet()->getStyle( $pCell->getWorksheet()->getStyle(
$pCell->getCoordinate() $pCell->getCoordinate()
)->getNumberFormat() )->getNumberFormat()
); );
} // function isDateTime() }
/** /**
@ -266,9 +267,10 @@ class PHPExcel_Shared_Date
* @param PHPExcel_Style_NumberFormat $pFormat * @param PHPExcel_Style_NumberFormat $pFormat
* @return boolean * @return boolean
*/ */
public static function isDateTimeFormat(PHPExcel_Style_NumberFormat $pFormat) { public static function isDateTimeFormat(PHPExcel_Style_NumberFormat $pFormat)
{
return self::isDateTimeFormatCode($pFormat->getFormatCode()); return self::isDateTimeFormatCode($pFormat->getFormatCode());
} // function isDateTimeFormat() }
private static $possibleDateFormatCharacters = 'eymdHs'; private static $possibleDateFormatCharacters = 'eymdHs';
@ -279,13 +281,14 @@ class PHPExcel_Shared_Date
* @param string $pFormatCode * @param string $pFormatCode
* @return boolean * @return boolean
*/ */
public static function isDateTimeFormatCode($pFormatCode = '') { public static function isDateTimeFormatCode($pFormatCode = '')
{
if (strtolower($pFormatCode) === strtolower(PHPExcel_Style_NumberFormat::FORMAT_GENERAL)) if (strtolower($pFormatCode) === strtolower(PHPExcel_Style_NumberFormat::FORMAT_GENERAL))
// "General" contains an epoch letter 'e', so we trap for it explicitly here (case-insensitive check) // "General" contains an epoch letter 'e', so we trap for it explicitly here (case-insensitive check)
return FALSE; return false;
if (preg_match('/[0#]E[+-]0/i', $pFormatCode)) if (preg_match('/[0#]E[+-]0/i', $pFormatCode))
// Scientific format // Scientific format
return FALSE; return false;
// Switch on formatcode // Switch on formatcode
switch ($pFormatCode) { switch ($pFormatCode) {
// Explicitly defined date formats // Explicitly defined date formats
@ -311,34 +314,34 @@ class PHPExcel_Shared_Date
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX16: case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX16:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX17: case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX17:
case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX22: case PHPExcel_Style_NumberFormat::FORMAT_DATE_XLSX22:
return TRUE; return true;
} }
// Typically number, currency or accounting (or occasionally fraction) formats // Typically number, currency or accounting (or occasionally fraction) formats
if ((substr($pFormatCode,0,1) == '_') || (substr($pFormatCode,0,2) == '0 ')) { if ((substr($pFormatCode, 0, 1) == '_') || (substr($pFormatCode, 0, 2) == '0 ')) {
return FALSE; return false;
} }
// Try checking for any of the date formatting characters that don't appear within square braces // Try checking for any of the date formatting characters that don't appear within square braces
if (preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i',$pFormatCode)) { if (preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i', $pFormatCode)) {
// We might also have a format mask containing quoted strings... // We might also have a format mask containing quoted strings...
// we don't want to test for any of our characters within the quoted blocks // we don't want to test for any of our characters within the quoted blocks
if (strpos($pFormatCode,'"') !== FALSE) { if (strpos($pFormatCode, '"') !== false) {
$segMatcher = FALSE; $segMatcher = false;
foreach(explode('"',$pFormatCode) as $subVal) { foreach(explode('"', $pFormatCode) as $subVal) {
// Only test in alternate array entries (the non-quoted blocks) // Only test in alternate array entries (the non-quoted blocks)
if (($segMatcher = !$segMatcher) && if (($segMatcher = !$segMatcher) &&
(preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i',$subVal))) { (preg_match('/(^|\])[^\[]*['.self::$possibleDateFormatCharacters.']/i', $subVal))) {
return TRUE; return true;
} }
} }
return FALSE; return false;
} }
return TRUE; return true;
} }
// No date... // No date...
return FALSE; return false;
} // function isDateTimeFormatCode() }
/** /**
@ -347,33 +350,33 @@ class PHPExcel_Shared_Date
* @param string $dateValue Examples: '2009-12-31', '2009-12-31 15:59', '2009-12-31 15:59:10' * @param string $dateValue Examples: '2009-12-31', '2009-12-31 15:59', '2009-12-31 15:59:10'
* @return float|FALSE Excel date/time serial value * @return float|FALSE Excel date/time serial value
*/ */
public static function stringToExcel($dateValue = '') { public static function stringToExcel($dateValue = '')
{
if (strlen($dateValue) < 2) if (strlen($dateValue) < 2)
return FALSE; return false;
if (!preg_match('/^(\d{1,4}[ \.\/\-][A-Z]{3,9}([ \.\/\-]\d{1,4})?|[A-Z]{3,9}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?|\d{1,4}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?)( \d{1,2}:\d{1,2}(:\d{1,2})?)?$/iu', $dateValue)) if (!preg_match('/^(\d{1,4}[ \.\/\-][A-Z]{3,9}([ \.\/\-]\d{1,4})?|[A-Z]{3,9}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?|\d{1,4}[ \.\/\-]\d{1,4}([ \.\/\-]\d{1,4})?)( \d{1,2}:\d{1,2}(:\d{1,2})?)?$/iu', $dateValue))
return FALSE; return false;
$dateValueNew = PHPExcel_Calculation_DateTime::DATEVALUE($dateValue); $dateValueNew = PHPExcel_Calculation_DateTime::DATEVALUE($dateValue);
if ($dateValueNew === PHPExcel_Calculation_Functions::VALUE()) { if ($dateValueNew === PHPExcel_Calculation_Functions::VALUE()) {
return FALSE; return false;
} else { }
if (strpos($dateValue, ':') !== FALSE) {
if (strpos($dateValue, ':') !== false) {
$timeValue = PHPExcel_Calculation_DateTime::TIMEVALUE($dateValue); $timeValue = PHPExcel_Calculation_DateTime::TIMEVALUE($dateValue);
if ($timeValue === PHPExcel_Calculation_Functions::VALUE()) { if ($timeValue === PHPExcel_Calculation_Functions::VALUE()) {
return FALSE; return false;
} }
$dateValueNew += $timeValue; $dateValueNew += $timeValue;
} }
return $dateValueNew; return $dateValueNew;
} }
public static function monthStringToNumber($month)
} {
public static function monthStringToNumber($month) {
$monthIndex = 1; $monthIndex = 1;
foreach(self::$_monthNames as $shortMonthName => $longMonthName) { foreach(self::$monthNames as $shortMonthName => $longMonthName) {
if (($month === $longMonthName) || ($month === $shortMonthName)) { if (($month === $longMonthName) || ($month === $shortMonthName)) {
return $monthIndex; return $monthIndex;
} }
@ -382,12 +385,12 @@ class PHPExcel_Shared_Date
return $month; return $month;
} }
public static function dayStringToNumber($day) { public static function dayStringToNumber($day)
$strippedDayValue = (str_replace(self::$_numberSuffixes,'',$day)); {
$strippedDayValue = (str_replace(self::$numberSuffixes, '', $day));
if (is_numeric($strippedDayValue)) { if (is_numeric($strippedDayValue)) {
return $strippedDayValue; return $strippedDayValue;
} }
return $day; return $day;
} }
} }

View File

@ -1,6 +1,12 @@
<?php <?php
if (!defined('PCLZIP_TEMPORARY_DIR')) {
define('PCLZIP_TEMPORARY_DIR', PHPExcel_Shared_File::sys_get_temp_dir() . DIRECTORY_SEPARATOR);
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/PCLZip/pclzip.lib.php';
/** /**
* PHPExcel * PHPExcel_Shared_ZipArchive
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,20 +30,6 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
if (!defined('PCLZIP_TEMPORARY_DIR')) {
define('PCLZIP_TEMPORARY_DIR', PHPExcel_Shared_File::sys_get_temp_dir() . DIRECTORY_SEPARATOR);
}
require_once PHPEXCEL_ROOT . 'PHPExcel/Shared/PCLZip/pclzip.lib.php';
/**
* PHPExcel_Shared_ZipArchive
*
* @category PHPExcel
* @package PHPExcel_Shared_ZipArchive
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_ZipArchive class PHPExcel_Shared_ZipArchive
{ {

View File

@ -1,6 +1,7 @@
<?php <?php
/** /**
* PHPExcel * PHPExcel_Shared_ZipStreamWrapper
* *
* Copyright (c) 2006 - 2015 PHPExcel * Copyright (c) 2006 - 2015 PHPExcel
* *
@ -24,15 +25,6 @@
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL * @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version ##VERSION##, ##DATE## * @version ##VERSION##, ##DATE##
*/ */
/**
* PHPExcel_Shared_ZipStreamWrapper
*
* @category PHPExcel
* @package PHPExcel_Shared
* @copyright Copyright (c) 2006 - 2015 PHPExcel (http://www.codeplex.com/PHPExcel)
*/
class PHPExcel_Shared_ZipStreamWrapper { class PHPExcel_Shared_ZipStreamWrapper {
/** /**
* Internal ZipAcrhive * Internal ZipAcrhive