Permalink
Browse files

BackwardsCompatibilityBreak - fCore::getOS() and fCore::getPHPVersion…

…() were removed and replaced with fCore::checkOS() and fCore::checkVersion()
  • Loading branch information...
wbond committed Feb 17, 2009
1 parent ee82755 commit 09f5f00aaf82fecb85e165d8770bfae1e336aa24
View
@@ -2,15 +2,16 @@
/**
* Provides a consistent cookie API, HTTPOnly compatibility with older PHP versions and default parameters
*
* @copyright Copyright (c) 2008 Will Bond
* @copyright Copyright (c) 2008-2009 Will Bond
* @author Will Bond [wb] <will@flourishlib.com>
* @license http://flourishlib.com/license
*
* @package Flourish
* @link http://flourishlib.com/fCookie
*
* @version 1.0.0b
* @changes 1.0.0b The initial implementation [wb, 2008-09-01]
* @version 1.0.0b2
* @changes 1.0.0b2 Updated for new fCore API [wb, 2009-02-16]
* @changes 1.0.0b The initial implementation [wb, 2008-09-01]
*/
class fCookie
{
@@ -145,7 +146,7 @@ static public function set($name, $value, $expires=NULL, $path=NULL, $domain=NUL
}
// Adds support for httponly cookies to PHP 5.0 and 5.1
if (strlen($value) && $httponly && fCore::getPHPVersion() < '5.2.0') {
if (strlen($value) && $httponly && !fCore::checkVersion('5.2')) {
$header_string = urlencode($name) . '=' . urlencode($value);
if ($expires) {
$header_string .= '; expires=' . gmdate('D, d-M-Y H:i:s T', $expires);
@@ -259,7 +260,7 @@ private function __construct() { }
/**
* Copyright (c) 2008 Will Bond <will@flourishlib.com>
* Copyright (c) 2008-2009 Will Bond <will@flourishlib.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
View
@@ -9,7 +9,8 @@
* @package Flourish
* @link http://flourishlib.com/fCore
*
* @version 1.0.0b3
* @version 1.0.0b4
* @changes 1.0.0b4 Backwards compatibility break - ::getOS() and ::getPHPVersion() removed, replaced with ::checkOS() and ::checkVersion() [wb, 2009-02-16]
* @changes 1.0.0b3 ::handleError() now displays what kind of error occured as the heading [wb, 2009-02-15]
* @changes 1.0.0b2 Added ::registerDebugCallback() [wb, 2009-02-07]
* @changes 1.0.0b The initial implementation [wb, 2007-09-25]
@@ -20,15 +21,15 @@ class fCore
const backtrace = 'fCore::backtrace';
const call = 'fCore::call';
const callback = 'fCore::callback';
const checkOS = 'fCore::checkOS';
const checkVersion = 'fCore::checkVersion';
const debug = 'fCore::debug';
const dump = 'fCore::dump';
const enableDebugging = 'fCore::enableDebugging';
const enableDynamicConstants = 'fCore::enableDynamicConstants';
const enableErrorHandling = 'fCore::enableErrorHandling';
const enableExceptionHandling = 'fCore::enableExceptionHandling';
const expose = 'fCore::expose';
const getOS = 'fCore::getOS';
const getPHPVersion = 'fCore::getPHPVersion';
const handleError = 'fCore::handleError';
const handleException = 'fCore::handleException';
const registerDebugCallback = 'fCore::registerDebugCallback';
@@ -219,7 +220,7 @@ static public function backtrace($remove_lines=0)
static public function call($callback, $parameters=array())
{
// Fix PHP 5.0 and 5.1 static callback syntax
if (is_string($callback) && self::getPHPVersion() < '5.2.0' && strpos($callback, '::') !== FALSE) {
if (is_string($callback) && strpos($callback, '::') !== FALSE) {
$callback = explode('::', $callback);
}
@@ -278,6 +279,77 @@ static private function checkDestination($destination)
}
/**
* Returns is the current OS is one of the OSes passed as a parameter
*
* Valid OS strings are:
* - `'linux'`
* - `'bsd'`
* - `'osx'`
* - `'solaris'`
* - `'windows'`
*
* @param string $os The operating system to check - see method description for valid OSes
* @param string ...
* @return boolean If the current OS is included in the list of OSes passed as parameters
*/
static public function checkOS($os)
{
$oses = func_get_args();
$valid_oses = array('linux', 'bsd', 'osx', 'solaris', 'windows');
if ($invalid_oses = array_diff($oses, $valid_oses)) {
throw new fProgrammerException(
'One or more of the OSes specified, %$1s, is invalid. Must be one of: %2$s.',
join(' ', $invalid_oses),
join(', ', $valid_oses)
);
}
$uname = php_uname('s');
if (stripos($uname, 'linux') !== FALSE) {
return in_array('linux', $oses);
} elseif (stripos($uname, 'bsd') !== FALSE) {
return in_array('bsd', $oses);
} elseif (stripos($uname, 'solaris') !== FALSE || stripos($uname, 'sunos') !== FALSE) {
return in_array('solaris', $oses);
} elseif (stripos($uname, 'windows') !== FALSE) {
return in_array('windows', $oses);
} elseif (stripos($uname, 'darwin') !== FALSE) {
return in_array('osx', $oses);
}
throw new fEnvironmentException('Unable to determine the current OS');
}
/**
* Checks to see if the running version of PHP is greater or equal to the version passed
*
* @return boolean If the running version of PHP is greater or equal to the version passed
*/
static public function checkVersion($version)
{
static $running_version = NULL;
if ($running_version === NULL) {
$running_version = preg_replace(
'#^(\d+\.\d+\.\d+).*$#D',
'\1',
PHP_VERSION
);
}
return version_compare($running_version, $version, '>=');
}
/**
* Composes text using fText if loaded
*
@@ -544,58 +616,6 @@ static private function generateContext()
}
/**
* Returns the (generalized) operating system the code is currently running on
*
* @return string Either `'windows'`, `'solaris'` or `'linux/unix'` (linux, *BSD)
*/
static public function getOS()
{
$uname = php_uname('s');
if (stripos($uname, 'linux') !== FALSE) {
return 'linux/unix';
}
if (stripos($uname, 'bsd') !== FALSE) {
return 'linux/unix';
}
if (stripos($uname, 'solaris') !== FALSE || stripos($uname, 'sunos') !== FALSE) {
return 'solaris';
}
if (stripos($uname, 'windows') !== FALSE) {
return 'windows';
}
trigger_error(
self::compose(
'Unable to reliably determine the server OS. Defaulting to %s.',
"'linux/unix'"
),
E_USER_WARNING
);
return 'linux/unix';
}
/**
* Returns the version of PHP running, ignoring any information about the OS
*
* @return string The PHP version in the format major.minor.version
*/
static public function getPHPVersion()
{
static $version = NULL;
if ($version === NULL) {
$version = phpversion();
$version = preg_replace('#^(\d+\.\d+\.\d+).*$#D', '\1', $version);
}
return $version;
}
/**
* Handles an error, creating the necessary context information and sending it to the specified destination
*
@@ -9,7 +9,8 @@
* @package Flourish
* @link http://flourishlib.com/fCryptography
*
* @version 1.0.0b3
* @version 1.0.0b4
* @changes 1.0.0b4 Updated for new fCore API [wb, 2009-02-16]
* @changes 1.0.0b3 Changed @ error suppression operator to `error_reporting()` calls [wb, 2009-01-26]
* @changes 1.0.0b2 Backwards compatibility break - changed ::symmetricKeyEncrypt() to not encrypt the IV since we are using HMAC on it [wb, 2009-01-26]
* @changes 1.0.0b The initial implementation [wb, 2007-11-27]
@@ -389,12 +390,12 @@ static private function seedRandom()
$old_level = error_reporting(error_reporting() & ~E_WARNING);
// On linux/unix/solaris we should be able to use /dev/urandom
if (fCore::getOS() != 'windows' && $handle = fopen('/dev/urandom', 'rb')) {
if (!fCore::checkOS('windows') && $handle = fopen('/dev/urandom', 'rb')) {
$bytes = fread($handle, 32);
fclose($handle);
// On windows we should be able to use the Cryptographic Application Programming Interface COM object
} elseif (fCore::getOS() == 'windows' && class_exists('COM', FALSE)) {
} elseif (fCore::checkOS('windows') && class_exists('COM', FALSE)) {
$capi = new COM('CAPICOM.Utilities.1');
$bytes = base64_decode($capi->getrandom(32, 0));
unset($capi);
View
@@ -39,7 +39,8 @@
* @package Flourish
* @link http://flourishlib.com/fDatabase
*
* @version 1.0.0b6
* @version 1.0.0b7
* @changes 1.0.0b7 Updated for new fCore API [wb, 2009-02-16]
* @changes 1.0.0b6 Fixed a bug with executing transaction queries when using the mysqli extension [wb, 2009-02-12]
* @changes 1.0.0b5 Changed @ error suppression operator to `error_reporting()` calls [wb, 2009-01-26]
* @changes 1.0.0b4 Added a few error suppression operators back in so that developers don't get errors and exceptions [wb, 2009-01-14]
@@ -350,7 +351,7 @@ private function connectToDatabase()
}
if (!$odbc && in_array('mssql', PDO::getAvailableDrivers())) {
try {
$separator = (fCore::getOS() == 'windows') ? ',' : ':';
$separator = (fCore::checkOS('windows')) ? ',' : ':';
$port = ($this->port) ? $separator . $this->port : '';
$this->connection = new PDO('mssql:host=' . $this->host . $port . ';dbname=' . $this->database, $this->username, $this->password);
} catch (PDOException $e) {
@@ -387,7 +388,7 @@ private function connectToDatabase()
}
if ($this->extension == 'mssql') {
$separator = (fCore::getOS() == 'windows') ? ',' : ':';
$separator = (fCore::checkOS('windows')) ? ',' : ':';
$this->connection = mssql_connect(($this->port) ? $this->host . $separator . $this->port : $this->host, $this->username, $this->password);
if ($this->connection !== FALSE && mssql_select_db($this->database, $this->connection) === FALSE) {
$this->connection = FALSE;
View
@@ -9,7 +9,8 @@
* @package Flourish
* @link http://flourishlib.com/fDate
*
* @version 1.0.0b3
* @version 1.0.0b5
* @changes 1.0.0b5 Updated for new fCore API [wb, 2009-02-16]
* @changes 1.0.0b4 Fixed ::__construct() to properly handle the 5.0 to 5.1 change in strtotime() [wb, 2009-01-21]
* @changes 1.0.0b3 Added support for CURRENT_TIMESTAMP and CURRENT_DATE SQL keywords [wb, 2009-01-11]
* @changes 1.0.0b2 Removed the adjustment amount check from ::adjust() [wb, 2008-12-31]
@@ -73,7 +74,7 @@ public function __construct($date=NULL)
$timestamp = strtotime(fTimestamp::fixISOWeek($date));
}
$is_51 = version_compare(fCore::getPHPVersion(), '5.1.0') != -1;
$is_51 = fCore::checkVersion('5.1');
$is_valid = ($is_51 && $timestamp !== FALSE) || (!$is_51 && $timestamp !== -1);
if (!$is_valid) {
View
@@ -15,7 +15,8 @@
* @package Flourish
* @link http://flourishlib.com/fEmail
*
* @version 1.0.0b4
* @version 1.0.0b5
* @changes 1.0.0b5 Updated for new fCore API [wb, 2009-02-16]
* @changes 1.0.0b4 The recipient error message in ::validate() no longer contains a typo [wb, 2009-02-09]
* @changes 1.0.0b3 Fixed a bug with missing content in the fValidationException thrown by ::validate() [wb, 2009-01-14]
* @changes 1.0.0b2 Fixed a few bugs with sending S/MIME encrypted/signed emails [wb, 2009-01-10]
@@ -116,7 +117,7 @@ static protected function compose($message)
*/
static public function fixQmail()
{
if (fCore::getOS() == 'windows') {
if (fCore::checkOS('windows')) {
return;
}
@@ -503,7 +504,7 @@ private function combineNameEmail($name, $email)
$email = str_replace(array("\r", "\n"), '', $email);
$name = str_replace(array('\\', '"', "\r", "\n"), '', $name);
if (!$name || fCore::getOS() == 'windows') {
if (!$name || fCore::checkOS('windows')) {
return $email;
}
@@ -947,20 +948,20 @@ public function send()
// Sendmail when not in safe mode will allow you to set the envelope from address via the -f parameter
$parameters = NULL;
if (fCore::getOS() != 'windows' && $this->bounce_to_email && !ini_get('safe_mode')) {
if (!fCore::checkOS('windows') && $this->bounce_to_email && !ini_get('safe_mode')) {
preg_match(self::EMAIL_REGEX, $this->bounce_to_email, $matches);
$parameters = '-f ' . $matches[0];
}
// Windows takes the Return-Path email from the sendmail_from ini setting
if (fCore::getOS() == 'windows' && $this->bounce_to_email) {
if (fCore::checkOS('windows') && $this->bounce_to_email) {
$old_sendmail_from = ini_get('sendmail_from');
preg_match(self::EMAIL_REGEX, $this->bounce_to_email, $matches);
ini_set('sendmail_from', $matches[0]);
}
// Apparently SMTP server strip a leading . from lines
if (fCore::getOS() == 'windows') {
if (fCore::checkOS('windows')) {
$body = str_replace("\r\n.", "\r\n..", $body);
}
@@ -997,7 +998,7 @@ public function send()
$error = !mail($to, $subject, $body, $headers, $parameters);
}
if (fCore::getOS() == 'windows' && $this->bounce_to_email) {
if (fCore::checkOS('windows') && $this->bounce_to_email) {
ini_set('sendmail_from', $old_sendmail_from);
}
Oops, something went wrong.

0 comments on commit 09f5f00

Please sign in to comment.