Skip to content

Commit

Permalink
BackwardsCompatibilityBreak - fCore::detectOpcodeCache() was renamed …
Browse files Browse the repository at this point in the history
…to fLoader::hasOpcodeCache().

Added fLoader. Added flourish.rev file to track release version across version control systems.
  • Loading branch information
wbond committed Apr 12, 2012
1 parent acb4b43 commit 3903f02
Show file tree
Hide file tree
Showing 2 changed files with 307 additions and 31 deletions.
33 changes: 2 additions & 31 deletions classes/fCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
* @package Flourish
* @link http://flourishlib.com/fCore
*
* @version 1.0.0b23
* @version 1.0.0b24
* @changes 1.0.0b24 Backwards Compatibility Break - moved ::detectOpcodeCache() to fLoader::hasOpcodeCache() [wb, 2011-08-26]
* @changes 1.0.0b23 Backwards Compatibility Break - changed the email subject of error/exception emails to include relevant file info, instead of the timestamp, for better email message threading [wb, 2011-06-20]
* @changes 1.0.0b22 Fixed a bug with dumping arrays containing integers [wb, 2011-05-26]
* @changes 1.0.0b21 Changed ::startErrorCapture() to allow "stacking" it via multiple calls, fixed a couple of bugs with ::dump() mangling strings in the form `int(1)`, fixed mispelling of `occurred` [wb, 2011-05-09]
Expand Down Expand Up @@ -46,7 +47,6 @@ class fCore
const checkVersion = 'fCore::checkVersion';
const configureSMTP = 'fCore::configureSMTP';
const debug = 'fCore::debug';
const detectOpcodeCache = 'fCore::detectOpcodeCache';
const disableContext = 'fCore::disableContext';
const dump = 'fCore::dump';
const enableDebugging = 'fCore::enableDebugging';
Expand Down Expand Up @@ -544,35 +544,6 @@ static public function debug($message, $force=FALSE)
}


/**
* Detects if a PHP opcode cache is installed
*
* The following opcode caches are currently detected:
*
* - [http://pecl.php.net/package/APC APC]
* - [http://eaccelerator.net eAccelerator]
* - [http://www.nusphere.com/products/phpexpress.htm Nusphere PhpExpress]
* - [http://turck-mmcache.sourceforge.net/index_old.html Turck MMCache]
* - [http://xcache.lighttpd.net XCache]
* - [http://www.zend.com/en/products/server/ Zend Server (Optimizer+)]
* - [http://www.zend.com/en/products/platform/ Zend Platform (Code Acceleration)]
*
* @return boolean If a PHP opcode cache is loaded
*/
static public function detectOpcodeCache()
{
$apc = ini_get('apc.enabled');
$eaccelerator = ini_get('eaccelerator.enable');
$mmcache = ini_get('mmcache.enable');
$phpexpress = function_exists('phpexpress');
$xcache = ini_get('xcache.size') > 0 && ini_get('xcache.cacher');
$zend_accelerator = ini_get('zend_accelerator.enabled');
$zend_plus = ini_get('zend_optimizerplus.enable');

return $apc || $eaccelerator || $mmcache || $phpexpress || $xcache || $zend_accelerator || $zend_plus;
}


/**
* Creates a string representation of any variable using predefined strings for booleans, `NULL` and empty strings
*
Expand Down
305 changes: 305 additions & 0 deletions classes/fLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
<?php
/**
* A class that loads Flourish
*
* @copyright Copyright (c) 2011 Will Bond
* @author Will Bond [wb] <[email protected]>
* @license http://flourishlib.com/license
*
* @package Flourish
* @link http://flourishlib.com/fLoader
*
* @version 1.0.0b
* @changes 1.0.0b The initial implementation [wb, 2011-08-26]
*/
class fLoader
{
// The following constants allow for nice looking callbacks to static methods
const autoload = 'fLoader::autoload';
const best = 'fLoader::best';
const eager = 'fLoader::eager';
const hasOpcodeCache = 'fLoader::hasOpcodeCache';
const lazy = 'fLoader::lazy';


/**
* The Flourish classes in dependency order
*
* @var array
*/
static private $classes = array(
'fException',
'fExpectedException',
'fEmptySetException',
'fNoRemainingException',
'fNoRowsException',
'fNotFoundException',
'fValidationException',
'fUnexpectedException',
'fConnectivityException',
'fEnvironmentException',
'fProgrammerException',
'fSQLException',
'fActiveRecord',
'fAuthorization',
'fAuthorizationException',
'fBuffer',
'fCRUD',
'fCache',
'fCookie',
'fCore',
'fCryptography',
'fDatabase',
'fDate',
'fDirectory',
'fEmail',
'fFile',
'fFilesystem',
'fGrammar',
'fHTML',
'fImage',
'fJSON',
'fMailbox',
'fMessaging',
'fMoney',
'fNumber',
'fORM',
'fORMColumn',
'fORMDatabase',
'fORMDate',
'fORMFile',
'fORMJSON',
'fORMMoney',
'fORMOrdering',
'fORMRelated',
'fORMSchema',
'fORMValidation',
'fRecordSet',
'fRequest',
'fResult',
'fSMTP',
'fSQLSchemaTranslation',
'fSQLTranslation',
'fSchema',
'fSession',
'fStatement',
'fTemplating',
'fText',
'fTime',
'fTimestamp',
'fURL',
'fUTF8',
'fUnbufferedResult',
'fUpload',
'fValidation',
'fXML'
);

/**
* The path Flourish is installed into
*
* @var string
*/
static private $path = NULL;


/**
* Tries to load a Flourish class
*
* @internal
*
* @param string $class The class to load
* @return void
*/
static public function autoload($class)
{
if ($class[0] != 'f' || ord($class[1]) < 65 || ord($class[1]) > 90) {
return;
}

if (!in_array($class, self::$classes)) {
return;
}

include self::$path . $class . '.php';
}


/**
* Performs eager loading if an op-code cache is present, otherwise lazy
*
* @return void
*/
static public function best()
{
if (self::hasOpcodeCache()) {
return self::eager();
}
self::lazy();
}


/**
* Creates functions that act as chainable constructors for value objects
*
* @return void
*/
static private function createConstructorFunctions()
{
if (function_exists('fDate')) {
return;
}

function fDate($date=NULL)
{
return new fDate($date);
}

function fDirectory($directory)
{
return new fDirectory($directory);
}

function fFile($file)
{
return new fFile($file);
}

function fImage($file_path)
{
return new fImage($file_path);
}

function fMoney($amount, $currency=NULL)
{
return new fMoney($amount, $currency);
}

function fNumber($value, $scale=NULL)
{
return new fNumber($value, $scale);
}

function fTime($time=NULL)
{
return new fTime($time);
}

function fTimestamp($datetime=NULL, $timezone=NULL)
{
return new fTimestamp($datetime, $timezone);
}
}


/**
* Loads all Flourish classes when called
*
* @return void
*/
static public function eager()
{
self::setPath();
self::createConstructorFunctions();
foreach (self::$classes as $class) {
include self::$path . $class . '.php';
}
}


/**
* Check if a PHP opcode cache is installed
*
* The following opcode caches are currently detected:
*
* - [http://pecl.php.net/package/APC APC]
* - [http://eaccelerator.net eAccelerator]
* - [http://www.nusphere.com/products/phpexpress.htm Nusphere PhpExpress]
* - [http://turck-mmcache.sourceforge.net/index_old.html Turck MMCache]
* - [http://xcache.lighttpd.net XCache]
* - [http://www.zend.com/en/products/server/ Zend Server (Optimizer+)]
* - [http://www.zend.com/en/products/platform/ Zend Platform (Code Acceleration)]
*
* @return boolean If a PHP opcode cache is loaded
*/
static public function hasOpcodeCache()
{
$apc = ini_get('apc.enabled');
$eaccelerator = ini_get('eaccelerator.enable');
$mmcache = ini_get('mmcache.enable');
$phpexpress = function_exists('phpexpress');
$xcache = ini_get('xcache.size') > 0 && ini_get('xcache.cacher');
$zend_accelerator = ini_get('zend_accelerator.enabled');
$zend_plus = ini_get('zend_optimizerplus.enable');

return $apc || $eaccelerator || $mmcache || $phpexpress || $xcache || $zend_accelerator || $zend_plus;
}


/**
* Registers an autoloader for Flourish via [http://php.net/spl_autoload_register `spl_autoload_register()`]
*
* @return void
*/
static public function lazy()
{
self::setPath();
self::createConstructorFunctions();

if (function_exists('__autoload') && !spl_autoload_functions()) {
throw new Exception(
'fLoader::lazy() was called, which adds an autoload function ' .
'via spl_autoload_register(). It appears an __autoload ' .
'function has already been defined, but not registered via ' .
'spl_autoload_register(). Please call ' .
'spl_autoload_register("__autoload") after fLoader::lazy() ' .
'to ensure your autoloader continues to function.'
);
}

spl_autoload_register(array('fLoader', 'autoload'));
}


/**
* Determines where Flourish is installed
*
* @return void
*/
static private function setPath()
{
self::$path = realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR;
}


/**
* Forces use as a static class
*
* @return fLoader
*/
private function __construct() { }
}



/**
* Copyright (c) 2011 Will Bond <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

0 comments on commit 3903f02

Please sign in to comment.