Skip to content

Commit 46de16e

Browse files
committed
Add deprecation warnings to the Database package.
Add deprecation warnings and update tests in the database package.
1 parent 15d5e2b commit 46de16e

28 files changed

+441
-240
lines changed

src/Database/Connection.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ public function getDriver()
206206
*/
207207
public function driver($driver = null, $config = [])
208208
{
209+
deprecationWarning('Connection::driver() is deprecated. Use Connection::setDriver()/getDriver() instead.');
209210
if ($driver !== null) {
210211
$this->setDriver($driver, $config);
211212
}
@@ -380,6 +381,10 @@ public function getSchemaCollection()
380381
*/
381382
public function schemaCollection(SchemaCollection $collection = null)
382383
{
384+
deprecationWarning(
385+
'Connection::schemaCollection() is deprecated. ' .
386+
'Use Connection::setSchemaCollection()/getSchemaCollection() instead.'
387+
);
383388
if ($collection !== null) {
384389
$this->setSchemaCollection($collection);
385390
}
@@ -591,6 +596,10 @@ public function isSavePointsEnabled()
591596
*/
592597
public function useSavePoints($enable = null)
593598
{
599+
deprecationWarning(
600+
'Connection::useSavePoints() is deprecated. ' .
601+
'Use Connection::enableSavePoints()/isSavePointsEnabled() instead.'
602+
);
594603
if ($enable !== null) {
595604
$this->enableSavePoints($enable);
596605
}
@@ -816,6 +825,10 @@ public function logQueries($enable = null)
816825
*/
817826
public function logger($instance = null)
818827
{
828+
deprecationWarning(
829+
'Connection::logger() is deprecated. ' .
830+
'Use Connection::setLogger()/getLogger() instead.'
831+
);
819832
if ($instance === null) {
820833
return $this->getLogger();
821834
}

src/Database/Driver.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,10 @@ public function isAutoQuotingEnabled()
336336
*/
337337
public function autoQuoting($enable = null)
338338
{
339+
deprecationWarning(
340+
'Driver::autoQuoting() is deprecated. ' .
341+
'Use Driver::enableAutoQuoting()/isAutoQuotingEnabled() instead.'
342+
);
339343
if ($enable !== null) {
340344
$this->enableAutoQuoting($enable);
341345
}

src/Database/Expression/FunctionExpression.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ public function getName()
104104
*/
105105
public function name($name = null)
106106
{
107+
deprecationWarning(
108+
'FunctionExpression::name() is deprecated. ' .
109+
'Use FunctionExpression::setName()/getName() instead.'
110+
);
107111
if ($name !== null) {
108112
return $this->setName($name);
109113
}

src/Database/Expression/QueryExpression.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public function getConjunction()
105105
*/
106106
public function tieWith($conjunction = null)
107107
{
108+
deprecationWarning(
109+
'QueryExpression::tieWith() is deprecated. ' .
110+
'Use QueryExpression::setConjunction()/getConjunction() instead.'
111+
);
108112
if ($conjunction !== null) {
109113
return $this->setConjunction($conjunction);
110114
}
@@ -118,10 +122,14 @@ public function tieWith($conjunction = null)
118122
* @param string|null $conjunction value to be used for joining conditions. If null it
119123
* will not set any value, but return the currently stored one
120124
* @return string|$this
121-
* @deprecated 3.2.0 Use tieWith() instead
125+
* @deprecated 3.2.0 Use setConjunction()/getConjunction() instead
122126
*/
123127
public function type($conjunction = null)
124128
{
129+
deprecationWarning(
130+
'QueryExpression::type() is deprecated. ' .
131+
'Use QueryExpression::setConjunction()/getConjunction() instead.'
132+
);
125133
return $this->tieWith($conjunction);
126134
}
127135

src/Database/Expression/ValuesExpression.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ public function getColumns()
134134
*/
135135
public function columns($cols = null)
136136
{
137+
deprecationWarning(
138+
'ValuesExpression::columns() is deprecated. ' .
139+
'Use ValuesExpression::setColumns()/getColumns() instead.'
140+
);
137141
if ($cols !== null) {
138142
return $this->setColumns($cols);
139143
}
@@ -200,6 +204,10 @@ public function getValues()
200204
*/
201205
public function values($values = null)
202206
{
207+
deprecationWarning(
208+
'ValuesExpression::values() is deprecated. ' .
209+
'Use ValuesExpression::setValues()/getValues() instead.'
210+
);
203211
if ($values !== null) {
204212
return $this->setValues($values);
205213
}
@@ -243,6 +251,10 @@ public function getQuery()
243251
*/
244252
public function query(Query $query = null)
245253
{
254+
deprecationWarning(
255+
'ValuesExpression::query() is deprecated. ' .
256+
'Use ValuesExpression::setQuery()/getQuery() instead.'
257+
);
246258
if ($query !== null) {
247259
return $this->setQuery($query);
248260
}

src/Database/IdentifierQuoter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function __construct(Driver $driver)
5353
public function quote(Query $query)
5454
{
5555
$binder = $query->getValueBinder();
56-
$query->valueBinder(false);
56+
$query->setValueBinder(false);
5757

5858
if ($query->type() === 'insert') {
5959
$this->_quoteInsert($query);
@@ -64,7 +64,7 @@ public function quote(Query $query)
6464
}
6565

6666
$query->traverseExpressions([$this, 'quoteExpression']);
67-
$query->valueBinder($binder);
67+
$query->setValueBinder($binder);
6868

6969
return $query;
7070
}

src/Database/Log/LoggingStatement.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ public function bindValue($column, $value, $type = 'string')
115115
*/
116116
public function logger($instance = null)
117117
{
118+
deprecationWarning(
119+
'LoggingStatement::logger() is deprecated. ' .
120+
'Use LoggingStatement::setLogger()/getLogger() instead.'
121+
);
118122
if ($instance === null) {
119123
return $this->getLogger();
120124
}

src/Database/Query.php

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ public function getConnection()
182182
*/
183183
public function connection($connection = null)
184184
{
185+
deprecationWarning(
186+
'Query::connection() is deprecated. ' .
187+
'Use Query::setConnection()/getConnection() instead.'
188+
);
185189
if ($connection !== null) {
186190
return $this->setConnection($connection);
187191
}
@@ -1003,6 +1007,7 @@ public function andWhere($conditions, $types = [])
10031007
*/
10041008
public function orWhere($conditions, $types = [])
10051009
{
1010+
deprecationWarning('Query::orWhere() is deprecated. Use Query::where() instead.');
10061011
$this->_conjugate('where', $conditions, 'OR', $types);
10071012

10081013
return $this;
@@ -1242,6 +1247,7 @@ public function andHaving($conditions, $types = [])
12421247
*/
12431248
public function orHaving($conditions, $types = [])
12441249
{
1250+
deprecationWarning('Query::orHaving() is deprecated. Use Query::having() instead.');
12451251
$this->_conjugate('having', $conditions, 'OR', $types);
12461252

12471253
return $this;
@@ -1865,6 +1871,23 @@ public function getValueBinder()
18651871
return $this->_valueBinder;
18661872
}
18671873

1874+
/**
1875+
* Overwrite the current value binder
1876+
*
1877+
* A ValueBinder is responsible for generating query placeholders and temporarily
1878+
* associate values to those placeholders so that they can be passed correctly
1879+
* to the statement object.
1880+
*
1881+
* @param \Cake\Database\ValueBinder|bool $binder The binder or false to disable binding.
1882+
* @return $this
1883+
*/
1884+
public function setValueBinder($binder)
1885+
{
1886+
$this->_valueBinder = $binder;
1887+
1888+
return $this;
1889+
}
1890+
18681891
/**
18691892
* Returns the currently used ValueBinder instance. If a value is passed,
18701893
* it will be set as the new instance to be used.
@@ -1873,13 +1896,14 @@ public function getValueBinder()
18731896
* associate values to those placeholders so that they can be passed correctly
18741897
* to the statement object.
18751898
*
1876-
* @deprecated 3.5.0 Use getValueBinder() for the getter part instead.
1899+
* @deprecated 3.5.0 Use setValueBinder()/getValueBinder() instead.
18771900
* @param \Cake\Database\ValueBinder|null $binder new instance to be set. If no value is passed the
18781901
* default one will be returned
18791902
* @return $this|\Cake\Database\ValueBinder
18801903
*/
18811904
public function valueBinder($binder = null)
18821905
{
1906+
deprecationWarning('Query::valueBinder() is deprecated. Use Query::getValueBinder()/setValueBinder() instead.');
18831907
if ($binder === null) {
18841908
if ($this->_valueBinder === null) {
18851909
$this->_valueBinder = new ValueBinder();
@@ -1949,6 +1973,10 @@ public function isBufferedResultsEnabled()
19491973
*/
19501974
public function bufferResults($enable = null)
19511975
{
1976+
deprecationWarning(
1977+
'Query::bufferResults() is deprecated. ' .
1978+
'Use Query::enableBufferedResults()/isBufferedResultsEnabled() instead.'
1979+
);
19521980
if ($enable !== null) {
19531981
return $this->enableBufferedResults($enable);
19541982
}
@@ -1996,6 +2024,10 @@ public function getSelectTypeMap()
19962024
*/
19972025
public function selectTypeMap(TypeMap $typeMap = null)
19982026
{
2027+
deprecationWarning(
2028+
'Query::selectTypeMap() is deprecated. ' .
2029+
'Use Query::setSelectTypeMap()/getSelectTypeMap() instead.'
2030+
);
19992031
if ($typeMap !== null) {
20002032
return $this->setSelectTypeMap($typeMap);
20012033
}

src/Database/Schema/CachedCollection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ public function getCacheMetadata()
119119
*/
120120
public function cacheMetadata($enable = null)
121121
{
122+
deprecationWarning(
123+
'CachedCollection::cacheMetadata() is deprecated. ' .
124+
'Use CachedCollection::setCacheMetadata()/getCacheMetadata() instead.'
125+
);
122126
if ($enable !== null) {
123127
$this->setCacheMetadata($enable);
124128
}

src/Database/Schema/TableSchema.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,10 @@ public function isTemporary()
778778
*/
779779
public function temporary($temporary = null)
780780
{
781+
deprecationWarning(
782+
'TableSchema::temporary() is deprecated. ' .
783+
'Use TableSchema::setTemporary()/getTemporary() instead.'
784+
);
781785
if ($temporary !== null) {
782786
return $this->setTemporary($temporary);
783787
}

src/Database/Type.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ public function toPHP($value, Driver $driver)
223223
*/
224224
protected function _basicTypeCast($value)
225225
{
226+
deprecationWarning('Type::_basicTypeCast() is deprecated.');
226227
if ($value === null) {
227228
return null;
228229
}
@@ -259,6 +260,7 @@ public function toStatement($value, Driver $driver)
259260
*/
260261
public static function boolval($value)
261262
{
263+
deprecationWarning('Type::boolval() is deprecated.');
262264
if (is_string($value) && !is_numeric($value)) {
263265
return strtolower($value) === 'true';
264266
}
@@ -277,6 +279,7 @@ public static function boolval($value)
277279
*/
278280
public static function strval($value)
279281
{
282+
deprecationWarning('Type::strval() is deprecated.');
280283
if (is_array($value)) {
281284
$value = '';
282285
}

src/Database/TypeMap.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ public function getDefaults()
108108
*/
109109
public function defaults(array $defaults = null)
110110
{
111+
deprecationWarning(
112+
'TypeMap::defaults() is deprecated. ' .
113+
'Use TypeMap::setDefaults()/getDefaults() instead.'
114+
);
111115
if ($defaults !== null) {
112116
return $this->setDefaults($defaults);
113117
}
@@ -180,6 +184,10 @@ public function getTypes()
180184
*/
181185
public function types(array $types = null)
182186
{
187+
deprecationWarning(
188+
'TypeMap::types() is deprecated. ' .
189+
'Use TypeMap::setTypes()/getTypes() instead.'
190+
);
183191
if ($types !== null) {
184192
return $this->setTypes($types);
185193
}

src/Database/TypeMapTrait.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public function getTypeMap()
6262
*/
6363
public function typeMap($typeMap = null)
6464
{
65+
deprecationWarning(
66+
'TypeMapTrait::typeMap() is deprecated. ' .
67+
'Use TypeMapTrait::setTypeMap()/getTypeMap() instead.'
68+
);
6569
if ($typeMap !== null) {
6670
return $this->setTypeMap($typeMap);
6771
}
@@ -101,6 +105,10 @@ public function getDefaultTypes()
101105
*/
102106
public function defaultTypes(array $types = null)
103107
{
108+
deprecationWarning(
109+
'TypeMapTrait::defaultTypes() is deprecated. ' .
110+
'Use TypeMapTrait::setDefaultTypes()/getDefaultTypes() instead.'
111+
);
104112
if ($types !== null) {
105113
return $this->setDefaultTypes($types);
106114
}

src/Database/TypedResultTrait.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ public function setReturnType($type)
6060
*/
6161
public function returnType($type = null)
6262
{
63+
deprecationWarning(
64+
'TypedResultTrait::returnType() is deprecated. ' .
65+
'Use TypedResultTrait::setReturnType()/getReturnType() instead.'
66+
);
6367
if ($type !== null) {
6468
$this->_returnType = $type;
6569

src/TestSuite/Fixture/FixtureManager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public function load($test)
286286

287287
try {
288288
$createTables = function ($db, $fixtures) use ($test) {
289-
$tables = $db->schemaCollection()->listTables();
289+
$tables = $db->getSchemaCollection()->listTables();
290290
$configName = $db->configName();
291291
if (!isset($this->_insertionMap[$configName])) {
292292
$this->_insertionMap[$configName] = [];
@@ -455,7 +455,7 @@ public function loadSingle($name, $db = null, $dropTables = true)
455455
}
456456

457457
if (!$this->isFixtureSetup($db->configName(), $fixture)) {
458-
$sources = $db->schemaCollection()->listTables();
458+
$sources = $db->getSchemaCollection()->listTables();
459459
$this->_setupTable($fixture, $db, $sources, $dropTables);
460460
}
461461

0 commit comments

Comments
 (0)