/** * Show a list of all defined cache prefixes. * * @return void */ public function listPrefixes() { $prefixes = Cache::configured(); foreach ($prefixes as $prefix) { $this->out($prefix); } }
/** * TinyAuthorize::__construct() * * @param \Cake\Controller\ComponentRegistry $registry * @param array $config * @throws \Cake\Core\Exception\Exception */ public function __construct(ComponentRegistry $registry, array $config = []) { $config += (array) Configure::read('TinyAuth'); $config += $this->_defaultConfig; if (!$config['prefixes'] && !empty($config['authorizeByPrefix'])) { throw new Exception('Invalid TinyAuthorization setup for `authorizeByPrefix`. Please declare `prefixes`.'); } parent::__construct($registry, $config); if (!in_array($config['cache'], Cache::configured())) { throw new Exception(sprintf('Invalid TinyAuthorization cache `%s`', $config['cache'])); } }
/** * Initialize - install cache spies. * * @return void */ public function initialize() { foreach (Cache::configured() as $name) { $config = Cache::config($name); if ($config['className'] instanceof DebugEngine) { $instance = $config['className']; } else { Cache::drop($name); $instance = new DebugEngine($config); Cache::config($name, $instance); } $this->_instances[$name] = $instance; } }
/** * @param array $config * @throws \Cake\Core\Exception\Exception * @return array */ protected function _prepareConfig(array $config) { $config += $this->_defaultConfig(); if (!$config['prefixes'] && !empty($config['authorizeByPrefix'])) { throw new Exception('Invalid TinyAuthorization setup for `authorizeByPrefix`. Please declare `prefixes`.'); } if (!in_array($config['cache'], Cache::configured())) { throw new Exception(sprintf('Invalid TinyAuth cache `%s`', $config['cache'])); } if ($config['autoClearCache'] === null) { $config['autoClearCache'] = Configure::read('debug'); } return $config; }
/** * test that configured returns an array of the currently configured cache * config * * @return void */ public function testConfigured() { Cache::drop('default'); $result = Cache::configured(); $this->assertContains('_cake_core_', $result); $this->assertNotContains('default', $result, 'Unconnected engines should not display.'); }
/** * Get/Set caching. * * @param null|bool|string $cache Cache config name to use, If true is passed, 'cake_pdf' will be used. * @throws \Cake\Core\Exception\Exception * @return mixed */ public function cache($cache = null) { if ($cache === null) { return $this->_cache; } if ($cache === false) { $this->_cache = false; return $this; } if ($cache === true) { $cache = 'cake_pdf'; } if (!in_array($cache, Cache::configured())) { throw new Exception(sprintf('CakePdf cache is not configured: %s', $cache)); } $this->_cache = $cache; return $this; }
use Cake\Datasource\ConnectionManager; $findRoot = function ($root) { do { $lastRoot = $root; $root = dirname($root); if (is_dir($root . '/vendor/cakephp/cakephp')) { return $root; } } while ($root !== $lastRoot); throw new Exception('Cannot find the root of the application, unable to run tests'); }; $root = $findRoot(__FILE__); unset($findRoot); chdir($root); require_once 'vendor/cakephp/cakephp/src/basics.php'; require_once 'vendor/autoload.php'; define('ROOT', $root . DS . 'tests' . DS . 'test_app' . DS); define('APP', ROOT . 'TestApp' . DS); define('TMP', sys_get_temp_dir() . DS); Configure::write('debug', true); Configure::write('App', ['namespace' => 'TestApp', 'paths' => ['plugins' => [ROOT . 'Plugin' . DS]]]); if (!getenv('db_dsn')) { putenv('db_dsn=sqlite:///:memory:'); } ConnectionManager::config('test', ['url' => getenv('db_dsn')]); // Wipe out any accumulated caches before running tests. foreach (\Cake\Cache\Cache::configured() as $key) { \Cake\Cache\Cache::clear(false, $key); echo "Cleared cache: {$key}\n"; } echo PHP_EOL;