mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-12 06:56:24 +00:00
Naming conventions to datasources with plugins. Fixes #819
This commit is contained in:
parent
a1911b4714
commit
2a4489cdf2
6 changed files with 147 additions and 2 deletions
|
@ -272,9 +272,12 @@ class ConnectionManager extends Object {
|
||||||
if ($plugin) {
|
if ($plugin) {
|
||||||
$filename = Inflector::underscore($classname);
|
$filename = Inflector::underscore($classname);
|
||||||
} else {
|
} else {
|
||||||
$filename = $config['datasource'] . '_source';
|
$filename = Inflector::underscore($config['datasource']);
|
||||||
$classname = Inflector::camelize(strtolower($filename));
|
|
||||||
}
|
}
|
||||||
|
if (substr($filename, -7) != '_source') {
|
||||||
|
$filename .= '_source';
|
||||||
|
}
|
||||||
|
$classname = Inflector::camelize(strtolower($filename));
|
||||||
}
|
}
|
||||||
return compact('filename', 'classname', 'parent', 'plugin');
|
return compact('filename', 'classname', 'parent', 'plugin');
|
||||||
}
|
}
|
||||||
|
|
|
@ -276,4 +276,65 @@ class ConnectionManagerTest extends CakeTestCase {
|
||||||
$source = ConnectionManager::create(null, $config);
|
$source = ConnectionManager::create(null, $config);
|
||||||
$this->assertEqual($source, null);
|
$this->assertEqual($source, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testConnectionData method
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
function testConnectionData() {
|
||||||
|
App::build(array(
|
||||||
|
'plugins' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS),
|
||||||
|
'datasources' => array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'models' . DS . 'datasources' . DS)
|
||||||
|
));
|
||||||
|
|
||||||
|
$expected = array(
|
||||||
|
'filename' => 'test2_source',
|
||||||
|
'classname' => 'Test2Source',
|
||||||
|
'parent' => '',
|
||||||
|
'plugin' => ''
|
||||||
|
);
|
||||||
|
|
||||||
|
ConnectionManager::create('connection1', array('datasource' => 'Test2'));
|
||||||
|
$connections = ConnectionManager::enumConnectionObjects();
|
||||||
|
$this->assertEqual($expected, $connections['connection1']);
|
||||||
|
|
||||||
|
ConnectionManager::create('connection2', array('datasource' => 'Test2Source'));
|
||||||
|
$connections = ConnectionManager::enumConnectionObjects();
|
||||||
|
$this->assertEqual($expected, $connections['connection2']);
|
||||||
|
|
||||||
|
ConnectionManager::create('connection3', array('datasource' => 'TestPlugin.Test'));
|
||||||
|
$connections = ConnectionManager::enumConnectionObjects();
|
||||||
|
$expected['filename'] = 'test_source';
|
||||||
|
$expected['classname'] = 'TestSource';
|
||||||
|
$expected['plugin'] = 'TestPlugin';
|
||||||
|
$this->assertEqual($expected, $connections['connection3']);
|
||||||
|
|
||||||
|
ConnectionManager::create('connection4', array('datasource' => 'TestPlugin.TestSource'));
|
||||||
|
$connections = ConnectionManager::enumConnectionObjects();
|
||||||
|
$this->assertEqual($expected, $connections['connection4']);
|
||||||
|
|
||||||
|
ConnectionManager::create('connection5', array('datasource' => 'Test2Other'));
|
||||||
|
$connections = ConnectionManager::enumConnectionObjects();
|
||||||
|
$expected['filename'] = 'test2_other_source';
|
||||||
|
$expected['classname'] = 'Test2OtherSource';
|
||||||
|
$expected['plugin'] = '';
|
||||||
|
$this->assertEqual($expected, $connections['connection5']);
|
||||||
|
|
||||||
|
ConnectionManager::create('connection6', array('datasource' => 'Test2OtherSource'));
|
||||||
|
$connections = ConnectionManager::enumConnectionObjects();
|
||||||
|
$this->assertEqual($expected, $connections['connection6']);
|
||||||
|
|
||||||
|
ConnectionManager::create('connection7', array('datasource' => 'TestPlugin.TestOther'));
|
||||||
|
$connections = ConnectionManager::enumConnectionObjects();
|
||||||
|
$expected['filename'] = 'test_other_source';
|
||||||
|
$expected['classname'] = 'TestOtherSource';
|
||||||
|
$expected['plugin'] = 'TestPlugin';
|
||||||
|
$this->assertEqual($expected, $connections['connection7']);
|
||||||
|
|
||||||
|
ConnectionManager::create('connection8', array('datasource' => 'TestPlugin.TestOtherSource'));
|
||||||
|
$connections = ConnectionManager::enumConnectionObjects();
|
||||||
|
$this->assertEqual($expected, $connections['connection8']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
class Test2OtherSource extends DataSource {
|
||||||
|
|
||||||
|
function describe($model) {
|
||||||
|
return compact('model');
|
||||||
|
}
|
||||||
|
|
||||||
|
function listSources() {
|
||||||
|
return array('test_source');
|
||||||
|
}
|
||||||
|
|
||||||
|
function create($model, $fields = array(), $values = array()) {
|
||||||
|
return compact('model', 'fields', 'values');
|
||||||
|
}
|
||||||
|
|
||||||
|
function read($model, $queryData = array()) {
|
||||||
|
return compact('model', 'queryData');
|
||||||
|
}
|
||||||
|
|
||||||
|
function update($model, $fields = array(), $values = array()) {
|
||||||
|
return compact('model', 'fields', 'values');
|
||||||
|
}
|
||||||
|
|
||||||
|
function delete($model, $id) {
|
||||||
|
return compact('model', 'id');
|
||||||
|
}
|
||||||
|
}
|
27
cake/tests/test_app/models/datasources/test2_source.php
Normal file
27
cake/tests/test_app/models/datasources/test2_source.php
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
class Test2Source extends DataSource {
|
||||||
|
|
||||||
|
function describe($model) {
|
||||||
|
return compact('model');
|
||||||
|
}
|
||||||
|
|
||||||
|
function listSources() {
|
||||||
|
return array('test_source');
|
||||||
|
}
|
||||||
|
|
||||||
|
function create($model, $fields = array(), $values = array()) {
|
||||||
|
return compact('model', 'fields', 'values');
|
||||||
|
}
|
||||||
|
|
||||||
|
function read($model, $queryData = array()) {
|
||||||
|
return compact('model', 'queryData');
|
||||||
|
}
|
||||||
|
|
||||||
|
function update($model, $fields = array(), $values = array()) {
|
||||||
|
return compact('model', 'fields', 'values');
|
||||||
|
}
|
||||||
|
|
||||||
|
function delete($model, $id) {
|
||||||
|
return compact('model', 'id');
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
<?php
|
||||||
|
class TestOtherSource extends DataSource {
|
||||||
|
|
||||||
|
function describe($model) {
|
||||||
|
return compact('model');
|
||||||
|
}
|
||||||
|
|
||||||
|
function listSources() {
|
||||||
|
return array('test_source');
|
||||||
|
}
|
||||||
|
|
||||||
|
function create($model, $fields = array(), $values = array()) {
|
||||||
|
return compact('model', 'fields', 'values');
|
||||||
|
}
|
||||||
|
|
||||||
|
function read($model, $queryData = array()) {
|
||||||
|
return compact('model', 'queryData');
|
||||||
|
}
|
||||||
|
|
||||||
|
function update($model, $fields = array(), $values = array()) {
|
||||||
|
return compact('model', 'fields', 'values');
|
||||||
|
}
|
||||||
|
|
||||||
|
function delete($model, $id) {
|
||||||
|
return compact('model', 'id');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue