Skip to content

Commit

Permalink
Add deprecation warnings to the Database package.
Browse files Browse the repository at this point in the history
Add deprecation warnings and update tests in the database package.
  • Loading branch information
markstory committed Oct 28, 2017
1 parent 15d5e2b commit 46de16e
Show file tree
Hide file tree
Showing 28 changed files with 441 additions and 240 deletions.
13 changes: 13 additions & 0 deletions src/Database/Connection.php
Expand Up @@ -206,6 +206,7 @@ public function getDriver()
*/
public function driver($driver = null, $config = [])
{
deprecationWarning('Connection::driver() is deprecated. Use Connection::setDriver()/getDriver() instead.');
if ($driver !== null) {
$this->setDriver($driver, $config);
}
Expand Down Expand Up @@ -380,6 +381,10 @@ public function getSchemaCollection()
*/
public function schemaCollection(SchemaCollection $collection = null)
{
deprecationWarning(
'Connection::schemaCollection() is deprecated. ' .
'Use Connection::setSchemaCollection()/getSchemaCollection() instead.'
);
if ($collection !== null) {
$this->setSchemaCollection($collection);
}
Expand Down Expand Up @@ -591,6 +596,10 @@ public function isSavePointsEnabled()
*/
public function useSavePoints($enable = null)
{
deprecationWarning(
'Connection::useSavePoints() is deprecated. ' .
'Use Connection::enableSavePoints()/isSavePointsEnabled() instead.'
);
if ($enable !== null) {
$this->enableSavePoints($enable);
}
Expand Down Expand Up @@ -816,6 +825,10 @@ public function logQueries($enable = null)
*/
public function logger($instance = null)
{
deprecationWarning(
'Connection::logger() is deprecated. ' .
'Use Connection::setLogger()/getLogger() instead.'
);
if ($instance === null) {
return $this->getLogger();
}
Expand Down
4 changes: 4 additions & 0 deletions src/Database/Driver.php
Expand Up @@ -336,6 +336,10 @@ public function isAutoQuotingEnabled()
*/
public function autoQuoting($enable = null)
{
deprecationWarning(
'Driver::autoQuoting() is deprecated. ' .
'Use Driver::enableAutoQuoting()/isAutoQuotingEnabled() instead.'
);
if ($enable !== null) {
$this->enableAutoQuoting($enable);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Database/Expression/FunctionExpression.php
Expand Up @@ -104,6 +104,10 @@ public function getName()
*/
public function name($name = null)
{
deprecationWarning(
'FunctionExpression::name() is deprecated. ' .
'Use FunctionExpression::setName()/getName() instead.'
);
if ($name !== null) {
return $this->setName($name);
}
Expand Down
10 changes: 9 additions & 1 deletion src/Database/Expression/QueryExpression.php
Expand Up @@ -105,6 +105,10 @@ public function getConjunction()
*/
public function tieWith($conjunction = null)
{
deprecationWarning(
'QueryExpression::tieWith() is deprecated. ' .
'Use QueryExpression::setConjunction()/getConjunction() instead.'
);
if ($conjunction !== null) {
return $this->setConjunction($conjunction);
}
Expand All @@ -118,10 +122,14 @@ public function tieWith($conjunction = null)
* @param string|null $conjunction value to be used for joining conditions. If null it
* will not set any value, but return the currently stored one
* @return string|$this
* @deprecated 3.2.0 Use tieWith() instead
* @deprecated 3.2.0 Use setConjunction()/getConjunction() instead
*/
public function type($conjunction = null)
{
deprecationWarning(
'QueryExpression::type() is deprecated. ' .
'Use QueryExpression::setConjunction()/getConjunction() instead.'
);
return $this->tieWith($conjunction);
}

Expand Down
12 changes: 12 additions & 0 deletions src/Database/Expression/ValuesExpression.php
Expand Up @@ -134,6 +134,10 @@ public function getColumns()
*/
public function columns($cols = null)
{
deprecationWarning(
'ValuesExpression::columns() is deprecated. ' .
'Use ValuesExpression::setColumns()/getColumns() instead.'
);
if ($cols !== null) {
return $this->setColumns($cols);
}
Expand Down Expand Up @@ -200,6 +204,10 @@ public function getValues()
*/
public function values($values = null)
{
deprecationWarning(
'ValuesExpression::values() is deprecated. ' .
'Use ValuesExpression::setValues()/getValues() instead.'
);
if ($values !== null) {
return $this->setValues($values);
}
Expand Down Expand Up @@ -243,6 +251,10 @@ public function getQuery()
*/
public function query(Query $query = null)
{
deprecationWarning(
'ValuesExpression::query() is deprecated. ' .
'Use ValuesExpression::setQuery()/getQuery() instead.'
);
if ($query !== null) {
return $this->setQuery($query);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Database/IdentifierQuoter.php
Expand Up @@ -53,7 +53,7 @@ public function __construct(Driver $driver)
public function quote(Query $query)
{
$binder = $query->getValueBinder();
$query->valueBinder(false);
$query->setValueBinder(false);

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

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

return $query;
}
Expand Down
4 changes: 4 additions & 0 deletions src/Database/Log/LoggingStatement.php
Expand Up @@ -115,6 +115,10 @@ public function bindValue($column, $value, $type = 'string')
*/
public function logger($instance = null)
{
deprecationWarning(
'LoggingStatement::logger() is deprecated. ' .
'Use LoggingStatement::setLogger()/getLogger() instead.'
);
if ($instance === null) {
return $this->getLogger();
}
Expand Down
34 changes: 33 additions & 1 deletion src/Database/Query.php
Expand Up @@ -182,6 +182,10 @@ public function getConnection()
*/
public function connection($connection = null)
{
deprecationWarning(
'Query::connection() is deprecated. ' .
'Use Query::setConnection()/getConnection() instead.'
);
if ($connection !== null) {
return $this->setConnection($connection);
}
Expand Down Expand Up @@ -1003,6 +1007,7 @@ public function andWhere($conditions, $types = [])
*/
public function orWhere($conditions, $types = [])
{
deprecationWarning('Query::orWhere() is deprecated. Use Query::where() instead.');
$this->_conjugate('where', $conditions, 'OR', $types);

return $this;
Expand Down Expand Up @@ -1242,6 +1247,7 @@ public function andHaving($conditions, $types = [])
*/
public function orHaving($conditions, $types = [])
{
deprecationWarning('Query::orHaving() is deprecated. Use Query::having() instead.');
$this->_conjugate('having', $conditions, 'OR', $types);

return $this;
Expand Down Expand Up @@ -1865,6 +1871,23 @@ public function getValueBinder()
return $this->_valueBinder;
}

/**
* Overwrite the current value binder
*
* A ValueBinder is responsible for generating query placeholders and temporarily
* associate values to those placeholders so that they can be passed correctly
* to the statement object.
*
* @param \Cake\Database\ValueBinder|bool $binder The binder or false to disable binding.
* @return $this
*/
public function setValueBinder($binder)
{
$this->_valueBinder = $binder;

return $this;
}

/**
* Returns the currently used ValueBinder instance. If a value is passed,
* it will be set as the new instance to be used.
Expand All @@ -1873,13 +1896,14 @@ public function getValueBinder()
* associate values to those placeholders so that they can be passed correctly
* to the statement object.
*
* @deprecated 3.5.0 Use getValueBinder() for the getter part instead.
* @deprecated 3.5.0 Use setValueBinder()/getValueBinder() instead.
* @param \Cake\Database\ValueBinder|null $binder new instance to be set. If no value is passed the
* default one will be returned
* @return $this|\Cake\Database\ValueBinder
*/
public function valueBinder($binder = null)
{
deprecationWarning('Query::valueBinder() is deprecated. Use Query::getValueBinder()/setValueBinder() instead.');
if ($binder === null) {
if ($this->_valueBinder === null) {
$this->_valueBinder = new ValueBinder();
Expand Down Expand Up @@ -1949,6 +1973,10 @@ public function isBufferedResultsEnabled()
*/
public function bufferResults($enable = null)
{
deprecationWarning(
'Query::bufferResults() is deprecated. ' .
'Use Query::enableBufferedResults()/isBufferedResultsEnabled() instead.'
);
if ($enable !== null) {
return $this->enableBufferedResults($enable);
}
Expand Down Expand Up @@ -1996,6 +2024,10 @@ public function getSelectTypeMap()
*/
public function selectTypeMap(TypeMap $typeMap = null)
{
deprecationWarning(
'Query::selectTypeMap() is deprecated. ' .
'Use Query::setSelectTypeMap()/getSelectTypeMap() instead.'
);
if ($typeMap !== null) {
return $this->setSelectTypeMap($typeMap);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Database/Schema/CachedCollection.php
Expand Up @@ -119,6 +119,10 @@ public function getCacheMetadata()
*/
public function cacheMetadata($enable = null)
{
deprecationWarning(
'CachedCollection::cacheMetadata() is deprecated. ' .
'Use CachedCollection::setCacheMetadata()/getCacheMetadata() instead.'
);
if ($enable !== null) {
$this->setCacheMetadata($enable);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Database/Schema/TableSchema.php
Expand Up @@ -778,6 +778,10 @@ public function isTemporary()
*/
public function temporary($temporary = null)
{
deprecationWarning(
'TableSchema::temporary() is deprecated. ' .
'Use TableSchema::setTemporary()/getTemporary() instead.'
);
if ($temporary !== null) {
return $this->setTemporary($temporary);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Database/Type.php
Expand Up @@ -223,6 +223,7 @@ public function toPHP($value, Driver $driver)
*/
protected function _basicTypeCast($value)
{
deprecationWarning('Type::_basicTypeCast() is deprecated.');
if ($value === null) {
return null;
}
Expand Down Expand Up @@ -259,6 +260,7 @@ public function toStatement($value, Driver $driver)
*/
public static function boolval($value)
{
deprecationWarning('Type::boolval() is deprecated.');
if (is_string($value) && !is_numeric($value)) {
return strtolower($value) === 'true';
}
Expand All @@ -277,6 +279,7 @@ public static function boolval($value)
*/
public static function strval($value)
{
deprecationWarning('Type::strval() is deprecated.');
if (is_array($value)) {
$value = '';
}
Expand Down
8 changes: 8 additions & 0 deletions src/Database/TypeMap.php
Expand Up @@ -108,6 +108,10 @@ public function getDefaults()
*/
public function defaults(array $defaults = null)
{
deprecationWarning(
'TypeMap::defaults() is deprecated. ' .
'Use TypeMap::setDefaults()/getDefaults() instead.'
);
if ($defaults !== null) {
return $this->setDefaults($defaults);
}
Expand Down Expand Up @@ -180,6 +184,10 @@ public function getTypes()
*/
public function types(array $types = null)
{
deprecationWarning(
'TypeMap::types() is deprecated. ' .
'Use TypeMap::setTypes()/getTypes() instead.'
);
if ($types !== null) {
return $this->setTypes($types);
}
Expand Down
8 changes: 8 additions & 0 deletions src/Database/TypeMapTrait.php
Expand Up @@ -62,6 +62,10 @@ public function getTypeMap()
*/
public function typeMap($typeMap = null)
{
deprecationWarning(
'TypeMapTrait::typeMap() is deprecated. ' .
'Use TypeMapTrait::setTypeMap()/getTypeMap() instead.'
);
if ($typeMap !== null) {
return $this->setTypeMap($typeMap);
}
Expand Down Expand Up @@ -101,6 +105,10 @@ public function getDefaultTypes()
*/
public function defaultTypes(array $types = null)
{
deprecationWarning(
'TypeMapTrait::defaultTypes() is deprecated. ' .
'Use TypeMapTrait::setDefaultTypes()/getDefaultTypes() instead.'
);
if ($types !== null) {
return $this->setDefaultTypes($types);
}
Expand Down
4 changes: 4 additions & 0 deletions src/Database/TypedResultTrait.php
Expand Up @@ -60,6 +60,10 @@ public function setReturnType($type)
*/
public function returnType($type = null)
{
deprecationWarning(
'TypedResultTrait::returnType() is deprecated. ' .
'Use TypedResultTrait::setReturnType()/getReturnType() instead.'
);
if ($type !== null) {
$this->_returnType = $type;

Expand Down
4 changes: 2 additions & 2 deletions src/TestSuite/Fixture/FixtureManager.php
Expand Up @@ -286,7 +286,7 @@ public function load($test)

try {
$createTables = function ($db, $fixtures) use ($test) {
$tables = $db->schemaCollection()->listTables();
$tables = $db->getSchemaCollection()->listTables();
$configName = $db->configName();
if (!isset($this->_insertionMap[$configName])) {
$this->_insertionMap[$configName] = [];
Expand Down Expand Up @@ -455,7 +455,7 @@ public function loadSingle($name, $db = null, $dropTables = true)
}

if (!$this->isFixtureSetup($db->configName(), $fixture)) {
$sources = $db->schemaCollection()->listTables();
$sources = $db->getSchemaCollection()->listTables();
$this->_setupTable($fixture, $db, $sources, $dropTables);
}

Expand Down

0 comments on commit 46de16e

Please sign in to comment.