Merge remote-tracking branch 'origin/2.0' into 2.0-class-loading

This commit is contained in:
Jose Lorenzo Rodriguez 2011-03-12 23:49:02 -04:30
commit 0cd51de827
9 changed files with 169 additions and 167 deletions

View file

@ -1,9 +1,12 @@
<?php
/**
* This file is loaded automatically by the app/webroot/index.php file after the core bootstrap.php
* This file is loaded automatically by the app/webroot/index.php file after core.php
*
* This is an application wide file to load any function that is not used within a class
* define. You can also use this to include or require any files in your application.
* This file should load/create any application wide configuration settings, such as
* Caching, Logging, loading additional configuration files.
*
* You should also use this file to include any files that provide global functions/constants
* that your application uses.
*
* PHP 5
*
@ -20,6 +23,9 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
// Setup a 'default' cache configuration for use in the application.
Cache::config('default', array('engine' => 'File'));
/**
* The settings below can be used to set additional paths to models, views and controllers.
* This is related to Ticket #470 (https://trac.cakephp.org/ticket/470)

View file

@ -283,4 +283,40 @@
* ));
*
*/
Cache::config('default', array('engine' => 'File'));
// Pick the caching engine to use. If APC is enabled use it.
$engine = 'File';
if (extension_loaded('apc')) {
$engine = 'Apc';
}
// In development mode, caches should expire quickly.
$duration = '+999 days';
if (Configure::read('debug') >= 1) {
$duration = '+10 seconds';
}
/**
* Configure the cache used for general framework caching. Path information,
* object listings, and translation cache files are stored with this configuration.
*/
Cache::config('_cake_core_', array(
'engine' => $engine,
'prefix' => 'cake_core_',
'path' => CACHE . 'persistent' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration
));
/**
* Configure the cache for model, and datasource caches. This cache configuration
* is used to store schema descriptions, and table listings in connections.
*/
Cache::config('_cake_model_', array(
'engine' => $engine,
'prefix' => 'cake_model_',
'path' => CACHE . 'models' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration
));

View file

@ -73,14 +73,24 @@ class Cache {
* both create new configurations, return the settings for already configured
* configurations.
*
* To create a new configuration:
* To create a new configuration, or to modify an existing configuration permanently:
*
* `Cache::config('my_config', array('engine' => 'File', 'path' => TMP));`
*
* To get the settings for a configuration, and set it as the currently selected configuration
* If you need to modify a configuration temporarily, use Cache::set().
* To get the settings for a configuration:
*
* `Cache::config('default');`
*
* There are 4 built-in caching engines:
*
* - `FileEngine` - Uses simple files to store content. Poor performance, but good for
* storing large objects, or things that are not IO sensitive.
* - `ApcEngine` - Uses the APC object cache, one of the fastest caching engines.
* - `MemcacheEngine` - Uses the PECL::Memcache extension and Memcached for storage.
* Fast reads/writes, and benefits from memcache being distributed.
* - `XcacheEngine` - Uses the Xcache extension, an alternative to APC.
*
* @see app/config/core.php for configuration settings
* @param string $name Name of the configuration
* @param array $settings Optional associative array of settings passed to the engine

View file

@ -1,7 +1,10 @@
<?php
/**
* File Storage engine for cache
* File Storage engine for cache. Filestorage is the slowest cache storage
* to read and write. However, it is good for servers that don't have other storage
* engine available, or have content which is not performance sensitive.
*
* You can configure a FileEngine cache, using Cache::config()
*
* PHP 5
*
@ -13,7 +16,6 @@
*
* @copyright Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @package cake.libs.cache
* @since CakePHP(tm) v 1.2.0.4933
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
@ -21,7 +23,6 @@
/**
* File Storage engine for cache
*
* @todo use the File and Folder classes (if it's not a too big performance hit)
* @package cake.libs.cache
*/
class FileEngine extends CacheEngine {

View file

@ -1,9 +1,12 @@
<?php
/**
* This file is loaded automatically by the app/webroot/index.php file after the core bootstrap.php
* This file is loaded automatically by the app/webroot/index.php file after core.php
*
* This is an application wide file to load any function that is not used within a class
* define. You can also use this to include or require any files in your application.
* This file should load/create any application wide configuration settings, such as
* Caching, Logging, loading additional configuration files.
*
* You should also use this file to include any files that provide global functions/constants
* that your application uses.
*
* PHP 5
*
@ -20,6 +23,9 @@
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
// Setup a 'default' cache configuration for use in the application.
Cache::config('default', array('engine' => 'File'));
/**
* The settings below can be used to set additional paths to models, views and controllers.
* This is related to Ticket #470 (https://trac.cakephp.org/ticket/470)
@ -28,7 +34,7 @@
* 'plugins' => array('/full/path/to/plugins/', '/next/full/path/to/plugins/'),
* 'models' => array('/full/path/to/models/', '/next/full/path/to/models/'),
* 'views' => array('/full/path/to/views/', '/next/full/path/to/views/'),
* 'controllers' => array(/full/path/to/controllers/', '/next/full/path/to/controllers/'),
* 'controllers' => array('/full/path/to/controllers/', '/next/full/path/to/controllers/'),
* 'datasources' => array('/full/path/to/datasources/', '/next/full/path/to/datasources/'),
* 'behaviors' => array('/full/path/to/behaviors/', '/next/full/path/to/behaviors/'),
* 'components' => array('/full/path/to/components/', '/next/full/path/to/components/'),

View file

@ -283,4 +283,40 @@
* ));
*
*/
Cache::config('default', array('engine' => 'File'));
// Pick the caching engine to use. If APC is enabled use it.
$engine = 'File';
if (extension_loaded('apc')) {
$engine = 'Apc';
}
// In development mode, caches should expire quickly.
$duration = '+999 days';
if (Configure::read('debug') >= 1) {
$duration = '+10 seconds';
}
/**
* Configure the cache used for general framework caching. Path information,
* object listings, and translation cache files are stored with this configuration.
*/
Cache::config('_cake_core_', array(
'engine' => $engine,
'prefix' => 'cake_core_',
'path' => CACHE . 'persistent' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration
));
/**
* Configure the cache for model, and datasource caches. This cache configuration
* is used to store schema descriptions, and table listings in connections.
*/
Cache::config('_cake_model_', array(
'engine' => $engine,
'prefix' => 'cake_model_',
'path' => CACHE . 'models' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration
));

View file

@ -186,7 +186,7 @@ class SecurityComponent extends Component {
*/
public function startup($controller) {
$this->request = $controller->request;
$this->_action = strtolower($this->request->params['action']);
$this->_action = $this->request->params['action'];
$this->_methodsRequired($controller);
$this->_secureRequired($controller);
$this->_authRequired($controller);
@ -321,10 +321,10 @@ class SecurityComponent extends Component {
foreach (array('Post', 'Get', 'Put', 'Delete') as $method) {
$property = 'require' . $method;
if (is_array($this->$property) && !empty($this->$property)) {
$require = array_map('strtolower', $this->$property);
$require = $this->$property;
if (in_array($this->_action, $require) || $this->$property == array('*')) {
if (!$this->request->is(strtolower($method))) {
if (!$this->blackHole($controller, strtolower($method))) {
if (!$this->request->is($method)) {
if (!$this->blackHole($controller, $method)) {
return null;
}
}
@ -342,7 +342,7 @@ class SecurityComponent extends Component {
*/
protected function _secureRequired($controller) {
if (is_array($this->requireSecure) && !empty($this->requireSecure)) {
$requireSecure = array_map('strtolower', $this->requireSecure);
$requireSecure = $this->requireSecure;
if (in_array($this->_action, $requireSecure) || $this->requireSecure == array('*')) {
if (!$this->request->is('ssl')) {
@ -363,7 +363,7 @@ class SecurityComponent extends Component {
*/
protected function _authRequired($controller) {
if (is_array($this->requireAuth) && !empty($this->requireAuth) && !empty($this->request->data)) {
$requireAuth = array_map('strtolower', $this->requireAuth);
$requireAuth = $this->requireAuth;
if (in_array($this->request->params['action'], $requireAuth) || $this->requireAuth == array('*')) {
if (!isset($controller->request->data['_Token'] )) {

View file

@ -73,43 +73,6 @@ class Configure {
trigger_error(__("Can't find application core file. Please create %score.php, and make sure it is readable by PHP.", CONFIGS), E_USER_ERROR);
}
if (empty(self::$_values['Cache']['disable'])) {
$cache = Cache::config('default');
if (empty($cache['settings'])) {
trigger_error(__('Cache not configured properly. Please check Cache::config(); in APP/config/core.php'), E_USER_WARNING);
$cache = Cache::config('default', array('engine' => 'File'));
}
$path = $prefix = $duration = null;
if (!empty($cache['settings']['path'])) {
$path = realpath($cache['settings']['path']);
} else {
$prefix = $cache['settings']['prefix'];
}
if (self::$_values['debug'] >= 1) {
$duration = '+10 seconds';
} else {
$duration = '+999 days';
}
$cacheConfigs = Cache::configured();
if (!in_array('_cake_core_', $cacheConfigs)) {
Cache::config('_cake_core_', array_merge((array)$cache['settings'], array(
'prefix' => $prefix . 'cake_core_', 'path' => $path . DS . 'persistent' . DS,
'serialize' => true, 'duration' => $duration
)));
}
if (!in_array('_cake_model_', $cacheConfigs)) {
Cache::config('_cake_model_', array_merge((array)$cache['settings'], array(
'prefix' => $prefix . 'cake_model_', 'path' => $path . DS . 'models' . DS,
'serialize' => true, 'duration' => $duration
)));
}
}
App::init();
App::build();
if (!include(CONFIGS . 'bootstrap.php')) {

View file

@ -41,10 +41,9 @@ class FileEngineTest extends CakeTestCase {
* @return void
*/
function setUp() {
$this->_cacheDisable = Configure::read('Cache.disable');
$this->_cacheConfig = Cache::config('default');
parent::setUp();
Configure::write('Cache.disable', false);
Cache::config('default', array('engine' => 'File', 'path' => CACHE));
Cache::config('file_test', array('engine' => 'File', 'path' => CACHE));
}
/**
@ -54,9 +53,9 @@ class FileEngineTest extends CakeTestCase {
* @return void
*/
function tearDown() {
Cache::clear(false, 'default');
Configure::write('Cache.disable', $this->_cacheDisable);
Cache::config('default', $this->_cacheConfig['settings']);
parent::tearDown();
Cache::clear(false, 'file_test');
Cache::drop('file_test');
}
/**
@ -83,24 +82,24 @@ class FileEngineTest extends CakeTestCase {
function testReadAndWriteCache() {
Cache::config('default');
$result = Cache::write(null, 'here');
$result = Cache::write(null, 'here', 'file_test');
$this->assertFalse($result);
Cache::set(array('duration' => 1));
Cache::set(array('duration' => 1), 'file_test');
$result = Cache::read('test');
$result = Cache::read('test', 'file_test');
$expecting = '';
$this->assertEqual($result, $expecting);
$data = 'this is a test of the emergency broadcasting system';
$result = Cache::write('test', $data);
$result = Cache::write('test', $data, 'file_test');
$this->assertTrue(file_exists(CACHE . 'cake_test'));
$result = Cache::read('test');
$result = Cache::read('test', 'file_test');
$expecting = $data;
$this->assertEqual($result, $expecting);
Cache::delete('test');
Cache::delete('test', 'file_test');
}
/**
@ -110,27 +109,27 @@ class FileEngineTest extends CakeTestCase {
* @return void
*/
function testExpiry() {
Cache::set(array('duration' => 1));
Cache::set(array('duration' => 1), 'file_test');
$result = Cache::read('test');
$result = Cache::read('test', 'file_test');
$this->assertFalse($result);
$data = 'this is a test of the emergency broadcasting system';
$result = Cache::write('other_test', $data);
$result = Cache::write('other_test', $data, 'file_test');
$this->assertTrue($result);
sleep(2);
$result = Cache::read('other_test');
$result = Cache::read('other_test', 'file_test');
$this->assertFalse($result);
Cache::set(array('duration' => "+1 second"));
Cache::set(array('duration' => "+1 second"), 'file_test');
$data = 'this is a test of the emergency broadcasting system';
$result = Cache::write('other_test', $data);
$result = Cache::write('other_test', $data, 'file_test');
$this->assertTrue($result);
sleep(2);
$result = Cache::read('other_test');
$result = Cache::read('other_test', 'file_test');
$this->assertFalse($result);
}
@ -142,14 +141,14 @@ class FileEngineTest extends CakeTestCase {
*/
function testDeleteCache() {
$data = 'this is a test of the emergency broadcasting system';
$result = Cache::write('delete_test', $data);
$result = Cache::write('delete_test', $data, 'file_test');
$this->assertTrue($result);
$result = Cache::delete('delete_test');
$result = Cache::delete('delete_test', 'file_test');
$this->assertTrue($result);
$this->assertFalse(file_exists(TMP . 'tests' . DS . 'delete_test'));
$result = Cache::delete('delete_test');
$result = Cache::delete('delete_test', 'file_test');
$this->assertFalse($result);
}
@ -160,17 +159,17 @@ class FileEngineTest extends CakeTestCase {
* @return void
*/
function testSerialize() {
Cache::config('default', array('engine' => 'File', 'serialize' => true));
Cache::config('file_test', array('engine' => 'File', 'serialize' => true));
$data = 'this is a test of the emergency broadcasting system';
$write = Cache::write('serialize_test', $data);
$write = Cache::write('serialize_test', $data, 'file_test');
$this->assertTrue($write);
Cache::config('default', array('serialize' => false));
$read = Cache::read('serialize_test');
Cache::config('file_test', array('serialize' => false));
$read = Cache::read('serialize_test', 'file_test');
$newread = Cache::read('serialize_test');
$newread = Cache::read('serialize_test', 'file_test');
$delete = Cache::delete('serialize_test');
$delete = Cache::delete('serialize_test', 'file_test');
$this->assertIdentical($read, serialize($data));
@ -184,91 +183,35 @@ class FileEngineTest extends CakeTestCase {
* @return void
*/
function testClear() {
Cache::config('default', array('engine' => 'File', 'duration' => 1));
Cache::config('file_test', array('engine' => 'File', 'duration' => 1));
$data = 'this is a test of the emergency broadcasting system';
$write = Cache::write('serialize_test1', $data);
$write = Cache::write('serialize_test2', $data);
$write = Cache::write('serialize_test3', $data);
$write = Cache::write('serialize_test1', $data, 'file_test');
$write = Cache::write('serialize_test2', $data, 'file_test');
$write = Cache::write('serialize_test3', $data, 'file_test');
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test1'));
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test2'));
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test3'));
sleep(2);
$result = Cache::clear(true);
$result = Cache::clear(true, 'file_test');
$this->assertTrue($result);
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test1'));
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test2'));
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test3'));
$data = 'this is a test of the emergency broadcasting system';
$write = Cache::write('serialize_test1', $data);
$write = Cache::write('serialize_test2', $data);
$write = Cache::write('serialize_test3', $data);
$write = Cache::write('serialize_test1', $data, 'file_test');
$write = Cache::write('serialize_test2', $data, 'file_test');
$write = Cache::write('serialize_test3', $data, 'file_test');
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test1'));
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test2'));
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test3'));
$result = Cache::clear();
$result = Cache::clear(false, 'file_test');
$this->assertTrue($result);
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test1'));
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test2'));
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test3'));
Cache::config('default', array('engine' => 'File', 'path' => CACHE . 'views' . DS));
$data = 'this is a test of the emergency broadcasting system';
$write = Cache::write('controller_view_1', $data);
$write = Cache::write('controller_view_2', $data);
$write = Cache::write('controller_view_3', $data);
$write = Cache::write('controller_view_10', $data);
$write = Cache::write('controller_view_11', $data);
$write = Cache::write('controller_view_12', $data);
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_1'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_2'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_3'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_10'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_11'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_12'));
clearCache('controller_view_1', 'views', '');
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_1'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_2'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_3'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_10'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_11'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_12'));
clearCache('controller_view', 'views', '');
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_1'));
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_2'));
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_3'));
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_10'));
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_11'));
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_12'));
$write = Cache::write('controller_view_1', $data);
$write = Cache::write('controller_view_2', $data);
$write = Cache::write('controller_view_3', $data);
$write = Cache::write('controller_view_10', $data);
$write = Cache::write('controller_view_11', $data);
$write = Cache::write('controller_view_12', $data);
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_1'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_2'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_3'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_10'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_11'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_12'));
clearCache(array('controller_view_2', 'controller_view_11', 'controller_view_12'), 'views', '');
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_1'));
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_2'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_3'));
$this->assertTrue(file_exists(CACHE . 'views'. DS . 'cake_controller_view_10'));
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_11'));
$this->assertFalse(file_exists(CACHE . 'views'. DS . 'cake_controller_view_12'));
clearCache('controller_view');
Cache::config('default', array('engine' => 'File', 'path' => CACHE));
}
/**
@ -289,14 +232,15 @@ class FileEngineTest extends CakeTestCase {
));
$data1 = $data2 = $expected = 'content to cache';
$FileOne->write('key_one', $data1, DAY);
$FileTwo->write('key_two', $data2, DAY);
$FileOne->write('prefix_one_key_one', $data1, DAY);
$FileTwo->write('prefix_two_key_two', $data2, DAY);
$this->assertEqual($FileOne->read('key_one'), $expected);
$this->assertEqual($FileTwo->read('key_two'), $expected);
$this->assertEqual($FileOne->read('prefix_one_key_one'), $expected);
$this->assertEqual($FileTwo->read('prefix_two_key_two'), $expected);
$FileOne->clear(false);
$this->assertEqual($FileTwo->read('key_two'), $expected, 'secondary config was cleared by accident.');
$this->assertEqual($FileTwo->read('prefix_two_key_two'), $expected, 'secondary config was cleared by accident.');
$FileTwo->clear(false);
}
/**
@ -306,11 +250,11 @@ class FileEngineTest extends CakeTestCase {
* @return void
*/
function testKeyPath() {
$result = Cache::write('views.countries.something', 'here');
$result = Cache::write('views.countries.something', 'here', 'file_test');
$this->assertTrue($result);
$this->assertTrue(file_exists(CACHE . 'cake_views_countries_something'));
$result = Cache::read('views.countries.something');
$result = Cache::read('views.countries.something', 'file_test');
$this->assertEqual($result, 'here');
$result = Cache::clear();
@ -370,16 +314,16 @@ class FileEngineTest extends CakeTestCase {
* @return void
*/
function testWriteQuotedString() {
Cache::config('default', array('engine' => 'File', 'path' => TMP . 'tests'));
Cache::write('App.doubleQuoteTest', '"this is a quoted string"');
$this->assertIdentical(Cache::read('App.doubleQuoteTest'), '"this is a quoted string"');
Cache::write('App.singleQuoteTest', "'this is a quoted string'");
$this->assertIdentical(Cache::read('App.singleQuoteTest'), "'this is a quoted string'");
Cache::config('file_test', array('engine' => 'File', 'path' => TMP . 'tests'));
Cache::write('App.doubleQuoteTest', '"this is a quoted string"', 'file_test');
$this->assertIdentical(Cache::read('App.doubleQuoteTest', 'file_test'), '"this is a quoted string"');
Cache::write('App.singleQuoteTest', "'this is a quoted string'", 'file_test');
$this->assertIdentical(Cache::read('App.singleQuoteTest', 'file_test'), "'this is a quoted string'");
Cache::config('default', array('isWindows' => true, 'path' => TMP . 'tests'));
$this->assertIdentical(Cache::read('App.doubleQuoteTest'), '"this is a quoted string"');
Cache::write('App.singleQuoteTest', "'this is a quoted string'");
$this->assertIdentical(Cache::read('App.singleQuoteTest'), "'this is a quoted string'");
Cache::config('file_test', array('isWindows' => true, 'path' => TMP . 'tests'));
$this->assertIdentical(Cache::read('App.doubleQuoteTest', 'file_test'), '"this is a quoted string"');
Cache::write('App.singleQuoteTest', "'this is a quoted string'", 'file_test');
$this->assertIdentical(Cache::read('App.singleQuoteTest', 'file_test'), "'this is a quoted string'");
}
/**