public function testEmptyEncryptSaltInitialization() { Configure::consume('App.Encrypt.salt'); $this->setExpectedException('\\Cake\\Core\\Exception\\Exception'); $table = TableRegistry::get('BinaryValues'); $config = ['fields' => ['name' => 'string']]; $cypherBehaviorInstance = new CipherBehavior($table, $config); }
function consume($key, $default = null) { $ret = $default; if (Configure::check($key)) { $ret = Configure::consume($key); } return $ret; }
public function setUp() { parent::setUp(); $this->__resetAppConfig = Configure::read('App'); Configure::write('App.www_root', dirname(dirname(dirname(__DIR__))) . DS . 'test_app' . DS . 'webroot' . DS); $this->__resetAsseticConfig = Configure::consume('Assetic'); // Configure::write('Assetic', ['cssGroups' => ['main' => ['cake.group']]]); $view = $this->getMock('Cake\\View\\View', array('append')); $this->Assetic = new AsseticHelper($view); }
/** * startup callback * * @param \Cake\Event\Event $event Event. * * @return void */ public function startup(Event $event) { $secret = Configure::consume('Recaptcha.secret'); // throw an exception if the secret is not defined in config/recaptcha.php file if (empty($secret)) { throw new Exception(__d('recaptcha', "You must set the secret Recaptcha key in config/recaptcha.php file")); } // instantiate Recaptcha object that deals with retrieving data from google recaptcha $this->recaptcha = new Recaptcha(new RecaptchaResponse(), $secret); $controller = $event->subject(); $this->setController($controller); }
/** * Called after the Controller::beforeRender(), after the view class is loaded, and before the * Controller::render() * * @param \Cake\Event\Event $event * @return \Cake\Network\Response|null|void */ public function beforeRender(Event $event) { if (!$this->Controller->request->is('ajax')) { return; } $headerKey = $this->config('headerKey'); if (!$headerKey) { return; } $ajaxMessages = array_merge((array) $this->Controller->request->session()->consume('FlashMessage'), (array) Configure::consume('FlashMessage')); // The header can be read with JavaScript and a custom Message can be displayed $this->Controller->response->header($headerKey, json_encode($ajaxMessages)); }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); //データベース接続設定 $connectionInfo = self::$_connectionInfo; //cacheの設定はしていないためcacheを無効にする Cache::disable(); //defaultは使わないがいないとエラーになるのでテストと同じものを設定する Configure::write('Datasources.default', $connectionInfo); Configure::write('Datasources.test', $connectionInfo); ConnectionManager::config(Configure::consume('Datasources')); //APPが定義されていないとエラーになるため。(逆に何か設定してあればとりあえず動くみたい?) if (!defined('APP')) { define('APP', self::$_appInfo); } }
/** * testConsumeEmpty * * @return void */ public function testConsumeEmpty() { Configure::write('Test', ['key' => 'value', 'key2' => 'value2']); $result = Configure::consume(''); $this->assertNull($result); $result = Configure::consume(null); $this->assertNull($result); }
if (!Configure::read('App.fullBaseUrl')) { $s = null; if (env('HTTPS')) { $s = 's'; } $httpHost = env('HTTP_HOST'); if (isset($httpHost)) { Configure::write('App.fullBaseUrl', 'http' . $s . '://' . $httpHost); } unset($httpHost, $s); } Cache::config(Configure::consume('Cache')); ConnectionManager::config(Configure::consume('Datasources')); Email::configTransport(Configure::consume('EmailTransport')); Email::config(Configure::consume('Email')); Log::config(Configure::consume('Log')); /** * Setup detectors for mobile and tablet. */ Request::addDetector('mobile', function ($request) { $detector = new \Detection\MobileDetect(); return $detector->isMobile(); }); Request::addDetector('tablet', function ($request) { $detector = new \Detection\MobileDetect(); return $detector->isTablet(); }); /** * Custom Inflector rules, can be set to correctly pluralize or singularize table, model, controller names or whatever other * string is passed to the inflection functions *
*/ //Inflector::rules('plural', ['/^(inflect)or$/i' => '\1ables']); //Inflector::rules('irregular', ['red' => 'redlings']); //Inflector::rules('uninflected', ['dontinflectme']); //Inflector::rules('transliteration', ['/å/' => 'aa']); /* * Plugins need to be loaded manually, you can either load them one by one or all of them in a single call * Uncomment one of the lines below, as you need. make sure you read the documentation on Plugin to use more * advanced ways of loading plugins * * Plugin::loadAll(); // Loads all plugins at once * Plugin::load('Migrations'); //Loads a single plugin named Migrations * */ /* * Only try to load DebugKit in development mode * Debug Kit should not be installed on a production system */ if (Configure::read('debug')) { Plugin::load('DebugKit', ['bootstrap' => true]); } // Handle the CakeQueuesadilla Plugin::load('Josegonzalez/CakeQueuesadilla'); \Josegonzalez\CakeQueuesadilla\Queue\Queue::config(Configure::consume('Queuesadilla')); Plugin::load('AssetCompress', ['bootstrap' => true]); Plugin::load('BootstrapUI'); Plugin::load('Crud'); Plugin::load('CrudView'); Plugin::load('Josegonzalez/Upload'); Plugin::load('Migrations'); Plugin::load('Search');
$s = null; if (env('HTTPS')) { $s = 's'; } $httpHost = env('HTTP_HOST'); if (isset($httpHost)) { Configure::write('App.fullBaseUrl', 'http' . $s . '://' . $httpHost); } unset($httpHost, $s); } Cache::config(Configure::consume('Cache')); ConnectionManager::config(Configure::consume('Datasources')); Email::configTransport(Configure::consume('EmailTransport')); Email::config(Configure::consume('Email')); Log::config(Configure::consume('Log')); Security::salt(Configure::consume('Security.salt')); /** * The default crypto extension in 3.0 is OpenSSL. * If you are migrating from 2.x uncomment this code to * use a more compatible Mcrypt based implementation */ // Security::engine(new \Cake\Utility\Crypto\Mcrypt()); /** * Setup detectors for mobile and tablet. */ Request::addDetector('mobile', function ($request) { $detector = new \Detection\MobileDetect(); return $detector->isMobile(); }); Request::addDetector('tablet', function ($request) { $detector = new \Detection\MobileDetect();
/** * test that default profile is used by constructor if available. * * @return void */ public function testDefaultProfile() { $config = ['test' => 'ok', 'test2' => true]; Configure::write('Email.default', $config); Email::config(Configure::consume('Email')); $Email = new Email(); $this->assertSame($Email->profile(), $config); Configure::delete('Email'); Email::drop('default'); }
<?php // file: bootstrap.php // date: 2016-01-12 // author: Michael Leßnau <*****@*****.**> use Cake\Core\Configure; use Cake\Datasource\ConnectionManager; require __DIR__ . '/../vendor/autoload.php'; Configure::write('Datasources', ['default' => ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Sqlite', 'database' => __DIR__ . '/default.sqlite', 'encoding' => 'utf8', 'timezone' => 'UTC', 'cacheMetadata' => false, 'log' => false], 'test' => ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Sqlite', 'database' => __DIR__ . '/test.sqlite', 'encoding' => 'utf8', 'timezone' => 'UTC', 'cacheMetadata' => false, 'log' => false]]); ConnectionManager::config(Configure::consume('Datasources'));
/** * Reads and deletes a variable from Configure. * * @param string $name The key to read and remove (or a path as sent to Hash.extract). * @return mixed The value of the Configure variable, null if not available */ public function consume($name) { return Configure::consume($name); }
<?php use Cake\Core\Configure; use Cake\Cache\Cache; use PipingBag\Di\PipingBag; use Doctrine\Common\Annotations\AnnotationRegistry; use Doctrine\Common\Annotations\AnnotationReader; $config = Configure::consume('PipingBag'); $modules = !empty($config['modules']) ? $config['modules'] : []; $cache = isset($config['cacheConfig']) ? $config['cacheConfig'] : 'default'; AnnotationReader::addGlobalIgnoredName('triggers'); AnnotationRegistry::registerFile(dirname(__DIR__) . '/src/Annotation/Assisted.php'); $instance = Cache::read('pipingbag.instance', $cache); if (!$instance) { $instance = PipingBag::create($modules); } PipingBag::container($instance); register_shutdown_function(function () use($instance, $cache) { Cache::write('pipingbag.instance', $instance, $cache); });
<?php /** * MultiTenant Plugin * Copyright (c) PRONIQUE Software (http://pronique.com) * * Licensed under The MIT License * For full copyright and license information, please see the LICENSE.txt * Redistributions of files must retain the above copyright notice. * * @copyright Copyright (c) PRONIQUE Software (http://pronique.com) * @link http://github.com/pronique/multitenant MultiTenant Plugin Project * @since 0.5.1 * @license http://www.opensource.org/licenses/mit-license.php MIT License */ namespace MultiTenant\Config; use MultiTenant\Core\MTApp; use Cake\Configure\Engine\PhpConfig; use Cake\Core\Configure; MTApp::config(Configure::consume('MultiTenant'));
<?php use Cake\Core\Configure; use CvoTechnologies\Notifier\Notification; Notification::configTransport(Configure::consume('NotificationTransport')); Notification::config(Configure::consume('Notification'));
<?php use Cake\Core\Configure; use RochaMarcelo\CakePimpleDi\Di\Di; $config = Configure::consume('CakePimpleDi'); $scopes = []; if (!isset($config['scopes'])) { $scopes = ['default' => (array) $config]; } foreach ($scopes as $name => $config) { $Di = Di::instance($name); $config = $config + ['providers' => []]; foreach ($config['providers'] as $provider) { if (is_string($provider)) { $provider = new $provider(); } $Di->register($provider); } if (isset($config['services']) && is_array($config['services'])) { $Di->setMany($config['services']); } }
* @copyright Copyright (c) Frank Förster (http://frankfoerster.com) * @license http://www.opensource.org/licenses/mit-license.php MIT License */ use Cake\Cache\Cache; use Cake\Core\Configure; use Cake\Core\Plugin; use Cake\Event\EventManager; use Cake\Filesystem\Folder; use Wasabi\Cms\Event\DispatcherListener; use Wasabi\Cms\Event\MenuListener; use Wasabi\Cms\Event\RouteListener; use Wasabi\Cms\Event\ThemeListener; use Wasabi\Cms\View\Module\ModuleManager; try { // Load and apply the Wasabi Core cache config. Configure::load('Wasabi/Cms.cache', 'default'); foreach (Configure::consume('Cache') as $key => $config) { new Folder($config['path'], true, 0775); Cache::config($key, $config); } } catch (\Exception $e) { die($e->getMessage() . "\n"); } // Configure plugin translation paths. Configure::write('App.paths.locales', array_merge(Configure::read('App.paths.locales'), [Plugin::path('Wasabi/Cms') . 'src' . DS . 'Locale' . DS])); // Register module path. ModuleManager::registerModulePath(Plugin::path('Wasabi/Cms') . 'src' . DS . 'View' . DS . 'Module' . DS); EventManager::instance()->on(new RouteListener()); EventManager::instance()->on(new ThemeListener()); EventManager::instance()->on(new DispatcherListener()); EventManager::instance()->on(new MenuListener());
/** * test that default profile is used by constructor if available. * * @return void */ public function testDefaultProfile() { $config = ['test' => 'ok', 'test2' => true]; Configure::write('Notification.default', $config); Notification::config(Configure::consume('Notification')); $Notification = new Notification(); $this->assertSame($Notification->profile(), $config); Configure::delete('Notification'); Notification::drop('default'); }
$loader->addNamespace('App', APP); //@codingStandardsIgnoreStart @mkdir(LOGS); @mkdir(SESSIONS); @mkdir(CACHE); @mkdir(CACHE . 'views'); @mkdir(CACHE . 'models'); //@codingStandardsIgnoreEnd require_once CORE_PATH . 'config/bootstrap.php'; date_default_timezone_set('UTC'); mb_internal_encoding('UTF-8'); Configure::write('debug', true); Configure::write('App', ['namespace' => 'App', 'encoding' => 'UTF-8', 'base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => 'webroot', 'wwwRoot' => WWW_ROOT, 'fullBaseUrl' => 'http://localhost', 'imageBaseUrl' => 'img/', 'jsBaseUrl' => 'js/', 'cssBaseUrl' => 'css/', 'paths' => ['plugins' => [TEST_APP . 'Plugin' . DS], 'templates' => [APP . 'Template' . DS], 'locales' => [APP . 'Locale' . DS]]]); Cache::config(['_cake_core_' => ['engine' => 'File', 'prefix' => 'cake_core_', 'serialize' => true], '_cake_model_' => ['engine' => 'File', 'prefix' => 'cake_model_', 'serialize' => true]]); // Ensure default test connection is defined if (!getenv('db_dsn')) { putenv('db_dsn=sqlite:///:memory:'); } ConnectionManager::config('test', ['url' => getenv('db_dsn')]); ConnectionManager::config('test_custom_i18n_datasource', ['url' => getenv('db_dsn')]); Configure::write('Session', ['defaults' => 'php']); Configure::write('EmailTransport', ['default' => ['className' => 'Debug']]); Configure::write('Email', ['default' => ['transport' => 'default', 'from' => 'you@localhost']]); Email::configTransport(Configure::consume('EmailTransport')); Email::config(Configure::consume('Email')); Log::config(['debug' => ['engine' => 'Cake\\Log\\Engine\\FileLog', 'levels' => ['notice', 'info', 'debug'], 'file' => 'debug'], 'error' => ['engine' => 'Cake\\Log\\Engine\\FileLog', 'levels' => ['warning', 'error', 'critical', 'alert', 'emergency'], 'file' => 'error']]); Router::reload(); Cake\Routing\DispatcherFactory::add('Routing'); Cake\Routing\DispatcherFactory::add('ControllerFactory'); Plugin::load('Users', ['path' => ROOT . DS, 'routes' => true]); Cake\Utility\Security::salt('8b61f851d8cb3dfcf3b447dc67bd7bf9fe2ed91a916d4457f4969a05a637473d');
/** * Test the consume method. * * @return void */ public function testConsume() { $this->assertNull(Configure::consume('DoesNotExist'), 'Should be null on empty value'); Configure::write('Test', ['key' => 'value', 'key2' => 'value2']); $result = Configure::consume('Test.key'); $this->assertEquals('value', $result); $result = Configure::read('Test.key2'); $this->assertEquals('value2', $result, 'Other values should remain.'); $result = Configure::consume('Test'); $expected = ['key2' => 'value2']; $this->assertEquals($expected, $result); }