Skip to content
This repository was archived by the owner on Sep 12, 2022. It is now read-only.

Commit

Permalink
Merge pull request #25 from AOEpeople/change-codepool
Browse files Browse the repository at this point in the history
Change codepool and reformat code to PSR-1/PSR-2
  • Loading branch information
LeeSaferite committed Mar 4, 2015
2 parents 6a5e64c + d1cd8c4 commit 38b1af4
Show file tree
Hide file tree
Showing 14 changed files with 871 additions and 851 deletions.
1,348 changes: 674 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@

## Change log

* v0.5.0
* Changed code pool from 'local' to 'community'.
NB: This change could possibly break things if you are manually installing the code instead of using modman/composer
* Reformatted code to PSR-1/PSR-2
* Reformatted additional files to use spaces instead of tabs and \n for line-breaks

* v0.4.2
* Fixed bug when calling Varien_Autoload::setCache() with a bad cache file (Nicolas Fabre)

* v0.4.1
* Fixed bug in the autoload desctructor call that was throwing exceptions in developer mode
* Fixed bug in the autoload destructor call that was throwing exceptions in developer mode

* v0.4.0
* Added support for PSR-0 compliant autoloading
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

/**
* Helper
*
*
* @author Fabrizio Branca
* @since 2013-05-23
* @since 2013-05-23
*/
class Aoe_ClassPathCache_Helper_Data extends Mage_Core_Helper_Abstract {
class Aoe_ClassPathCache_Helper_Data extends Mage_Core_Helper_Abstract
{

const LOG_FILE = 'classpathcache.log';

Expand All @@ -15,18 +16,19 @@ class Aoe_ClassPathCache_Helper_Data extends Mage_Core_Helper_Abstract {
*
* @return bool
*/
public function clearClassPathCache() {
public function clearClassPathCache()
{
if (Varien_Autoload::isApcUsed() && php_sapi_name() == 'cli') {
// do frontend call
Mage::log('[ClassPathCache] Doing frontend call.', Zend_Log::INFO, self::LOG_FILE);
$response = file_get_contents($this->getUrl());
if ($response != 'OK') {
Mage::log('[ClassPathCache] Frontend call failed. Response: ' . $response, Zend_Log::INFO, self::LOG_FILE);
return FALSE;
return false;
}
}
$this->revalidateCache();
return TRUE;
return true;
}

/**
Expand All @@ -41,7 +43,7 @@ public function revalidateCache()
Varien_Autoload::getFullPath($className);
}
$duration = microtime(true) - $start;
Mage::log('[ClassPathCache] Revalidated '.count($cache).' classes (duration: ' . round($duration, 2) . ' sec)', 6 /* Zend_Log::INFO */, self::LOG_FILE);
Mage::log('[ClassPathCache] Revalidated ' . count($cache) . ' classes (duration: ' . round($duration, 2) . ' sec)', 6 /* Zend_Log::INFO */, self::LOG_FILE);
}

/**
Expand All @@ -65,11 +67,14 @@ public function checkUrl()
public function getUrl()
{
$k = Mage::helper('core')->getRandomString(16);
return Mage::getUrl('aoeclasspathcache/index/clear', array(
'k' => base64_encode($k),
'v' => base64_encode(Mage::helper('core')->encrypt($k)),
'_store' => Mage::app()->getDefaultStoreView()->getCode()
));
return Mage::getUrl(
'aoeclasspathcache/index/clear',
array(
'k' => base64_encode($k),
'v' => base64_encode(Mage::helper('core')->encrypt($k)),
'_store' => Mage::app()->getDefaultStoreView()->getCode()
)
);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

/**
* Class path cache controller
*
* @author Fabrizio Branca
* @since 2013-05-23
* @since 2013-05-23
*/
class Aoe_ClassPathCache_IndexController extends Mage_Core_Controller_Front_Action
{

/**
* Clear classpathcache
*
Expand All @@ -25,5 +25,4 @@ public function clearAction()
$this->getResponse()->setBody('WRONG KEY');
}
}

}
35 changes: 35 additions & 0 deletions app/code/community/Aoe/ClassPathCache/etc/config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0"?>
<config>
<modules>
<Aoe_ClassPathCache>
<version>0.5.0</version>
</Aoe_ClassPathCache>
</modules>
<global>
<helpers>
<aoe_classpathcache>
<class>Aoe_ClassPathCache_Helper</class>
</aoe_classpathcache>
</helpers>
</global>
<frontend>
<routers>
<aoe_classpathcache>
<use>standard</use>
<args>
<module>Aoe_ClassPathCache</module>
<frontName>aoeclasspathcache</frontName>
</args>
</aoe_classpathcache>
</routers>
</frontend>
<adminhtml>
<layout>
<updates>
<aoe_classpathcache>
<file>aoe_classpathcache/aoe_classpathcache.xml</file>
</aoe_classpathcache>
</updates>
</layout>
</adminhtml>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Varien_Autoload
static protected $_cache = array();
static protected $_numberOfFilesAddedToCache = 0;

static public $useAPC = NULL;
static public $useAPC = null;
static protected $cacheKey = self::CACHE_KEY_PREFIX;

/* Base Path */
Expand All @@ -28,16 +28,15 @@ public function __construct()
{
if (defined('BP')) {
self::$_BP = BP;
}
elseif (strpos($_SERVER["SCRIPT_FILENAME"], 'get.php') !== false) {
} elseif (strpos($_SERVER["SCRIPT_FILENAME"], 'get.php') !== false) {
global $bp; //get from get.php
if (isset($bp) && !empty($bp)){
if (isset($bp) && !empty($bp)) {
self::$_BP = $bp;
}
}

// Allow APC to be disabled externally by explicitly setting Varien_Autoload::$useAPC = FALSE;
if (self::$useAPC === NULL) {
if (self::$useAPC === null) {
self::$useAPC = extension_loaded('apc') && ini_get('apc.enabled');
}

Expand Down Expand Up @@ -71,14 +70,15 @@ static public function register()
* Load class source code
*
* @param string $class
*
* @return bool
*/
public function autoload($class)
{
// Prevent fatal errors when PHP has already started shutting down
if ( ! isset(self::$_cache)) {
if (!isset(self::$_cache)) {
$classFile = str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $class)));
return include $classFile.'.php';
return include $classFile . '.php';
}

// Get file path (from cache if available)
Expand All @@ -93,16 +93,18 @@ public function autoload($class)
* Get file name from class name
*
* @param string $className
*
* @return string
*/
static function getFileFromClassName($className) {
static function getFileFromClassName($className)
{
$className = ltrim($className, '\\');
$fileName = '';
$fileName = '';
$namespace = '';
if ($lastNsPos = strrpos($className, '\\')) {
$namespace = substr($className, 0, $lastNsPos);
$className = substr($className, $lastNsPos + 1);
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
$fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;
}

$fileName .= str_replace(' ', DIRECTORY_SEPARATOR, ucwords(str_replace('_', ' ', $className))) . '.php';
Expand Down Expand Up @@ -137,25 +139,28 @@ static public function getScope()
*
* @return string
*/
static public function getCacheFilePath() {
return self::$_BP . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'cache'. DIRECTORY_SEPARATOR . 'classPathCache.php';
static public function getCacheFilePath()
{
return self::$_BP . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'classPathCache.php';
}

/**
* Get revalidate flag file path
*
* @return string
*/
static public function getRevalidateFlagPath() {
return self::$_BP . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'cache'. DIRECTORY_SEPARATOR . 'classPathCache.flag';
static public function getRevalidateFlagPath()
{
return self::$_BP . DIRECTORY_SEPARATOR . 'var' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'classPathCache.flag';
}

/**
* Setting cache content
*
* @param array $cache
*/
static public function setCache(array $cache) {
static public function setCache(array $cache)
{
self::$_cache = $cache;
}

Expand All @@ -164,20 +169,21 @@ static public function setCache(array $cache) {
*
* @return array
*/
static public function loadCacheContent() {
static public function loadCacheContent()
{

if (self::isApcUsed()) {
$value = apc_fetch(self::getCacheKey());
if ($value !== FALSE) {
if ($value !== false) {
self::setCache($value);
}
} elseif (file_exists(self::getCacheFilePath())) {
$cacheFilePath = unserialize(file_get_contents(self::getCacheFilePath()));
// If the file is corrupted, it resets cache
if($cacheFilePath === false) {
$cacheFilePath = array();
}
self::setCache($cacheFilePath);
// If the file is corrupted, it resets cache
if ($cacheFilePath === false) {
$cacheFilePath = array();
}
self::setCache($cacheFilePath);
}

if (file_exists(self::getRevalidateFlagPath()) && unlink(self::getRevalidateFlagPath())) {
Expand All @@ -194,9 +200,11 @@ static public function loadCacheContent() {
* Get full path
*
* @param $className
*
* @return mixed
*/
static public function getFullPath($className) {
static public function getFullPath($className)
{
if (!isset(self::$_cache[$className])) {
self::$_cache[$className] = self::searchFullPath(self::getFileFromClassName($className));
// removing the basepath
Expand All @@ -212,6 +220,7 @@ static public function getFullPath($className) {
* Checks if a file exists in the include path and returns the full path if the file exists
*
* @param $filename
*
* @return bool|string
*/
static public function searchFullPath($filename)
Expand Down Expand Up @@ -267,7 +276,7 @@ public function __destruct()
if (PHP_SAPI != 'cli') {
apc_store(self::getCacheKey(), self::$_cache, 0);
}
} elseif(is_dir_writeable(dirname(self::getCacheFilePath()))) {
} elseif (is_dir_writeable(dirname(self::getCacheFilePath()))) {
$fileContent = serialize(self::$_cache);
$tmpFile = tempnam(sys_get_temp_dir(), 'aoe_classpathcache');
if (file_put_contents($tmpFile, $fileContent)) {
Expand Down
41 changes: 0 additions & 41 deletions app/code/local/Aoe/ClassPathCache/etc/config.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<layout>

<adminhtml_cache_index>
<reference name="cache.additional">
<block type="core/template" name="aoe_classpathcache" template="aoe_classpathcache/aoe_classpathcache.phtml" after="-"></block>
</reference>
</adminhtml_cache_index>

</layout>
<?xml version="1.0" encoding="UTF-8"?>
<layout>
<adminhtml_cache_index>
<reference name="cache.additional">
<block type="core/template" name="aoe_classpathcache" template="aoe_classpathcache/aoe_classpathcache.phtml" after="-"/>
</reference>
</adminhtml_cache_index>
</layout>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ $_helper = $this->helper('aoe_classpathcache'); /* @var $_helper Aoe_ClassPathCa
<table class="form-list">
<tr>
<td class="scope-label">
<button onclick="setLocation('<?php echo $_helper->getUrl() ?>')" type="button" class="scalable"><span><span><span><?php echo Mage::helper('adminhtml')->__('Flush Aoe_ClassPathCache') ?></span></span></span></button>
<button onclick="setLocation('<?php echo $_helper->getUrl() ?>')" type="button" class="scalable">
<span><span><span><?php echo Mage::helper('adminhtml')->__('Flush Aoe_ClassPathCache') ?></span></span></span>
</button>
</td>
<td class="scope-label">
<strong><?php echo Mage::helper('adminhtml')->__('Storage:') ?></strong>
Expand All @@ -14,4 +16,4 @@ $_helper = $this->helper('aoe_classpathcache'); /* @var $_helper Aoe_ClassPathCa
<?php echo count(Varien_Autoload::getCache()) ?>
</td>
</tr>
</table>
</table>
Loading

0 comments on commit 38b1af4

Please sign in to comment.