本文整理汇总了PHP中lithium\core\Libraries::cache方法的典型用法代码示例。如果您正苦于以下问题:PHP Libraries::cache方法的具体用法?PHP Libraries::cache怎么用?PHP Libraries::cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lithium\core\Libraries
的用法示例。
在下文中一共展示了Libraries::cache方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
Libraries::cache(false);
$this->classes = array('response' => 'lithium\\tests\\mocks\\console\\MockResponse');
$this->_backup['cwd'] = getcwd();
$this->_backup['_SERVER'] = $_SERVER;
$_SERVER['argv'] = array();
chdir(LITHIUM_LIBRARY_PATH . '/lithium');
$this->request = new Request(array('input' => fopen('php://temp', 'w+')));
$this->request->params = array('library' => 'build_test');
}
示例2: setUp
public function setUp()
{
Libraries::cache(false);
$this->classes = array('response' => 'lithium\\tests\\mocks\\console\\MockResponse');
$this->_backup['cwd'] = getcwd();
$this->_backup['_SERVER'] = $_SERVER;
$_SERVER['argv'] = array();
Libraries::add('create_test', array('path' => $this->_testPath . '/create_test'));
$this->request = new Request(array('input' => fopen('php://temp', 'w+')));
$this->request->params = array('library' => 'create_test');
}
示例3: array
* Lithium: the most rad php framework
*
* @copyright Copyright 2010, Union of RAD (http://union-of-rad.org)
* @license http://opensource.org/licenses/bsd-license.php The BSD License
*/
/**
* This file creates a default cache configuration using the most optimized adapter available, and
* uses it to provide default caching for high-overhead operations.
*/
use lithium\storage\Cache;
use lithium\core\Libraries;
use lithium\action\Dispatcher;
use lithium\storage\cache\adapter\Apc;
/**
* If APC is not available and the cache directory is not writeable, bail out.
*/
if (!($apcEnabled = Apc::enabled() && !is_writable(LITHIUM_APP_PATH . '/resources/tmp/cache'))) {
return;
}
Cache::config(array('default' => array('adapter' => '\\lithium\\storage\\cache\\adapter\\' . ($apcEnabled ? 'Apc' : 'File'))));
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
if ($cache = Cache::read('default', 'core.libraries')) {
$cache = (array) unserialize($cache) + Libraries::cache();
Libraries::cache($cache);
}
$result = $chain->next($self, $params, $chain);
if ($cache != Libraries::cache()) {
Cache::write('default', 'core.libraries', serialize(Libraries::cache()), '+1 day');
}
return $result;
});
示例4: array
* removed post-install, and the cache should be configured with the adapter you plan to use.
*/
$cachePath = Libraries::get(true, 'resources') . '/tmp/cache';
if (!($apcEnabled = Apc::enabled()) && !is_writable($cachePath)) {
return;
}
/**
* This configures the default cache, based on whether ot not APC user caching is enabled. If it is
* not, file caching will be used. Most of this code is for getting you up and running only, and
* should be replaced with a hard-coded configuration, based on the cache(s) you plan to use.
*/
$default = array('adapter' => 'File', 'strategies' => array('Serializer'));
if ($apcEnabled) {
$default = array('adapter' => 'Apc');
}
Cache::config(compact('default'));
/**
* Caches paths for auto-loaded and service-located classes.
*/
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
$key = md5(LITHIUM_APP_PATH) . '.core.libraries';
if ($cache = Cache::read('default', $key)) {
$cache = (array) $cache + Libraries::cache();
Libraries::cache($cache);
}
$result = $chain->next($self, $params, $chain);
if ($cache != Libraries::cache()) {
Cache::write('default', $key, Libraries::cache(), '+1 day');
}
return $result;
});
示例5: function
* 2. Cache describe calls on all connections that use a `Database` based adapter.
*
* @see lithium\core\Environment
* @see lithium\core\Libraries
*/
if (!Environment::is('production')) {
return;
}
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
$cacheKey = 'core.libraries';
if ($cached = Cache::read('default', $cacheKey)) {
$cached = (array) $cached + Libraries::cache();
Libraries::cache($cached);
}
$result = $chain->next($self, $params, $chain);
if ($cached != ($data = Libraries::cache())) {
Cache::write('default', $cacheKey, $data, '+1 day');
}
return $result;
});
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
foreach (Connections::get() as $name) {
if (!($connection = Connections::get($name)) instanceof Database) {
continue;
}
$connection->applyFilter('describe', function ($self, $params, $chain) use($name) {
if ($params['fields']) {
return $chain->next($self, $params, $chain);
}
$cacheKey = "data.connections.{$name}.sources.{$params['entity']}.schema";
return Cache::read('default', $cacheKey, array('write' => function () use($self, $params, $chain) {
示例6: testClassInstanceWithSubnamespace
public function testClassInstanceWithSubnamespace()
{
$testApp = Libraries::get(true, 'resources') . '/tmp/tests/test_app';
mkdir($testApp);
$paths = array("/controllers", "/controllers/admin");
foreach ($paths as $path) {
$namespace = str_replace('/', '\\', $path);
$dotsyntax = str_replace('/', '.', trim($path, '/'));
$class = 'Posts';
Libraries::add('test_app', array('path' => $testApp));
mkdir($testApp . $path, 0777, true);
file_put_contents($testApp . $path . "/{$class}Controller.php", "<?php namespace test_app{$namespace};\n\n\t\t\t\tclass {$class}Controller extends \\lithium\\action\\Controller {\n\t\t\t\tpublic function index() {\n\t\t\t\t\treturn true;\n\t\t\t\t}}");
Libraries::cache(false);
$expected = "test_app{$namespace}\\{$class}Controller";
$instance = Libraries::instance($dotsyntax, "Posts", array('library' => 'test_app'));
$result = get_class($instance);
$this->assertEqual($expected, $result, "{$path} did not work");
}
$this->_cleanUp();
}
示例7: testRunGroupForTestAppModel
public function testRunGroupForTestAppModel()
{
$testApp = Libraries::get(true, 'resources') . '/tmp/tests/test_app';
mkdir($testApp);
Libraries::add('test_app', array('path' => $testApp));
mkdir($testApp . '/tests/cases/models', 0777, true);
file_put_contents($testApp . '/tests/cases/models/UserTest.php', "<?php namespace test_app\\tests\\cases\\models;\n\n\t\t\tclass UserTest extends \\lithium\\test\\Unit { public function testMe() {\n\t\t\t\t\$this->assertTrue(true);\n\t\t\t}}");
Libraries::cache(false);
$group = new Group(array('data' => array('\\test_app\\tests\\cases')));
$expected = array('test_app\\tests\\cases\\models\\UserTest');
$result = $group->to('array');
$this->assertEqual($expected, $result);
$expected = 'pass';
$result = $group->tests()->run();
$this->assertEqual($expected, $result[0][0]['result']);
Libraries::cache(false);
$this->_cleanUp();
}
示例8: testCaseSensitivePathLookups
public function testCaseSensitivePathLookups()
{
Libraries::cache(false);
$library = Libraries::get('lithium');
$base = $library['path'] . '/';
$expected = $base . 'template/view.php';
$result = Libraries::path('\\lithium\\template\\view');
$this->assertEqual($expected, $result);
$result = Libraries::path('lithium\\template\\view');
$this->assertEqual($expected, $result);
$expected = $base . 'template/View.php';
$result = Libraries::path('\\lithium\\template\\View');
$this->assertEqual($expected, $result);
$result = Libraries::path('lithium\\template\\View');
$this->assertEqual($expected, $result);
$expected = $base . 'template/view';
$result = Libraries::path('\\lithium\\template\\view', array('dirs' => true));
$this->assertEqual($expected, $result);
$result = Libraries::path('lithium\\template\\view', array('dirs' => true));
$this->assertEqual($expected, $result);
}
示例9: array
use lithium\storage\Cache;
use lithium\core\Libraries;
use lithium\action\Dispatcher;
use lithium\storage\cache\adapter\Apc;
if (PHP_SAPI === 'cli') {
return;
}
/**
* If APC is not available and the cache directory is not writeable, bail out. This block should be
* removed post-install, and the cache should be configured with the adapter you plan to use.
*/
if (!($apcEnabled = Apc::enabled()) && !is_writable(LITHIUM_APP_PATH . '/resources/tmp/cache')) {
return;
}
if ($apcEnabled) {
$default = array('adapter' => 'lithium\\storage\\cache\\adapter\\Apc');
} else {
$default = array('adapter' => 'lithium\\storage\\cache\\adapter\\File', 'strategies' => array('Serializer'));
}
Cache::config(compact('default'));
Dispatcher::applyFilter('run', function ($self, $params, $chain) {
if ($cache = Cache::read('default', 'core.libraries')) {
$cache = (array) $cache + Libraries::cache();
Libraries::cache($cache);
}
$result = $chain->next($self, $params, $chain);
if ($cache != Libraries::cache()) {
Cache::write('default', 'core.libraries', Libraries::cache(), '+1 day');
}
return $result;
});