/** * Tests that connecting with invalid credentials or database name throws an exception * * @expectedException \Cake\Database\Exception\MissingConnectionException * @return void */ public function testWrongCredentials() { $config = ConnectionManager::config('test'); $this->skipIf(isset($config['url']), 'Datasource has dsn, skipping.'); $connection = new Connection(['database' => '/dev/nonexistent'] + ConnectionManager::config('test')); $connection->connect(); }
/** * Set up some fake datasources and security salt **once** before all tests. * * @return void * @see ::testMainSpecialKeys() */ public static function setUpBeforeClass() { // Prime the ConnectionManager with some configs. \Cake\Datasource\ConnectionManager::config(self::$datasources); // Prime the security salt. \Cake\Utility\Security::salt(self::$salt); }
/** * Overrides the original method from phinx in order to return a tailored * Config object containing the connection details for the database. * * @return Phinx\Config\Config */ public function getConfig() { if ($this->configuration) { return $this->configuration; } $folder = 'Migrations'; if ($this->input->getOption('source')) { $folder = $this->input->getOption('source'); } $dir = ROOT . DS . 'config' . DS . $folder; $plugin = null; if ($this->input->getOption('plugin')) { $plugin = $this->input->getOption('plugin'); $dir = Plugin::path($plugin) . 'config' . DS . $folder; } if (!is_dir($dir)) { mkdir($dir, 0777, true); } $plugin = $plugin ? Inflector::underscore($plugin) . '_' : ''; $plugin = str_replace(array('\\', '/', '.'), '_', $plugin); $connection = 'default'; if ($this->input->getOption('connection')) { $connection = $this->input->getOption('connection'); } $config = ConnectionManager::config($connection); return $this->configuration = new Config(['paths' => ['migrations' => $dir], 'environments' => ['default_migration_table' => $plugin . 'phinxlog', 'default_database' => 'default', 'default' => ['adapter' => $this->getAdapterName($config['driver']), 'host' => isset($config['host']) ? $config['host'] : null, 'user' => isset($config['username']) ? $config['username'] : null, 'pass' => isset($config['password']) ? $config['password'] : null, 'port' => isset($config['port']) ? $config['port'] : null, 'name' => $config['database'], 'charset' => $config['encoding']]]]); }
/** * Overrides the original method from phinx in order to return a tailored * Config object containing the connection details for the database. * * @param bool $forceRefresh * @return \Phinx\Config\Config */ public function getConfig($forceRefresh = false) { if ($this->configuration && $forceRefresh === false) { return $this->configuration; } $folder = 'Migrations'; if ($this->input->getOption('source')) { $folder = $this->input->getOption('source'); } $dir = ROOT . DS . 'config' . DS . $folder; $plugin = null; if ($this->input->getOption('plugin')) { $plugin = $this->input->getOption('plugin'); $dir = Plugin::path($plugin) . 'config' . DS . $folder; } if (!is_dir($dir)) { mkdir($dir, 0777, true); } $plugin = $plugin ? Inflector::underscore($plugin) . '_' : ''; $plugin = str_replace(['\\', '/', '.'], '_', $plugin); $connection = $this->getConnectionName($this->input); $connectionConfig = ConnectionManager::config($connection); $adapterName = $this->getAdapterName($connectionConfig['driver']); $config = ['paths' => ['migrations' => $dir], 'environments' => ['default_migration_table' => $plugin . 'phinxlog', 'default_database' => 'default', 'default' => ['adapter' => $adapterName, 'host' => isset($connectionConfig['host']) ? $connectionConfig['host'] : null, 'user' => isset($connectionConfig['username']) ? $connectionConfig['username'] : null, 'pass' => isset($connectionConfig['password']) ? $connectionConfig['password'] : null, 'port' => isset($connectionConfig['port']) ? $connectionConfig['port'] : null, 'name' => $connectionConfig['database'], 'charset' => isset($connectionConfig['encoding']) ? $connectionConfig['encoding'] : null, 'unix_socket' => isset($connectionConfig['unix_socket']) ? $connectionConfig['unix_socket'] : null]]]; if ($adapterName === 'mysql') { if (!empty($connectionConfig['ssl_key']) && !empty($connectionConfig['ssl_cert'])) { $config['environments']['default']['mysql_attr_ssl_key'] = $connectionConfig['ssl_key']; $config['environments']['default']['mysql_attr_ssl_cert'] = $connectionConfig['ssl_cert']; } if (!empty($connectionConfig['ssl_ca'])) { $config['environments']['default']['mysql_attr_ssl_ca'] = $connectionConfig['ssl_ca']; } } return $this->configuration = new Config($config); }
/** * Overrides the original method from phinx in order to return a tailored * Config object containing the connection details for the database. * * @param bool $forceRefresh * @return \Phinx\Config\Config */ public function getConfig($forceRefresh = false) { if ($this->configuration && $forceRefresh === false) { return $this->configuration; } $migrationsPath = $this->getOperationsPath($this->input); $seedsPath = $this->getOperationsPath($this->input, 'Seeds'); $plugin = $this->getPlugin($this->input); if (!is_dir($migrationsPath)) { mkdir($migrationsPath, 0777, true); } if (!is_dir($seedsPath)) { mkdir($seedsPath, 0777, true); } $phinxTable = $this->getPhinxTable($plugin); $connection = $this->getConnectionName($this->input); $connectionConfig = ConnectionManager::config($connection); $adapterName = $this->getAdapterName($connectionConfig['driver']); $config = ['paths' => ['migrations' => $migrationsPath, 'seeds' => $seedsPath], 'environments' => ['default_migration_table' => $phinxTable, 'default_database' => 'default', 'default' => ['adapter' => $adapterName, 'host' => isset($connectionConfig['host']) ? $connectionConfig['host'] : null, 'user' => isset($connectionConfig['username']) ? $connectionConfig['username'] : null, 'pass' => isset($connectionConfig['password']) ? $connectionConfig['password'] : null, 'port' => isset($connectionConfig['port']) ? $connectionConfig['port'] : null, 'name' => $connectionConfig['database'], 'charset' => isset($connectionConfig['encoding']) ? $connectionConfig['encoding'] : null, 'unix_socket' => isset($connectionConfig['unix_socket']) ? $connectionConfig['unix_socket'] : null]]]; if ($adapterName === 'pgsql') { if (!empty($connectionConfig['schema'])) { $config['environments']['default']['schema'] = $connectionConfig['schema']; } } if ($adapterName === 'mysql') { if (!empty($connectionConfig['ssl_key']) && !empty($connectionConfig['ssl_cert'])) { $config['environments']['default']['mysql_attr_ssl_key'] = $connectionConfig['ssl_key']; $config['environments']['default']['mysql_attr_ssl_cert'] = $connectionConfig['ssl_cert']; } if (!empty($connectionConfig['ssl_ca'])) { $config['environments']['default']['mysql_attr_ssl_ca'] = $connectionConfig['ssl_ca']; } } return $this->configuration = new Config($config); }
public function testWithPreMadeConnection() { ConnectionManager::config('default', ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Sqlite']); $module = new CakeDbModule('default'); $instance = (new Injector($module, $_ENV['TMP_DIR']))->getInstance('Cake\\Database\\Connection'); $this->assertSame(ConnectionManager::get('default'), $instance); }
public function __construct() { $config = ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Mysql', 'database' => Configure::get('database.database'), 'username' => Configure::get('database.username'), 'password' => Configure::get('database.password'), 'host' => Configure::get('database.host'), 'persistent' => Configure::get('database.persistant'), 'encoding' => Configure::get('database.encoding'), 'timezone' => Configure::get('database.timezone'), 'quoteIdentifiers' => Configure::get('database.quoteIdentifiers'), 'log' => Configure::get('database.log')]; ConnectionManager::config('default', $config); $link = ConnectionManager::get('default'); self::$_logger = new QueryLogger(); $link->logger(self::$_logger); }
protected function setUp() { parent::setUp(); $configured = ConnectionManager::configured(); if (empty($configured)) { ConnectionManager::config('default', ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Sqlite', 'database' => self::SQLITE_PATH]); } $this->Posts = TableRegistry::get('Posts'); }
public function getMaxNo($restaurantId) { $datasource = ConnectionManager::config('default'); $connection = mysql_connect($datasource['host'], $datasource['username'], $datasource['password']); mysql_select_db($datasource['database'], $connection); $query = "call RestaurantDB.getMaxTakeawayNo(" . $restaurantId . ", @takawaymaxno);"; $result = mysql_query($query); $data = mysql_fetch_assoc($result); mysql_close($connection); return $data['maxId']; }
/** * Union migrate manager constructor. * * @param null $plugin */ public function __construct($plugin = null) { if (Plugin::loaded($plugin)) { $this->_connectionConfig = ConnectionManager::config($this->_connectionName); $this->_adapterName = $this->_getAdapterName($this->_connectionConfig['driver']); $config = ['paths' => ['migrations' => UnionPlugin::migrationPath($plugin)], 'environments' => $this->_configuration()]; $this->_plugin = $plugin; $this->_config = new Config($config); $adapterOptions = $this->_config->getEnvironment($this->_connectionName); $this->_adapter = $this->_setAdapter($adapterOptions); } }
public function get_product_list() { // make array with value is offeritems_id and text show from product table ConnectionManager::config('default'); $conn = ConnectionManager::get('default'); $product_list = $conn->query("SELECT OfferItems.id AS `OfferItems__id`, Products.productName AS `Products__productName`" . " FROM offer_items OfferItems INNER JOIN order_items OrderItems ON OrderItems.id = (OfferItems.order_items_id)" . " INNER JOIN products Products ON Products.id = (OrderItems.products_id) LIMIT 20 OFFSET 0"); $offerItem_product_list = []; foreach ($product_list as $prod) { $offerItem_product_list[$prod['OfferItems__id']] = $prod['Products__productName']; } return $offerItem_product_list; }
/** * {@inheritdoc} */ public function startup() { foreach (Config::get('cake_orm.datasources', []) as $name => $dataSource) { ConnectionManager::config($name, $dataSource); } Cache::config(Config::get('cake_orm.cache', [])); if (!is_dir($cakeLogPath = LOG_DIR . DS . 'cake')) { mkdir($cakeLogPath, 0777, true); } Log::config('queries', ['className' => 'File', 'path' => LOG_DIR . DS . 'cake' . DS, 'file' => 'queries.log', 'scopes' => ['queriesLog']]); $this->getEventManager()->addSubscriber(new CakeORMSubscriber()); }
function initialize(Container $container) { parent::initialize($container); $configs = $this->getConfigs(); // 设置数据库 foreach ($configs['datasources'] as $name => $config) { ConnectionManager::config($name, $config); } // 设置缓存 foreach ($configs['cache'] as $name => $config) { Cache::config($name, $config); } }
public function testInvalidDB() { $this->setExpectedException('Chris48s\\Searchable\\Exception\\SearchableFatalException'); //set up a SQLite DB connection - SQLite is not supported ConnectionManager::config('invalid', ['url' => 'sqlite:///:memory:', 'timezone' => 'UTC']); $conn = ConnectionManager::get('invalid'); //create a table in SQLite $conn->query("CREATE TABLE `Foo` (\n `id` int(11) NOT NULL,\n `textcol` VARCHAR(255),\n PRIMARY KEY (`id`)\n );"); $table = TableRegistry::get('Foo', ['connection' => $conn]); $table->addBehavior('Chris48s/Searchable.Searchable'); //tidy up ConnectionManager::dropAlias('invalid'); }
public static function get_related_products($parent_id, $product_id) { ConnectionManager::config('default'); $conn = ConnectionManager::get('default'); /* $product_list = $conn->query("SELECT products.*, product_makers.products_id As ProdMakerId FROM products INNER JOIN product_makers ON product_makers.id = products.product_makers_id WHERE product_makers.users_id = (SELECT product_makers.users_id AS MakerID FROM products LEFT JOIN product_makers ON product_makers.id = products.product_makers_id WHERE products.id = '" . $product_id . "') AND products.id != '" . $product_id . "'"); */ $product_list = $conn->query("SELECT products.* FROM products WHERE products.id != '" . $product_id . "'" . " AND products.categoreys_id IN((" . "SELECT categoreys.id FROM categoreys WHERE categoreys.parent_id =(" . "SELECT categoreys.parent_id FROM categoreys WHERE categoreys.id= '" . $parent_id . "')))"); return $product_list; }
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); } }
public function onBootstrap(MvcEvent $e) { /* * pega as configurações */ $config = $e->getApplication()->getServiceManager()->get('Config'); /* * arruma a configuração do cakePHP */ $config['CakePHP']['Cache']['_cake_model_']['duration'] = $config['caches']['Zend\\Cache']['options']['ttl']; $config['CakePHP']['Datasources']['default']['host'] = $config['db']['adapters']['Zend\\Db\\Adapter']['host']; $config['CakePHP']['Datasources']['default']['username'] = $config['db']['adapters']['Zend\\Db\\Adapter']['username']; $config['CakePHP']['Datasources']['default']['password'] = $config['db']['adapters']['Zend\\Db\\Adapter']['password']; $config['CakePHP']['Datasources']['default']['database'] = $config['db']['adapters']['Zend\\Db\\Adapter']['dbname']; /* * seta o namespace padrão do CakePHP (App\Model) */ foreach ($config['CakePHP']['Configure'] as $configKey => $configValue) { Configure::write($configKey, $configValue); } /* * configura o cache do CakePHP */ foreach ($config['CakePHP']['Cache'] as $configKey => $configValue) { $cacheDir = sprintf('%s/%s', ROOT_PATH, $configValue['path']); if (!is_dir($cacheDir)) { @mkdir($cacheDir, 0755, true); } Cache::config($configKey, $configValue); } /* * configura o log do CakePHP */ foreach ($config['CakePHP']['Log'] as $configKey => $configValue) { $logDir = sprintf('%s/%s', ROOT_PATH, $configValue['path']); if (!is_dir($logDir)) { @mkdir($logDir, 0755, true); } Log::config($configKey, $configValue); } /* * setup da conexão com banco de dados no CakePHP */ foreach ($config['CakePHP']['Datasources'] as $configKey => $configValue) { ConnectionManager::config($configKey, $configValue); } }
/** * Test truncate * * @return void */ public function testTruncate() { $is = $this->Users->find('count'); $this->assertEquals(4, $is); $config = ConnectionManager::config('test'); if (strpos($config['driver'], 'Mysql') !== false) { $is = $this->Users->getNextAutoIncrement(); $this->assertEquals(5, $is); } $is = $this->Users->truncate(); $is = $this->Users->find('count'); $this->assertEquals(0, $is); if (strpos($config['driver'], 'Mysql') !== false) { $is = $this->Users->getNextAutoIncrement(); $this->assertEquals(1, $is); } }
define('SESSIONS', TMP . 'sessions' . DS); define('CAKE_CORE_INCLUDE_PATH', ROOT . '/vendor/cakephp/cakephp'); define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS); define('CAKE', CORE_PATH . APP_DIR . DS); define('TEST_APP', ROOT . DS . 'tests' . DS . 'test_app' . DS); define('APP', TEST_APP . 'TestApp' . DS); define('WWW_ROOT', TEST_APP . 'webroot' . DS); define('CONFIG', ROOT . DS . 'config' . DS); //@codingStandardsIgnoreStart @mkdir(TMP); @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' => 'TestApp', 'fullBaseUrl' => 'http://localhost', 'encoding' => 'UTF-8', 'base' => false, 'baseUrl' => false, 'dir' => APP_DIR, 'webroot' => 'webroot', 'wwwRoot' => WWW_ROOT]); Cache::config(['_cake_core_' => ['engine' => 'File', 'prefix' => 'cake_core_', 'serialize' => true], '_cake_model_' => ['engine' => 'File', 'prefix' => 'cake_model_', 'serialize' => true]]); //needed? Plugin::load('JsonApi', ['path' => ROOT . DS, 'autoload' => true]); // Ensure default test connection is defined if (!getenv('db_dsn')) { putenv('db_dsn=sqlite:///:memory:'); } ConnectionManager::config('test', ['url' => getenv('db_dsn')]); Configure::write('Session', ['defaults' => 'php']); 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']]);
public function setUp() { StreamWrapper::overrideWrapper('https'); ConnectionManager::config('twitter', ['className' => 'Muffin\\Webservice\\Connection', 'service' => 'CvoTechnologies/Twitter.Twitter']); }
use Cake\Datasource\ConnectionManager; use Cake\Log\Log; require_once 'vendor/autoload.php'; // Path constants to a few helpful things. define('DS', DIRECTORY_SEPARATOR); define('ROOT', dirname(__DIR__) . DS); define('CAKE_CORE_INCLUDE_PATH', ROOT . 'vendor' . DS . 'cakephp' . DS . 'cakephp'); define('CORE_PATH', ROOT . 'vendor' . DS . 'cakephp' . DS . 'cakephp' . DS); define('CAKE', CORE_PATH . 'src' . DS); define('APP', ROOT . 'tests' . DS . 'test_app' . DS); define('TMP', sys_get_temp_dir() . DS); define('CACHE', TMP); define('LOGS', TMP); $loader = new \Cake\Core\ClassLoader(); $loader->register(); $loader->addNamespace('Cake\\Test\\Fixture', ROOT . '/vendor/cakephp/cakephp/tests/Fixture'); 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' => 'src', 'webroot' => 'webroot', 'www_root' => APP . 'webroot', 'fullBaseUrl' => 'http://localhost', 'imageBaseUrl' => 'img/', 'jsBaseUrl' => 'js/', 'cssBaseUrl' => 'css/', 'paths' => ['plugins' => [APP . 'Plugin' . DS], 'templates' => [APP . 'Template' . DS]]]); Configure::write('Session', ['defaults' => 'php']); Cache::config(['_cake_core_' => ['engine' => 'File', 'prefix' => 'cake_core_', 'serialize' => true], '_cake_model_' => ['engine' => 'File', 'prefix' => 'cake_model_', 'serialize' => true], 'default' => ['engine' => 'File', 'prefix' => 'default_', 'serialize' => true]]); // Ensure default test connection is defined if (!getenv('db_class')) { putenv('db_class=Cake\\Database\\Driver\\Sqlite'); putenv('db_dsn=sqlite::memory:'); } ConnectionManager::config('test', ['className' => 'Cake\\Database\\Connection', 'driver' => getenv('db_class'), 'dsn' => getenv('db_dsn'), 'database' => getenv('db_database'), 'username' => getenv('db_login'), 'password' => getenv('db_password'), 'timezone' => 'UTC']); 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']]); Plugin::load('Ceeram/Blame', ['path' => ROOT]);
/** * Test aliasing connections. * * @return void */ public function testAlias() { ConnectionManager::config('test_variant', ['className' => __NAMESPACE__ . '\\FakeConnection', 'database' => ':memory:']); ConnectionManager::alias('test_variant', 'other_name'); $result = ConnectionManager::get('test_variant'); $this->assertSame($result, ConnectionManager::get('other_name')); }
<?php use Cake\Datasource\ConnectionManager; use Cake\Utility\Hash; ConnectionManager::config(Hash::merge(['default' => ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Mysql', 'persistent' => false, 'host' => env('DATABASE_DEFAULT_HOST') ?: 'localhost', 'username' => env('DATABASE_DEFAULT_USER') ?: 'my_app', 'password' => env('DATABASE_DEFAULT_PASS') ?: 'secret', 'database' => env('DATABASE_DEFAULT_NAME') ?: 'my_app', 'prefix' => false, 'encoding' => strtolower(str_replace('-', '', read('App.encoding'))), 'timezone' => read('App.timezone'), 'quoteIdentifiers' => false], 'test' => ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Mysql', 'persistent' => false, 'host' => env('DATABASE_TEST_HOST') ?: 'localhost', 'username' => env('DATABASE_TEST_USER') ?: 'my_app', 'password' => env('DATABASE_TEST_PASS') ?: 'secret', 'database' => env('DATABASE_TEST_NAME') ?: 'test_myapp', 'prefix' => false, 'encoding' => strtolower(str_replace('-', '', read('App.encoding'))), 'timezone' => read('App.timezone'), 'quoteIdentifiers' => false]], consume('Datasources')));
/** * setup * * @return void */ public function setup() { parent::setUp(); $config = ConnectionManager::config('test'); $this->skipIf(strpos($config['driver'], 'Mysql') === false, 'Not using Mysql for test config'); }
define('CAKE_CORE_INCLUDE_PATH', ROOT . 'vendor' . DS . 'cakephp' . DS . 'cakephp'); define('CORE_PATH', ROOT . 'vendor' . DS . 'cakephp' . DS . 'cakephp' . DS); define('CAKE', CORE_PATH . 'src' . DS); define('TESTS', ROOT . 'tests'); define('APP', ROOT . 'tests' . DS . 'test_app' . DS); define('APP_DIR', 'test_app'); define('WEBROOT_DIR', 'webroot'); define('WWW_ROOT', APP . 'webroot' . DS); define('TMP', sys_get_temp_dir() . DS); define('CONFIG', APP . 'config' . DS); define('CACHE', TMP); define('LOGS', TMP); $loader = new \Cake\Core\ClassLoader(); $loader->register(); $loader->addNamespace('TestApp', APP); $loader->addNamespace('DebugHttpTestPlugin', APP . 'Plugin' . DS . 'TestPlugin' . DS . 'src'); 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' => 'src', 'webroot' => 'webroot', 'www_root' => APP . 'webroot', 'fullBaseUrl' => 'http://localhost', 'imageBaseUrl' => 'img/', 'jsBaseUrl' => 'js/', 'cssBaseUrl' => 'css/', 'paths' => ['plugins' => [APP . 'Plugin' . DS], 'templates' => [APP . 'Template' . DS]]]); Configure::write('Session', ['defaults' => 'php']); Cache::config(['_cake_core_' => ['engine' => 'File', 'prefix' => 'cake_core_', 'serialize' => true], '_cake_model_' => ['engine' => 'File', 'prefix' => 'cake_model_', 'serialize' => true], 'default' => ['engine' => 'File', 'prefix' => 'default_', 'serialize' => true]]); $config = ['timezone' => 'UTC']; // Use the test connection for 'debug_kit' as well. ConnectionManager::config('test', $config); ConnectionManager::config('test_debug_http', $config); 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']]); Plugin::load('DebugHttp', ['path' => ROOT]); DispatcherFactory::add('Routing'); DispatcherFactory::add('ControllerFactory');
* * If you define fullBaseUrl in your config file you can remove this. */ 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')); 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();
/** * Tests the junction passes the source connection name on. * * @return void */ public function testJunctionConnection() { $mock = $this->getMockBuilder('Cake\\Database\\Connection')->setMethods(['driver'])->setConstructorArgs(['name' => 'other_source'])->getMock(); ConnectionManager::config('other_source', $mock); $this->article->connection(ConnectionManager::get('other_source')); $assoc = new BelongsToMany('Test', ['sourceTable' => $this->article, 'targetTable' => $this->tag]); $junction = $assoc->junction(); $this->assertSame($mock, $junction->connection()); ConnectionManager::drop('other_source'); }
public function testInvalidDB() { $this->setExpectedException('Chris48s\\GeoDistance\\Exception\\GeoDistanceFatalException'); //set up a SQLite DB connection - SQLite is not supported ConnectionManager::config('invalid', ['url' => 'sqlite:///:memory:', 'timezone' => 'UTC']); $conn = ConnectionManager::get('invalid'); //create a table in SQLite $conn->query("CREATE TABLE `Foo` (\n `id` int(11) NOT NULL,\n `lat` float,\n `lng` float,\n PRIMARY KEY (`id`)\n );"); $table = TableRegistry::get('Foo', ['connection' => $conn]); $table->addBehavior('Chris48s/GeoDistance.GeoDistance', ['latitudeColumn' => 'lat', 'longitudeColumn' => 'lng']); //tidy up ConnectionManager::dropAlias('invalid'); }
$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');
public function setDataSource() { $config = ['className' => 'Cake\\Database\\Connection', 'driver' => 'Cake\\Database\\Driver\\Mysql', 'persistent' => false, 'host' => '192.168.1.101', 'username' => 'c0webcore', 'password' => '@webcore', 'database' => 'c0webcore', 'encoding' => 'utf8', 'timezone' => 'UTC', 'cacheMetadata' => true, 'quoteIdentifiers' => true]; ConnectionManager::config('server_hw', $config); }