Browse Source

do not use reserved php words as function in schemabuilder

there is a reason for them to be reserved, we should not add such workarounds to still use them.

close #9283
tags/2.0.6
Carsten Brandt 9 years ago
parent
commit
7150e830d9
  1. 29
      framework/db/SchemaBuilder.php
  2. 2
      tests/framework/db/QueryBuilderTest.php
  3. 2
      tests/framework/db/cubrid/CubridQueryBuilderTest.php
  4. 2
      tests/framework/db/oci/OracleQueryBuilderTest.php
  5. 2
      tests/framework/db/pgsql/PostgreSQLQueryBuilderTest.php
  6. 2
      tests/framework/db/sqlite/SqliteQueryBuilderTest.php

29
framework/db/SchemaBuilder.php

@ -11,14 +11,14 @@ use Yii;
use yii\base\Object;
/**
* SchemaBuilder is the class help to define DB's schema types.
* SchemaBuilder helps to define database schema types using a PHP interface.
*
* For example you may use the following code inside your migration files:
*
* ```php
* $this->createTable('table', [
* 'name' => Schema::string(64)->notNull(),
* 'type' => Schema::integer()->notNull()->default(10),
* 'type' => Schema::integer()->notNull()->defaultValue(10),
* 'description' => Schema::text(),
* 'rule_name' => Schema::string(64),
* 'data' => Schema::text(),
@ -27,8 +27,6 @@ use yii\base\Object;
* ]);
* ```
*
* @method SchemaBuilder default($default = null) see [[SchemaBuilder::_default()]] for more info
*
* @author Vasenin Matvey <vaseninm@gmail.com>
* @since 2.0.6
*/
@ -291,26 +289,6 @@ abstract class SchemaBuilder extends Object
}
/**
* Calls the named method which is not a class method.
*
* Do not call this method directly as it is a PHP magic method that
* will be implicitly called when an unknown method is being invoked.
*
* @param string $name the method name
* @param array $arguments method parameters
*
* @return mixed the method return value
*/
public function __call($name, $arguments)
{
if ($name === 'default') {
return call_user_func_array([$this, '_default'], $arguments);
}
return parent::__call($name, $arguments);
}
/**
* Specify check value for the column
*
* @param string $check
@ -344,10 +322,9 @@ abstract class SchemaBuilder extends Object
* Specify default value for the column
*
* @param mixed $default
*
* @return $this
*/
protected function _default($default = null)
protected function defaultValue($default = null)
{
$this->default = $default;

2
tests/framework/db/QueryBuilderTest.php

@ -122,7 +122,7 @@ class QueryBuilderTest extends DatabaseTestCase
[Schema::TYPE_DATE . ' NOT NULL', Schema::date()->notNull(), 'date NOT NULL'],
[Schema::TYPE_BINARY, Schema::binary(), 'blob'],
[Schema::TYPE_BOOLEAN, Schema::boolean(), 'tinyint(1)'],
[Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', Schema::boolean()->notNull()->default(1), 'tinyint(1) NOT NULL DEFAULT 1'],
[Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', Schema::boolean()->notNull()->defaultValue(1), 'tinyint(1) NOT NULL DEFAULT 1'],
[Schema::TYPE_MONEY, Schema::money(), 'decimal(19,4)'],
[Schema::TYPE_MONEY . '(16,2)', Schema::money(16, 2), 'decimal(16,2)'],
[Schema::TYPE_MONEY . ' CHECK (value > 0.0)', Schema::money()->check('value > 0.0'), 'decimal(19,4) CHECK (value > 0.0)'],

2
tests/framework/db/cubrid/CubridQueryBuilderTest.php

@ -71,7 +71,7 @@ class CubridQueryBuilderTest extends QueryBuilderTest
[Schema::TYPE_DATE . ' NOT NULL', Schema::date()->notNull(), 'date NOT NULL'],
[Schema::TYPE_BINARY, Schema::binary(), 'blob'],
[Schema::TYPE_BOOLEAN, Schema::boolean(), 'smallint'],
[Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', Schema::boolean()->notNull()->default(1), 'smallint NOT NULL DEFAULT 1'],
[Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', Schema::boolean()->notNull()->defaultValue(1), 'smallint NOT NULL DEFAULT 1'],
[Schema::TYPE_MONEY, Schema::money(), 'decimal(19,4)'],
[Schema::TYPE_MONEY . '(16,2)', Schema::money(16, 2), 'decimal(16,2)'],
[Schema::TYPE_MONEY . ' CHECK (value > 0.0)', Schema::money()->check('value > 0.0'), 'decimal(19,4) CHECK (value > 0.0)'],

2
tests/framework/db/oci/OracleQueryBuilderTest.php

@ -76,7 +76,7 @@ class OracleQueryBuilderTest extends QueryBuilderTest
[Schema::TYPE_DATE . ' NOT NULL', Schema::date()->notNull(), 'DATE NOT NULL'],
[Schema::TYPE_BINARY, Schema::binary(), 'BLOB'],
[Schema::TYPE_BOOLEAN, Schema::boolean(), 'NUMBER(1)'],
[Schema::TYPE_BOOLEAN . ' DEFAULT 1 NOT NULL', Schema::boolean()->notNull()->default(1), 'NUMBER(1) DEFAULT 1 NOT NULL'],
[Schema::TYPE_BOOLEAN . ' DEFAULT 1 NOT NULL', Schema::boolean()->notNull()->defaultValue(1), 'NUMBER(1) DEFAULT 1 NOT NULL'],
[Schema::TYPE_MONEY, Schema::money(), 'NUMBER(19,4)'],
[Schema::TYPE_MONEY . '(16,2)', Schema::money(16, 2), 'NUMBER(16,2)'],
[Schema::TYPE_MONEY . ' CHECK (value > 0.0)', Schema::money()->check('value > 0.0'), 'NUMBER(19,4) CHECK (value > 0.0)'],

2
tests/framework/db/pgsql/PostgreSQLQueryBuilderTest.php

@ -66,7 +66,7 @@ class PostgreSQLQueryBuilderTest extends QueryBuilderTest
[Schema::TYPE_DATE . ' NOT NULL', Schema::date()->notNull(), 'date NOT NULL'],
[Schema::TYPE_BINARY, Schema::binary(), 'bytea'],
[Schema::TYPE_BOOLEAN, Schema::boolean(), 'boolean'],
[Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT TRUE', Schema::boolean()->notNull()->default(true), 'boolean NOT NULL DEFAULT TRUE'],
[Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT TRUE', Schema::boolean()->notNull()->defaultValue(true), 'boolean NOT NULL DEFAULT TRUE'],
[Schema::TYPE_MONEY, Schema::money(), 'numeric(19,4)'],
[Schema::TYPE_MONEY . '(16,2)', Schema::money(16, 2), 'numeric(16,2)'],
[Schema::TYPE_MONEY . ' CHECK (value > 0.0)', Schema::money()->check('value > 0.0'), 'numeric(19,4) CHECK (value > 0.0)'],

2
tests/framework/db/sqlite/SqliteQueryBuilderTest.php

@ -67,7 +67,7 @@ class SqliteQueryBuilderTest extends QueryBuilderTest
[Schema::TYPE_DATE . ' NOT NULL', Schema::date()->notNull(), 'date NOT NULL'],
[Schema::TYPE_BINARY, Schema::binary(), 'blob'],
[Schema::TYPE_BOOLEAN, Schema::boolean(), 'boolean'],
[Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', Schema::boolean()->notNull()->default(1), 'boolean NOT NULL DEFAULT 1'],
[Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', Schema::boolean()->notNull()->defaultValue(1), 'boolean NOT NULL DEFAULT 1'],
[Schema::TYPE_MONEY, Schema::money(), 'decimal(19,4)'],
[Schema::TYPE_MONEY . '(16,2)', Schema::money(16, 2), 'decimal(16,2)'],
[Schema::TYPE_MONEY . ' CHECK (value > 0.0)', Schema::money()->check('value > 0.0'), 'decimal(19,4) CHECK (value > 0.0)'],

Loading…
Cancel
Save