diff --git a/BaseYii.php b/BaseYii.php index d00943fca..091b920f1 100644 --- a/BaseYii.php +++ b/BaseYii.php @@ -93,7 +93,7 @@ class BaseYii */ public static function getVersion() { - return '2.0.53-dev'; + return '2.2-dev'; } /** @@ -414,18 +414,6 @@ public static function debug($message, $category = 'application') } } - /** - * Alias of [[debug()]]. - * @param string|array $message the message to be logged. This can be a simple string or a more - * complex data structure, such as an array. - * @param string $category the category of the message. - * @deprecated since 2.0.14. Use [[debug()]] instead. - */ - public static function trace($message, $category = 'application') - { - static::debug($message, $category); - } - /** * Logs an error message. * An error message is typically logged when an unrecoverable error occurs @@ -500,18 +488,6 @@ public static function endProfile($token, $category = 'application') static::getLogger()->log($token, Logger::LEVEL_PROFILE_END, $category); } - /** - * Returns an HTML hyperlink that can be displayed on your Web page showing "Powered by Yii Framework" information. - * @return string an HTML hyperlink that can be displayed on your Web page showing "Powered by Yii Framework" information - * @deprecated since 2.0.14, this method will be removed in 2.1.0. - */ - public static function powered() - { - return \Yii::t('yii', 'Powered by {yii}', [ - 'yii' => '' . \Yii::t('yii', 'Yii Framework') . '', - ]); - } - /** * Translates a message to the specified language. * diff --git a/CHANGELOG.md b/CHANGELOG.md index 95339288f..47cca0834 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ Yii Framework 2 Change Log ========================== +2.2 under development +------------------------ + +- Chg #19902: Remove support for CUBRID (mtangoo) +- Chg #19891: Remove XCache and ZendDataCache support (mtangoo) +- Enh #20368: Refactor asset management: Migrate from `Bower` to `NPM` for package dependencies and update related documentation (terabytesoftw) + + 2.0.53 under development ------------------------ diff --git a/UPGRADE.md b/UPGRADE.md index 902136088..a6fdf69f0 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -416,7 +416,7 @@ Upgrade from Yii 2.0.34 public function rules() { return [ - ['attribute', 'each', 'rule' => ['exist', 'targetClass' => static::className(), 'targetAttribute' => 'id']], + ['attribute', 'each', 'rule' => ['exist', 'targetClass' => static::class, 'targetAttribute' => 'id']], ]; } ``` @@ -645,13 +645,11 @@ Upgrade from Yii 2.0.13 * Log targets (like `yii\log\EmailTarget`) are now throwing `yii\log\LogRuntimeException` in case log can not be properly exported. -* You can start preparing your application for Yii 2.1 by doing the following: +* You can start preparing your application for Yii 2.2 by doing the following: - - Replace `::className()` calls with `::class` (if you’re running PHP 5.5+). - Replace usages of `yii\base\InvalidParamException` with `yii\base\InvalidArgumentException`. - Replace calls to `Yii::trace()` with `Yii::debug()`. - Remove calls to `yii\BaseYii::powered()`. - - If you are using XCache or Zend data cache, those are going away in 2.1 so you might want to start looking for an alternative. * In case you aren't using CSRF cookies (REST APIs etc.) you should turn them off explicitly by setting `\yii\web\Request::$enableCsrfCookie` to `false` in your config file. diff --git a/base/Application.php b/base/Application.php index e2944b82a..fddd279b7 100644 --- a/base/Application.php +++ b/base/Application.php @@ -459,8 +459,7 @@ public function setVendorPath($path) { $this->_vendorPath = Yii::getAlias($path); Yii::setAlias('@vendor', $this->_vendorPath); - Yii::setAlias('@bower', $this->_vendorPath . DIRECTORY_SEPARATOR . 'bower'); - Yii::setAlias('@npm', $this->_vendorPath . DIRECTORY_SEPARATOR . 'npm'); + Yii::setAlias('@npm', $this->getBasePath() . DIRECTORY_SEPARATOR . 'node_modules'); } /** diff --git a/base/BaseObject.php b/base/BaseObject.php index 8ef2f1566..6a87b4aed 100644 --- a/base/BaseObject.php +++ b/base/BaseObject.php @@ -76,16 +76,6 @@ */ class BaseObject implements Configurable { - /** - * Returns the fully qualified name of this class. - * @return string the fully qualified name of this class. - * @deprecated since 2.0.14. On PHP >=5.5, use `::class` instead. - */ - public static function className() - { - return get_called_class(); - } - /** * Constructor. * @@ -295,4 +285,14 @@ public function hasMethod($name) { return method_exists($this, $name); } + + /** + * Returns the fully qualified name of this class. + * + * @return string the fully qualified name of this class. + */ + public static function className(): string + { + return static::class; + } } diff --git a/base/Controller.php b/base/Controller.php index 494e1c535..a8f8ae625 100644 --- a/base/Controller.php +++ b/base/Controller.php @@ -105,8 +105,8 @@ public function __construct($id, $module, $config = []) public function init() { parent::init(); - $this->request = Instance::ensure($this->request, Request::className()); - $this->response = Instance::ensure($this->response, Response::className()); + $this->request = Instance::ensure($this->request, Request::class); + $this->response = Instance::ensure($this->response, Response::class); } /** diff --git a/base/InvalidArgumentException.php b/base/InvalidArgumentException.php index 20a7c6c75..428d73b58 100644 --- a/base/InvalidArgumentException.php +++ b/base/InvalidArgumentException.php @@ -13,7 +13,7 @@ * @author Qiang Xue * @since 2.0.14 */ -class InvalidArgumentException extends InvalidParamException +class InvalidArgumentException extends \BadMethodCallException { /** * @return string the user-friendly name of this exception diff --git a/base/InvalidParamException.php b/base/InvalidParamException.php deleted file mode 100644 index 0024602ec..000000000 --- a/base/InvalidParamException.php +++ /dev/null @@ -1,26 +0,0 @@ - - * @since 2.0 - * @deprecated since 2.0.14. Use [[InvalidArgumentException]] instead. - */ -class InvalidParamException extends \BadMethodCallException -{ - /** - * @return string the user-friendly name of this exception - */ - public function getName() - { - return 'Invalid Parameter'; - } -} diff --git a/base/Security.php b/base/Security.php index 85faf50e5..bee3336e5 100644 --- a/base/Security.php +++ b/base/Security.php @@ -72,16 +72,6 @@ class Security extends Component * Set as high as possible to hinder dictionary password attacks. */ public $derivationIterations = 100000; - /** - * @var string strategy, which should be used to generate password hash. - * Available strategies: - * - 'password_hash' - use of PHP `password_hash()` function with PASSWORD_DEFAULT algorithm. - * This option is recommended, but it requires PHP version >= 5.5.0 - * - 'crypt' - use PHP `crypt()` function. - * @deprecated since version 2.0.7, [[generatePasswordHash()]] ignores [[passwordHashStrategy]] and - * uses `password_hash()` when available or `crypt()` when not. - */ - public $passwordHashStrategy; /** * @var int Default cost used for password hashing. * Allowed value is between 4 and 31. diff --git a/behaviors/SluggableBehavior.php b/behaviors/SluggableBehavior.php index c18bd4fa2..369be6c37 100644 --- a/behaviors/SluggableBehavior.php +++ b/behaviors/SluggableBehavior.php @@ -243,7 +243,7 @@ protected function validateSlug($slug) /* @var $model BaseActiveRecord */ $validator = Yii::createObject(array_merge( [ - 'class' => UniqueValidator::className(), + 'class' => UniqueValidator::class, ], $this->uniqueValidator )); diff --git a/caching/Cache.php b/caching/Cache.php index d6d363c6d..390494271 100644 --- a/caching/Cache.php +++ b/caching/Cache.php @@ -166,23 +166,6 @@ public function exists($key) return $value !== false; } - /** - * Retrieves multiple values from cache with the specified keys. - * Some caches (such as memcache, apc) allow retrieving multiple cached values at the same time, - * which may improve the performance. In case a cache does not support this feature natively, - * this method will try to simulate it. - * - * @param string[] $keys list of string keys identifying the cached values - * @return array list of cached values corresponding to the specified keys. The array - * is returned in terms of (key, value) pairs. - * If a value is not cached or expired, the corresponding array value will be false. - * @deprecated This method is an alias for [[multiGet()]] and will be removed in 2.1.0. - */ - public function mget($keys) - { - return $this->multiGet($keys); - } - /** * Retrieves multiple values from cache with the specified keys. * Some caches (such as memcache, apc) allow retrieving multiple cached values at the same time, @@ -255,25 +238,6 @@ public function set($key, $value, $duration = null, $dependency = null) return $this->setValue($key, $value, $duration); } - /** - * Stores multiple items in cache. Each item contains a value identified by a key. - * If the cache already contains such a key, the existing value and - * expiration time will be replaced with the new ones, respectively. - * - * @param array $items the items to be cached, as key-value pairs. - * @param int|null $duration default duration in seconds before the cache will expire. If not set, - * default [[defaultDuration]] value is used. - * @param Dependency|null $dependency dependency of the cached items. If the dependency changes, - * the corresponding values in the cache will be invalidated when it is fetched via [[get()]]. - * This parameter is ignored if [[serializer]] is false. - * @return array array of failed keys - * @deprecated This method is an alias for [[multiSet()]] and will be removed in 2.1.0. - */ - public function mset($items, $duration = null, $dependency = null) - { - return $this->multiSet($items, $duration, $dependency); - } - /** * Stores multiple items in cache. Each item contains a value identified by a key. * If the cache already contains such a key, the existing value and @@ -299,23 +263,6 @@ public function multiSet($items, $duration = null, $dependency = null) return $this->setValues($data, $duration); } - /** - * Stores multiple items in cache. Each item contains a value identified by a key. - * If the cache already contains such a key, the existing value and expiration time will be preserved. - * - * @param array $items the items to be cached, as key-value pairs. - * @param int $duration default number of seconds in which the cached values will expire. 0 means never expire. - * @param Dependency|null $dependency dependency of the cached items. If the dependency changes, - * the corresponding values in the cache will be invalidated when it is fetched via [[get()]]. - * This parameter is ignored if [[serializer]] is false. - * @return array array of failed keys - * @deprecated This method is an alias for [[multiAdd()]] and will be removed in 2.1.0. - */ - public function madd($items, $duration = 0, $dependency = null) - { - return $this->multiAdd($items, $duration, $dependency); - } - /** * Stores multiple items in cache. Each item contains a value identified by a key. * If the cache already contains such a key, the existing value and expiration time will be preserved. diff --git a/caching/DbCache.php b/caching/DbCache.php index d707ba41a..45f172969 100644 --- a/caching/DbCache.php +++ b/caching/DbCache.php @@ -95,7 +95,7 @@ class DbCache extends Cache public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); } /** diff --git a/caching/DbDependency.php b/caching/DbDependency.php index 43a51d926..525c3e02b 100644 --- a/caching/DbDependency.php +++ b/caching/DbDependency.php @@ -50,7 +50,7 @@ class DbDependency extends Dependency protected function generateDependencyData($cache) { /* @var $db Connection */ - $db = Instance::ensure($this->db, Connection::className()); + $db = Instance::ensure($this->db, Connection::class); if ($this->sql === null) { throw new InvalidConfigException('DbDependency::sql must be set.'); } diff --git a/caching/Dependency.php b/caching/Dependency.php index e558bfef8..c4de5078a 100644 --- a/caching/Dependency.php +++ b/caching/Dependency.php @@ -57,17 +57,6 @@ public function evaluateDependency($cache) } } - /** - * Returns a value indicating whether the dependency has changed. - * @deprecated since version 2.0.11. Will be removed in version 2.1. Use [[isChanged()]] instead. - * @param CacheInterface $cache the cache component that is currently evaluating this dependency - * @return bool whether the dependency has changed. - */ - public function getHasChanged($cache) - { - return $this->isChanged($cache); - } - /** * Checks whether the dependency is changed. * @param CacheInterface $cache the cache component that is currently evaluating this dependency diff --git a/caching/XCache.php b/caching/XCache.php deleted file mode 100644 index 06c305de2..000000000 --- a/caching/XCache.php +++ /dev/null @@ -1,111 +0,0 @@ - - * @since 2.0 - * @deprecated since 2.0.14. This class will be removed in 2.1.0. - */ -class XCache extends Cache -{ - /** - * Checks whether a specified key exists in the cache. - * This can be faster than getting the value from the cache if the data is big. - * Note that this method does not check whether the dependency associated - * with the cached data, if there is any, has changed. So a call to [[get]] - * may return false while exists returns true. - * @param mixed $key a key identifying the cached value. This can be a simple string or - * a complex data structure consisting of factors representing the key. - * @return bool true if a value exists in cache, false if the value is not in the cache or expired. - */ - public function exists($key) - { - $key = $this->buildKey($key); - - return xcache_isset($key); - } - - /** - * Retrieves a value from cache with a specified key. - * This is the implementation of the method declared in the parent class. - * @param string $key a unique key identifying the cached value - * @return mixed|false the value stored in cache, false if the value is not in the cache or expired. - */ - protected function getValue($key) - { - return xcache_isset($key) ? xcache_get($key) : false; - } - - /** - * Stores a value identified by a key in cache. - * This is the implementation of the method declared in the parent class. - * - * @param string $key the key identifying the value to be cached - * @param mixed $value the value to be cached. Most often it's a string. If you have disabled [[serializer]], - * it could be something else. - * @param int $duration the number of seconds in which the cached value will expire. 0 means never expire. - * @return bool true if the value is successfully stored into cache, false otherwise - */ - protected function setValue($key, $value, $duration) - { - return xcache_set($key, $value, $duration); - } - - /** - * Stores a value identified by a key into cache if the cache does not contain this key. - * This is the implementation of the method declared in the parent class. - * - * @param string $key the key identifying the value to be cached - * @param mixed $value the value to be cached. Most often it's a string. If you have disabled [[serializer]], - * it could be something else. - * @param int $duration the number of seconds in which the cached value will expire. 0 means never expire. - * @return bool true if the value is successfully stored into cache, false otherwise - */ - protected function addValue($key, $value, $duration) - { - return !xcache_isset($key) ? $this->setValue($key, $value, $duration) : false; - } - - /** - * Deletes a value with the specified key from cache - * This is the implementation of the method declared in the parent class. - * @param string $key the key of the value to be deleted - * @return bool if no error happens during deletion - */ - protected function deleteValue($key) - { - return xcache_unset($key); - } - - /** - * Deletes all values from cache. - * This is the implementation of the method declared in the parent class. - * @return bool whether the flush operation was successful. - */ - protected function flushValues() - { - for ($i = 0, $max = xcache_count(XC_TYPE_VAR); $i < $max; $i++) { - if (xcache_clear_cache(XC_TYPE_VAR, $i) === false) { - return false; - } - } - - return true; - } -} diff --git a/caching/ZendDataCache.php b/caching/ZendDataCache.php deleted file mode 100644 index 0f49501db..000000000 --- a/caching/ZendDataCache.php +++ /dev/null @@ -1,89 +0,0 @@ - - * @since 2.0 - * @deprecated since 2.0.14. This class will be removed in 2.1.0. - */ -class ZendDataCache extends Cache -{ - /** - * Retrieves a value from cache with a specified key. - * This is the implementation of the method declared in the parent class. - * @param string $key a unique key identifying the cached value - * @return mixed|false the value stored in cache, false if the value is not in the cache or expired. - */ - protected function getValue($key) - { - $result = zend_shm_cache_fetch($key); - - return $result === null ? false : $result; - } - - /** - * Stores a value identified by a key in cache. - * This is the implementation of the method declared in the parent class. - * - * @param string $key the key identifying the value to be cached - * @param mixed $value the value to be cached. Most often it's a string. If you have disabled [[serializer]], - * it could be something else. - * @param int $duration the number of seconds in which the cached value will expire. 0 means never expire. - * @return bool true if the value is successfully stored into cache, false otherwise - */ - protected function setValue($key, $value, $duration) - { - return zend_shm_cache_store($key, $value, $duration); - } - - /** - * Stores a value identified by a key into cache if the cache does not contain this key. - * This is the implementation of the method declared in the parent class. - * - * @param string $key the key identifying the value to be cached - * @param mixed $value the value to be cached. Most often it's a string. If you have disabled [[serializer]], - * it could be something else. - * @param int $duration the number of seconds in which the cached value will expire. 0 means never expire. - * @return bool true if the value is successfully stored into cache, false otherwise - */ - protected function addValue($key, $value, $duration) - { - return zend_shm_cache_fetch($key) === null ? $this->setValue($key, $value, $duration) : false; - } - - /** - * Deletes a value with the specified key from cache - * This is the implementation of the method declared in the parent class. - * @param string $key the key of the value to be deleted - * @return bool if no error happens during deletion - */ - protected function deleteValue($key) - { - return zend_shm_cache_delete($key); - } - - /** - * Deletes all values from cache. - * This is the implementation of the method declared in the parent class. - * @return bool whether the flush operation was successful. - */ - protected function flushValues() - { - return zend_shm_cache_clear(); - } -} diff --git a/classes.php b/classes.php index 03b69c92a..a5758b0c0 100644 --- a/classes.php +++ b/classes.php @@ -36,7 +36,6 @@ 'yii\base\InvalidArgumentException' => YII2_PATH . '/base/InvalidArgumentException.php', 'yii\base\InvalidCallException' => YII2_PATH . '/base/InvalidCallException.php', 'yii\base\InvalidConfigException' => YII2_PATH . '/base/InvalidConfigException.php', - 'yii\base\InvalidParamException' => YII2_PATH . '/base/InvalidParamException.php', 'yii\base\InvalidRouteException' => YII2_PATH . '/base/InvalidRouteException.php', 'yii\base\InvalidValueException' => YII2_PATH . '/base/InvalidValueException.php', 'yii\base\Model' => YII2_PATH . '/base/Model.php', @@ -86,8 +85,6 @@ 'yii\caching\MemCacheServer' => YII2_PATH . '/caching/MemCacheServer.php', 'yii\caching\TagDependency' => YII2_PATH . '/caching/TagDependency.php', 'yii\caching\WinCache' => YII2_PATH . '/caching/WinCache.php', - 'yii\caching\XCache' => YII2_PATH . '/caching/XCache.php', - 'yii\caching\ZendDataCache' => YII2_PATH . '/caching/ZendDataCache.php', 'yii\captcha\Captcha' => YII2_PATH . '/captcha/Captcha.php', 'yii\captcha\CaptchaAction' => YII2_PATH . '/captcha/CaptchaAction.php', 'yii\captcha\CaptchaAsset' => YII2_PATH . '/captcha/CaptchaAsset.php', @@ -169,10 +166,6 @@ 'yii\db\conditions\OrCondition' => YII2_PATH . '/db/conditions/OrCondition.php', 'yii\db\conditions\SimpleCondition' => YII2_PATH . '/db/conditions/SimpleCondition.php', 'yii\db\conditions\SimpleConditionBuilder' => YII2_PATH . '/db/conditions/SimpleConditionBuilder.php', - 'yii\db\cubrid\ColumnSchemaBuilder' => YII2_PATH . '/db/cubrid/ColumnSchemaBuilder.php', - 'yii\db\cubrid\QueryBuilder' => YII2_PATH . '/db/cubrid/QueryBuilder.php', - 'yii\db\cubrid\Schema' => YII2_PATH . '/db/cubrid/Schema.php', - 'yii\db\cubrid\conditions\LikeConditionBuilder' => YII2_PATH . '/db/cubrid/conditions/LikeConditionBuilder.php', 'yii\db\mssql\ColumnSchema' => YII2_PATH . '/db/mssql/ColumnSchema.php', 'yii\db\mssql\ColumnSchemaBuilder' => YII2_PATH . '/db/mssql/ColumnSchemaBuilder.php', 'yii\db\mssql\DBLibPDO' => YII2_PATH . '/db/mssql/DBLibPDO.php', diff --git a/composer.json b/composer.json index 72e5079cd..461206ffd 100644 --- a/composer.json +++ b/composer.json @@ -63,17 +63,13 @@ "source": "https://github.com/yiisoft/yii2" }, "require": { - "php": ">=7.3.0", + "php": ">=8.1", "ext-mbstring": "*", "ext-ctype": "*", "lib-pcre": "*", "yiisoft/yii2-composer": "~2.0.4", "ezyang/htmlpurifier": "^4.17", - "cebe/markdown": "~1.0.0 | ~1.1.0 | ~1.2.0", - "bower-asset/jquery": "3.7.*@stable | 3.6.*@stable | 3.5.*@stable | 3.4.*@stable | 3.3.*@stable | 3.2.*@stable | 3.1.*@stable | 2.2.*@stable | 2.1.*@stable | 1.11.*@stable | 1.12.*@stable", - "bower-asset/inputmask": "^5.0.8 ", - "bower-asset/punycode": "^1.4", - "bower-asset/yii2-pjax": "~2.0.1" + "cebe/markdown": "~1.0.0 | ~1.1.0 | ~1.2.0" }, "autoload": { "psr-4": {"yii\\": ""} @@ -84,6 +80,7 @@ "extra": { "branch-alias": { "dev-master": "2.0.x-dev" - } + }, + "foxy": true } } diff --git a/console/Controller.php b/console/Controller.php index 7029abd54..667ff1e44 100644 --- a/console/Controller.php +++ b/console/Controller.php @@ -38,15 +38,6 @@ */ class Controller extends \yii\base\Controller { - /** - * @deprecated since 2.0.13. Use [[ExitCode::OK]] instead. - */ - const EXIT_CODE_NORMAL = 0; - /** - * @deprecated since 2.0.13. Use [[ExitCode::UNSPECIFIED_ERROR]] instead. - */ - const EXIT_CODE_ERROR = 1; - /** * @var bool whether to run the command interactively. */ diff --git a/console/controllers/CacheController.php b/console/controllers/CacheController.php index d5d0a756e..4a2fabff7 100644 --- a/console/controllers/CacheController.php +++ b/console/controllers/CacheController.php @@ -300,6 +300,6 @@ private function isCacheClass($className) */ private function canBeFlushed($className) { - return !is_a($className, ApcCache::className(), true) || PHP_SAPI !== 'cli'; + return !is_a($className, ApcCache::class, true) || PHP_SAPI !== 'cli'; } } diff --git a/console/controllers/FixtureController.php b/console/controllers/FixtureController.php index caba5d271..9187ea517 100644 --- a/console/controllers/FixtureController.php +++ b/console/controllers/FixtureController.php @@ -8,8 +8,8 @@ namespace yii\console\controllers; use Yii; +use yii\base\InvalidArgumentException; use yii\base\InvalidConfigException; -use yii\base\InvalidParamException; use yii\console\Controller; use yii\console\Exception; use yii\console\ExitCode; @@ -258,7 +258,7 @@ private function notifyLoaded($fixtures) $fixtureClassNames = []; foreach ($fixtures as $fixture) { - $fixtureClassNames[] = $fixture::className(); + $fixtureClassNames[] = $fixture::class; } $this->outputList($fixtureClassNames); @@ -536,7 +536,7 @@ private function getFixturePath() { try { return Yii::getAlias('@' . str_replace('\\', '/', $this->namespace)); - } catch (InvalidParamException $e) { + } catch (InvalidArgumentException $e) { throw new InvalidConfigException('Invalid fixture namespace: "' . $this->namespace . '". Please, check your FixtureController::namespace parameter'); } } diff --git a/console/controllers/MessageController.php b/console/controllers/MessageController.php index 63d3aa10b..baffa797c 100644 --- a/console/controllers/MessageController.php +++ b/console/controllers/MessageController.php @@ -318,7 +318,7 @@ public function actionExtract($configFile = null) } } elseif ($this->config['format'] === 'db') { /** @var Connection $db */ - $db = Instance::ensure($this->config['db'], Connection::className()); + $db = Instance::ensure($this->config['db'], Connection::class); $sourceMessageTable = isset($this->config['sourceMessageTable']) ? $this->config['sourceMessageTable'] : '{{%source_message}}'; $messageTable = isset($this->config['messageTable']) ? $this->config['messageTable'] : '{{%message}}'; $this->saveMessagesToDb( diff --git a/console/controllers/MigrateController.php b/console/controllers/MigrateController.php index 104c68657..2f2d1dd17 100644 --- a/console/controllers/MigrateController.php +++ b/console/controllers/MigrateController.php @@ -180,7 +180,7 @@ public function optionAliases() public function beforeAction($action) { if (parent::beforeAction($action)) { - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); return true; } @@ -468,7 +468,7 @@ protected function generateMigrationSourceCode($params) if ($relatedColumn === null) { $relatedColumn = 'id'; try { - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); $relatedTableSchema = $this->db->getTableSchema($relatedTable); if ($relatedTableSchema !== null) { $primaryKeyCount = count($relatedTableSchema->primaryKey); diff --git a/data/BaseDataProvider.php b/data/BaseDataProvider.php index 9339972c5..abecb7c42 100644 --- a/data/BaseDataProvider.php +++ b/data/BaseDataProvider.php @@ -211,7 +211,7 @@ public function getPagination() public function setPagination($value) { if (is_array($value)) { - $config = ['class' => Pagination::className()]; + $config = ['class' => Pagination::class]; if ($this->id !== null) { $config['pageParam'] = $this->id . '-page'; $config['pageSizeParam'] = $this->id . '-per-page'; @@ -252,7 +252,7 @@ public function getSort() public function setSort($value) { if (is_array($value)) { - $config = ['class' => Sort::className()]; + $config = ['class' => Sort::class]; if ($this->id !== null) { $config['sortParam'] = $this->id . '-sort'; } diff --git a/data/DataFilter.php b/data/DataFilter.php index 057509203..587b7b10a 100644 --- a/data/DataFilter.php +++ b/data/DataFilter.php @@ -288,7 +288,7 @@ public function getSearchModel() if (!is_object($this->_searchModel) || $this->_searchModel instanceof \Closure) { $model = Yii::createObject($this->_searchModel); if (!$model instanceof Model) { - throw new InvalidConfigException('`' . get_class($this) . '::$searchModel` should be an instance of `' . Model::className() . '` or its DI compatible configuration.'); + throw new InvalidConfigException('`' . get_class($this) . '::$searchModel` should be an instance of `' . Model::class . '` or its DI compatible configuration.'); } $this->_searchModel = $model; } @@ -302,7 +302,7 @@ public function getSearchModel() public function setSearchModel($model) { if (is_object($model) && !$model instanceof Model && !$model instanceof \Closure) { - throw new InvalidConfigException('`' . get_class($this) . '::$searchModel` should be an instance of `' . Model::className() . '` or its DI compatible configuration.'); + throw new InvalidConfigException('`' . get_class($this) . '::$searchModel` should be an instance of `' . Model::class . '` or its DI compatible configuration.'); } $this->_searchModel = $model; } diff --git a/data/SqlDataProvider.php b/data/SqlDataProvider.php index a0fe4bc29..e8620ff34 100644 --- a/data/SqlDataProvider.php +++ b/data/SqlDataProvider.php @@ -95,7 +95,7 @@ class SqlDataProvider extends BaseDataProvider public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); if ($this->sql === null) { throw new InvalidConfigException('The "sql" property must be set.'); } diff --git a/db/ActiveRecord.php b/db/ActiveRecord.php index 3714e43a8..c34b51168 100644 --- a/db/ActiveRecord.php +++ b/db/ActiveRecord.php @@ -417,7 +417,7 @@ public static function deleteAll($condition = null, $params = []) */ public static function find() { - return Yii::createObject(ActiveQuery::className(), [get_called_class()]); + return Yii::createObject(ActiveQuery::class, [get_called_class()]); } /** diff --git a/db/BaseActiveRecord.php b/db/BaseActiveRecord.php index 761bc2cb9..3772f047b 100644 --- a/db/BaseActiveRecord.php +++ b/db/BaseActiveRecord.php @@ -11,7 +11,6 @@ use yii\base\InvalidArgumentException; use yii\base\InvalidCallException; use yii\base\InvalidConfigException; -use yii\base\InvalidParamException; use yii\base\Model; use yii\base\ModelEvent; use yii\base\NotSupportedException; @@ -1681,7 +1680,7 @@ public function getAttributeHint($attribute) } else { try { $relation = $relatedModel->getRelation($relationName); - } catch (InvalidParamException $e) { + } catch (InvalidArgumentException $e) { return ''; } /* @var $modelClass ActiveRecordInterface */ diff --git a/db/ColumnSchemaBuilder.php b/db/ColumnSchemaBuilder.php index 02ca9f2fe..d041d4573 100644 --- a/db/ColumnSchemaBuilder.php +++ b/db/ColumnSchemaBuilder.php @@ -225,7 +225,7 @@ public function unsigned() /** * Adds an `AFTER` constraint to the column. - * Note: MySQL, Oracle and Cubrid support only. + * Note: MySQL and Oracle support only. * @param string $after the column after which $this column will be added. * @return $this * @since 2.0.8 @@ -238,7 +238,7 @@ public function after($after) /** * Adds an `FIRST` constraint to the column. - * Note: MySQL, Oracle and Cubrid support only. + * Note: MySQL and Oracle support only. * @return $this * @since 2.0.8 */ diff --git a/db/Connection.php b/db/Connection.php index 0c3eca41c..12c442702 100644 --- a/db/Connection.php +++ b/db/Connection.php @@ -238,7 +238,7 @@ class Connection extends Component public $queryCache = 'cache'; /** * @var string|null the charset used for database connection. The property is only used - * for MySQL, PostgreSQL and CUBRID databases. Defaults to null, meaning using default charset + * for MySQL and PostgreSQL databases. Defaults to null, meaning using default charset * as configured by the database. * * For Oracle Database, the charset must be specified in the [[dsn]], for example for UTF-8 by appending `;charset=UTF-8` @@ -282,22 +282,12 @@ class Connection extends Component 'oci' => 'yii\db\oci\Schema', // Oracle driver 'mssql' => 'yii\db\mssql\Schema', // older MSSQL driver on MS Windows hosts 'dblib' => 'yii\db\mssql\Schema', // dblib drivers on GNU/Linux (and maybe other OSes) hosts - 'cubrid' => 'yii\db\cubrid\Schema', // CUBRID ]; /** * @var string|null Custom PDO wrapper class. If not set, it will use [[PDO]] or [[\yii\db\mssql\PDO]] when MSSQL is used. * @see pdo */ public $pdoClass; - /** - * @var string the class used to create new database [[Command]] objects. If you want to extend the [[Command]] class, - * you may configure this property to use your extended version of the class. - * Since version 2.0.14 [[$commandMap]] is used if this property is set to its default value. - * @see createCommand - * @since 2.0.7 - * @deprecated since 2.0.14. Use [[$commandMap]] for precise configuration. - */ - public $commandClass = 'yii\db\Command'; /** * @var array mapping between PDO driver names and [[Command]] classes. * The keys of the array are PDO driver names while the values are either the corresponding @@ -319,7 +309,6 @@ class Connection extends Component 'oci' => 'yii\db\oci\Command', // Oracle driver 'mssql' => 'yii\db\Command', // older MSSQL driver on MS Windows hosts 'dblib' => 'yii\db\Command', // dblib drivers on GNU/Linux (and maybe other OSes) hosts - 'cubrid' => 'yii\db\Command', // CUBRID ]; /** * @var bool whether to enable [savepoint](https://en.wikipedia.org/wiki/Savepoint). @@ -745,7 +734,7 @@ protected function initConnection() if (!$this->isSybase && in_array($this->getDriverName(), ['mssql', 'dblib'], true)) { $this->pdo->exec('SET ANSI_NULL_DFLT_ON ON'); } - if ($this->charset !== null && in_array($this->getDriverName(), ['pgsql', 'mysql', 'mysqli', 'cubrid'], true)) { + if ($this->charset !== null && in_array($this->getDriverName(), ['pgsql', 'mysql', 'mysqli'], true)) { $this->pdo->exec('SET NAMES ' . $this->pdo->quote($this->charset)); } $this->trigger(self::EVENT_AFTER_OPEN); @@ -761,9 +750,7 @@ public function createCommand($sql = null, $params = []) { $driver = $this->getDriverName(); $config = ['class' => 'yii\db\Command']; - if ($this->commandClass !== $config['class']) { - $config['class'] = $this->commandClass; - } elseif (isset($this->commandMap[$driver])) { + if (isset($this->commandMap[$driver])) { $config = !is_array($this->commandMap[$driver]) ? ['class' => $this->commandMap[$driver]] : $this->commandMap[$driver]; } $config['db'] = $this; diff --git a/db/Migration.php b/db/Migration.php index e9af02dcc..5b864f225 100644 --- a/db/Migration.php +++ b/db/Migration.php @@ -87,7 +87,7 @@ class Migration extends Component implements MigrationInterface public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); $this->db->getSchema()->refresh(); $this->db->enableSlaves = false; } diff --git a/db/Query.php b/db/Query.php index 1819c9c31..f44a1c447 100644 --- a/db/Query.php +++ b/db/Query.php @@ -198,7 +198,7 @@ public function prepare($builder) public function batch($batchSize = 100, $db = null) { return Yii::createObject([ - 'class' => BatchQueryResult::className(), + 'class' => BatchQueryResult::class, 'query' => $this, 'batchSize' => $batchSize, 'db' => $db, @@ -226,7 +226,7 @@ public function batch($batchSize = 100, $db = null) public function each($batchSize = 100, $db = null) { return Yii::createObject([ - 'class' => BatchQueryResult::className(), + 'class' => BatchQueryResult::class, 'query' => $this, 'batchSize' => $batchSize, 'db' => $db, @@ -715,59 +715,6 @@ protected function normalizeSelect($columns) return $select; } - /** - * Returns unique column names excluding duplicates. - * Columns to be removed: - * - if column definition already present in SELECT part with same alias - * - if column definition without alias already present in SELECT part without alias too - * @param array $columns the columns to be merged to the select. - * @since 2.0.14 - * @deprecated in 2.0.21 - */ - protected function getUniqueColumns($columns) - { - $unaliasedColumns = $this->getUnaliasedColumnsFromSelect(); - - $result = []; - foreach ($columns as $columnAlias => $columnDefinition) { - if (!$columnDefinition instanceof Query) { - if (is_string($columnAlias)) { - $existsInSelect = isset($this->select[$columnAlias]) && $this->select[$columnAlias] === $columnDefinition; - if ($existsInSelect) { - continue; - } - } elseif (is_int($columnAlias)) { - $existsInSelect = in_array($columnDefinition, $unaliasedColumns, true); - $existsInResultSet = in_array($columnDefinition, $result, true); - if ($existsInSelect || $existsInResultSet) { - continue; - } - } - } - - $result[$columnAlias] = $columnDefinition; - } - return $result; - } - - /** - * @return array List of columns without aliases from SELECT statement. - * @since 2.0.14 - * @deprecated in 2.0.21 - */ - protected function getUnaliasedColumnsFromSelect() - { - $result = []; - if (is_array($this->select)) { - foreach ($this->select as $name => $value) { - if (is_int($name)) { - $result[] = $value; - } - } - } - return array_unique($result); - } - /** * Sets the value indicating whether to SELECT DISTINCT or not. * @param bool $value whether to SELECT DISTINCT or not. diff --git a/db/QueryBuilder.php b/db/QueryBuilder.php index 9d243abe1..92f97aa9f 100644 --- a/db/QueryBuilder.php +++ b/db/QueryBuilder.php @@ -53,12 +53,6 @@ class QueryBuilder extends \yii\base\BaseObject */ public $typeMap = []; - /** - * @var array map of query condition to builder methods. - * These methods are used by [[buildCondition]] to build SQL conditions from array syntax. - * @deprecated since 2.0.14. Is not used, will be dropped in 2.1.0. - */ - protected $conditionBuilders = []; /** * @var array map of condition aliases to condition classes. For example: * @@ -1610,139 +1604,6 @@ public function createConditionFromArray($condition) return new HashCondition($condition); } - /** - * Creates a condition based on column-value pairs. - * @param array $condition the condition specification. - * @param array $params the binding parameters to be populated - * @return string the generated SQL expression - * @deprecated since 2.0.14. Use `buildCondition()` instead. - */ - public function buildHashCondition($condition, &$params) - { - return $this->buildCondition(new HashCondition($condition), $params); - } - - /** - * Connects two or more SQL expressions with the `AND` or `OR` operator. - * @param string $operator the operator to use for connecting the given operands - * @param array $operands the SQL expressions to connect. - * @param array $params the binding parameters to be populated - * @return string the generated SQL expression - * @deprecated since 2.0.14. Use `buildCondition()` instead. - */ - public function buildAndCondition($operator, $operands, &$params) - { - array_unshift($operands, $operator); - return $this->buildCondition($operands, $params); - } - - /** - * Inverts an SQL expressions with `NOT` operator. - * @param string $operator the operator to use for connecting the given operands - * @param array $operands the SQL expressions to connect. - * @param array $params the binding parameters to be populated - * @return string the generated SQL expression - * @throws InvalidArgumentException if wrong number of operands have been given. - * @deprecated since 2.0.14. Use `buildCondition()` instead. - */ - public function buildNotCondition($operator, $operands, &$params) - { - array_unshift($operands, $operator); - return $this->buildCondition($operands, $params); - } - - /** - * Creates an SQL expressions with the `BETWEEN` operator. - * @param string $operator the operator to use (e.g. `BETWEEN` or `NOT BETWEEN`) - * @param array $operands the first operand is the column name. The second and third operands - * describe the interval that column value should be in. - * @param array $params the binding parameters to be populated - * @return string the generated SQL expression - * @throws InvalidArgumentException if wrong number of operands have been given. - * @deprecated since 2.0.14. Use `buildCondition()` instead. - */ - public function buildBetweenCondition($operator, $operands, &$params) - { - array_unshift($operands, $operator); - return $this->buildCondition($operands, $params); - } - - /** - * Creates an SQL expressions with the `IN` operator. - * @param string $operator the operator to use (e.g. `IN` or `NOT IN`) - * @param array $operands the first operand is the column name. If it is an array - * a composite IN condition will be generated. - * The second operand is an array of values that column value should be among. - * If it is an empty array the generated expression will be a `false` value if - * operator is `IN` and empty if operator is `NOT IN`. - * @param array $params the binding parameters to be populated - * @return string the generated SQL expression - * @throws Exception if wrong number of operands have been given. - * @deprecated since 2.0.14. Use `buildCondition()` instead. - */ - public function buildInCondition($operator, $operands, &$params) - { - array_unshift($operands, $operator); - return $this->buildCondition($operands, $params); - } - - /** - * Creates an SQL expressions with the `LIKE` operator. - * @param string $operator the operator to use (e.g. `LIKE`, `NOT LIKE`, `OR LIKE` or `OR NOT LIKE`) - * @param array $operands an array of two or three operands - * - * - The first operand is the column name. - * - The second operand is a single value or an array of values that column value - * should be compared with. If it is an empty array the generated expression will - * be a `false` value if operator is `LIKE` or `OR LIKE`, and empty if operator - * is `NOT LIKE` or `OR NOT LIKE`. - * - An optional third operand can also be provided to specify how to escape special characters - * in the value(s). The operand should be an array of mappings from the special characters to their - * escaped counterparts. If this operand is not provided, a default escape mapping will be used. - * You may use `false` or an empty array to indicate the values are already escaped and no escape - * should be applied. Note that when using an escape mapping (or the third operand is not provided), - * the values will be automatically enclosed within a pair of percentage characters. - * @param array $params the binding parameters to be populated - * @return string the generated SQL expression - * @throws InvalidArgumentException if wrong number of operands have been given. - * @deprecated since 2.0.14. Use `buildCondition()` instead. - */ - public function buildLikeCondition($operator, $operands, &$params) - { - array_unshift($operands, $operator); - return $this->buildCondition($operands, $params); - } - - /** - * Creates an SQL expressions with the `EXISTS` operator. - * @param string $operator the operator to use (e.g. `EXISTS` or `NOT EXISTS`) - * @param array $operands contains only one element which is a [[Query]] object representing the sub-query. - * @param array $params the binding parameters to be populated - * @return string the generated SQL expression - * @throws InvalidArgumentException if the operand is not a [[Query]] object. - * @deprecated since 2.0.14. Use `buildCondition()` instead. - */ - public function buildExistsCondition($operator, $operands, &$params) - { - array_unshift($operands, $operator); - return $this->buildCondition($operands, $params); - } - - /** - * Creates an SQL expressions like `"column" operator value`. - * @param string $operator the operator to use. Anything could be used e.g. `>`, `<=`, etc. - * @param array $operands contains two column names. - * @param array $params the binding parameters to be populated - * @return string the generated SQL expression - * @throws InvalidArgumentException if wrong number of operands have been given. - * @deprecated since 2.0.14. Use `buildCondition()` instead. - */ - public function buildSimpleCondition($operator, $operands, &$params) - { - array_unshift($operands, $operator); - return $this->buildCondition($operands, $params); - } - /** * Creates a SELECT EXISTS() SQL statement. * @param string $rawSql the subquery in a raw form to select from. diff --git a/db/Schema.php b/db/Schema.php index 53c0af988..43e15d99b 100644 --- a/db/Schema.php +++ b/db/Schema.php @@ -313,7 +313,7 @@ public function refreshTableSchema($name) */ public function createQueryBuilder() { - return Yii::createObject(QueryBuilder::className(), [$this->db]); + return Yii::createObject(QueryBuilder::class, [$this->db]); } /** @@ -328,7 +328,7 @@ public function createQueryBuilder() */ public function createColumnSchemaBuilder($type, $length = null) { - return Yii::createObject(ColumnSchemaBuilder::className(), [$type, $length]); + return Yii::createObject(ColumnSchemaBuilder::class, [$type, $length]); } /** @@ -516,6 +516,10 @@ protected function getTableNameParts($name) */ public function quoteColumnName($name) { + if ($name === null) { + return ''; + } + if (strpos($name, '(') !== false || strpos($name, '[[') !== false) { return $name; } diff --git a/db/conditions/ConditionInterface.php b/db/conditions/ConditionInterface.php index fc8146940..96d63548c 100644 --- a/db/conditions/ConditionInterface.php +++ b/db/conditions/ConditionInterface.php @@ -7,7 +7,7 @@ namespace yii\db\conditions; -use yii\base\InvalidParamException; +use InvalidArgumentException; use yii\db\ExpressionInterface; /** @@ -27,7 +27,7 @@ interface ConditionInterface extends ExpressionInterface * @param array $operands array of corresponding operands * * @return $this - * @throws InvalidParamException if input parameters are not suitable for this condition + * @throws InvalidArgumentException if input parameters are not suitable for this condition */ public static function fromArrayDefinition($operator, $operands); } diff --git a/db/cubrid/ColumnSchemaBuilder.php b/db/cubrid/ColumnSchemaBuilder.php deleted file mode 100644 index e3f402b03..000000000 --- a/db/cubrid/ColumnSchemaBuilder.php +++ /dev/null @@ -1,72 +0,0 @@ - - * @since 2.0.8 - */ -class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder -{ - /** - * {@inheritdoc} - */ - protected function buildUnsignedString() - { - return $this->isUnsigned ? ' UNSIGNED' : ''; - } - - /** - * {@inheritdoc} - */ - protected function buildAfterString() - { - return $this->after !== null ? - ' AFTER ' . $this->db->quoteColumnName($this->after) : - ''; - } - - /** - * {@inheritdoc} - */ - protected function buildFirstString() - { - return $this->isFirst ? ' FIRST' : ''; - } - - /** - * {@inheritdoc} - */ - protected function buildCommentString() - { - return $this->comment !== null ? ' COMMENT ' . $this->db->quoteValue($this->comment) : ''; - } - - /** - * {@inheritdoc} - */ - public function __toString() - { - switch ($this->getTypeCategory()) { - case self::CATEGORY_PK: - $format = '{type}{check}{comment}{append}{pos}'; - break; - case self::CATEGORY_NUMERIC: - $format = '{type}{length}{unsigned}{notnull}{unique}{default}{check}{comment}{append}{pos}'; - break; - default: - $format = '{type}{length}{notnull}{unique}{default}{check}{comment}{append}{pos}'; - } - - return $this->buildCompleteString($format); - } -} diff --git a/db/cubrid/QueryBuilder.php b/db/cubrid/QueryBuilder.php deleted file mode 100644 index 72ac4df6e..000000000 --- a/db/cubrid/QueryBuilder.php +++ /dev/null @@ -1,294 +0,0 @@ - - * @since 2.0 - */ -class QueryBuilder extends \yii\db\QueryBuilder -{ - /** - * @var array mapping from abstract column types (keys) to physical column types (values). - */ - public $typeMap = [ - Schema::TYPE_PK => 'int NOT NULL AUTO_INCREMENT PRIMARY KEY', - Schema::TYPE_UPK => 'int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', - Schema::TYPE_BIGPK => 'bigint NOT NULL AUTO_INCREMENT PRIMARY KEY', - Schema::TYPE_UBIGPK => 'bigint UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY', - Schema::TYPE_CHAR => 'char(1)', - Schema::TYPE_STRING => 'varchar(255)', - Schema::TYPE_TEXT => 'varchar', - Schema::TYPE_TINYINT => 'smallint', - Schema::TYPE_SMALLINT => 'smallint', - Schema::TYPE_INTEGER => 'int', - Schema::TYPE_BIGINT => 'bigint', - Schema::TYPE_FLOAT => 'float(7)', - Schema::TYPE_DOUBLE => 'double(15)', - Schema::TYPE_DECIMAL => 'decimal(10,0)', - Schema::TYPE_DATETIME => 'datetime', - Schema::TYPE_TIMESTAMP => 'timestamp', - Schema::TYPE_TIME => 'time', - Schema::TYPE_DATE => 'date', - Schema::TYPE_BINARY => 'blob', - Schema::TYPE_BOOLEAN => 'smallint', - Schema::TYPE_MONEY => 'decimal(19,4)', - ]; - - - /** - * {@inheritdoc} - */ - protected function defaultExpressionBuilders() - { - return array_merge(parent::defaultExpressionBuilders(), [ - 'yii\db\conditions\LikeCondition' => 'yii\db\cubrid\conditions\LikeConditionBuilder', - ]); - } - - /** - * {@inheritdoc} - * @see https://www.cubrid.org/manual/en/9.3.0/sql/query/merge.html - */ - public function upsert($table, $insertColumns, $updateColumns, &$params) - { - /** @var Constraint[] $constraints */ - list($uniqueNames, $insertNames, $updateNames) = $this->prepareUpsertColumns($table, $insertColumns, $updateColumns, $constraints); - if (empty($uniqueNames)) { - return $this->insert($table, $insertColumns, $params); - } - if ($updateNames === []) { - // there are no columns to update - $updateColumns = false; - } - - $onCondition = ['or']; - $quotedTableName = $this->db->quoteTableName($table); - foreach ($constraints as $constraint) { - $constraintCondition = ['and']; - foreach ($constraint->columnNames as $name) { - $quotedName = $this->db->quoteColumnName($name); - $constraintCondition[] = "$quotedTableName.$quotedName=\"EXCLUDED\".$quotedName"; - } - $onCondition[] = $constraintCondition; - } - $on = $this->buildCondition($onCondition, $params); - list(, $placeholders, $values, $params) = $this->prepareInsertValues($table, $insertColumns, $params); - $mergeSql = 'MERGE INTO ' . $this->db->quoteTableName($table) . ' ' - . 'USING (' . (!empty($placeholders) ? 'VALUES (' . implode(', ', $placeholders) . ')' : ltrim($values, ' ')) . ') AS "EXCLUDED" (' . implode(', ', $insertNames) . ') ' - . "ON ($on)"; - $insertValues = []; - foreach ($insertNames as $name) { - $quotedName = $this->db->quoteColumnName($name); - if (strrpos($quotedName, '.') === false) { - $quotedName = '"EXCLUDED".' . $quotedName; - } - $insertValues[] = $quotedName; - } - $insertSql = 'INSERT (' . implode(', ', $insertNames) . ')' - . ' VALUES (' . implode(', ', $insertValues) . ')'; - if ($updateColumns === false) { - return "$mergeSql WHEN NOT MATCHED THEN $insertSql"; - } - - if ($updateColumns === true) { - $updateColumns = []; - foreach ($updateNames as $name) { - $quotedName = $this->db->quoteColumnName($name); - if (strrpos($quotedName, '.') === false) { - $quotedName = '"EXCLUDED".' . $quotedName; - } - $updateColumns[$name] = new Expression($quotedName); - } - } - list($updates, $params) = $this->prepareUpdateSets($table, $updateColumns, $params); - $updateSql = 'UPDATE SET ' . implode(', ', $updates); - return "$mergeSql WHEN MATCHED THEN $updateSql WHEN NOT MATCHED THEN $insertSql"; - } - - /** - * Creates a SQL statement for resetting the sequence value of a table's primary key. - * The sequence will be reset such that the primary key of the next new row inserted - * will have the specified value or 1. - * @param string $tableName the name of the table whose primary key sequence will be reset - * @param mixed $value the value for the primary key of the next new row inserted. If this is not set, - * the next new row's primary key will have a value 1. - * @return string the SQL statement for resetting sequence - * @throws InvalidArgumentException if the table does not exist or there is no sequence associated with the table. - */ - public function resetSequence($tableName, $value = null) - { - $table = $this->db->getTableSchema($tableName); - if ($table !== null && $table->sequenceName !== null) { - $tableName = $this->db->quoteTableName($tableName); - if ($value === null) { - $key = reset($table->primaryKey); - $value = (int) $this->db->createCommand("SELECT MAX(`$key`) FROM " . $this->db->schema->quoteTableName($tableName))->queryScalar() + 1; - } else { - $value = (int) $value; - } - - return 'ALTER TABLE ' . $this->db->schema->quoteTableName($tableName) . " AUTO_INCREMENT=$value;"; - } elseif ($table === null) { - throw new InvalidArgumentException("Table not found: $tableName"); - } - - throw new InvalidArgumentException("There is not sequence associated with table '$tableName'."); - } - - /** - * {@inheritdoc} - */ - public function buildLimit($limit, $offset) - { - $sql = ''; - // limit is not optional in CUBRID - // https://www.cubrid.org/manual/en/9.3.0/sql/query/select.html#limit-clause - // "You can specify a very big integer for row_count to display to the last row, starting from a specific row." - if ($this->hasLimit($limit)) { - $sql = 'LIMIT ' . $limit; - if ($this->hasOffset($offset)) { - $sql .= ' OFFSET ' . $offset; - } - } elseif ($this->hasOffset($offset)) { - $sql = "LIMIT 9223372036854775807 OFFSET $offset"; // 2^63-1 - } - - return $sql; - } - - /** - * {@inheritdoc} - * @since 2.0.8 - */ - public function selectExists($rawSql) - { - return 'SELECT CASE WHEN EXISTS(' . $rawSql . ') THEN 1 ELSE 0 END'; - } - - /** - * {@inheritdoc} - * @see https://www.cubrid.org/manual/en/9.3.0/sql/schema/table.html#drop-index-clause - */ - public function dropIndex($name, $table) - { - /** @var Schema $schema */ - $schema = $this->db->getSchema(); - foreach ($schema->getTableUniques($table) as $unique) { - if ($unique->name === $name) { - return $this->dropUnique($name, $table); - } - } - - return 'DROP INDEX ' . $this->db->quoteTableName($name) . ' ON ' . $this->db->quoteTableName($table); - } - - /** - * {@inheritdoc} - * @throws NotSupportedException this is not supported by CUBRID. - */ - public function addCheck($name, $table, $expression) - { - throw new NotSupportedException(__METHOD__ . ' is not supported by CUBRID.'); - } - - /** - * {@inheritdoc} - * @throws NotSupportedException this is not supported by CUBRID. - */ - public function dropCheck($name, $table) - { - throw new NotSupportedException(__METHOD__ . ' is not supported by CUBRID.'); - } - - /** - * {@inheritdoc} - * @since 2.0.8 - */ - public function addCommentOnColumn($table, $column, $comment) - { - $definition = $this->getColumnDefinition($table, $column); - $definition = trim(preg_replace("/COMMENT '(.*?)'/i", '', $definition)); - - return 'ALTER TABLE ' . $this->db->quoteTableName($table) - . ' CHANGE ' . $this->db->quoteColumnName($column) - . ' ' . $this->db->quoteColumnName($column) - . (empty($definition) ? '' : ' ' . $definition) - . ' COMMENT ' . $this->db->quoteValue($comment); - } - - /** - * {@inheritdoc} - * @since 2.0.8 - */ - public function addCommentOnTable($table, $comment) - { - return 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' COMMENT ' . $this->db->quoteValue($comment); - } - - /** - * {@inheritdoc} - * @since 2.0.8 - */ - public function dropCommentFromColumn($table, $column) - { - return $this->addCommentOnColumn($table, $column, ''); - } - - /** - * {@inheritdoc} - * @since 2.0.8 - */ - public function dropCommentFromTable($table) - { - return $this->addCommentOnTable($table, ''); - } - - - /** - * Gets column definition. - * - * @param string $table table name - * @param string $column column name - * @return string|null the column definition - * @throws Exception in case when table does not contain column - * @since 2.0.8 - */ - private function getColumnDefinition($table, $column) - { - $row = $this->db->createCommand('SHOW CREATE TABLE ' . $this->db->quoteTableName($table))->queryOne(); - if ($row === false) { - throw new Exception("Unable to find column '$column' in table '$table'."); - } - if (isset($row['Create Table'])) { - $sql = $row['Create Table']; - } else { - $row = array_values($row); - $sql = $row[1]; - } - $sql = preg_replace('/^[^(]+\((.*)\).*$/', '\1', $sql); - $sql = str_replace(', [', ",\n[", $sql); - if (preg_match_all('/^\s*\[(.*?)\]\s+(.*?),?$/m', $sql, $matches)) { - foreach ($matches[1] as $i => $c) { - if ($c === $column) { - return $matches[2][$i]; - } - } - } - - return null; - } -} diff --git a/db/cubrid/Schema.php b/db/cubrid/Schema.php deleted file mode 100644 index b50206d4d..000000000 --- a/db/cubrid/Schema.php +++ /dev/null @@ -1,420 +0,0 @@ - - * @since 2.0 - */ -class Schema extends \yii\db\Schema implements ConstraintFinderInterface -{ - use ConstraintFinderTrait; - - /** - * @var array mapping from physical column types (keys) to abstract column types (values) - * Please refer to [CUBRID manual](https://www.cubrid.org/manual/en/9.3.0/sql/datatype.html) for - * details on data types. - */ - public $typeMap = [ - // Numeric data types - 'short' => self::TYPE_SMALLINT, - 'smallint' => self::TYPE_SMALLINT, - 'int' => self::TYPE_INTEGER, - 'integer' => self::TYPE_INTEGER, - 'bigint' => self::TYPE_BIGINT, - 'numeric' => self::TYPE_DECIMAL, - 'decimal' => self::TYPE_DECIMAL, - 'float' => self::TYPE_FLOAT, - 'real' => self::TYPE_FLOAT, - 'double' => self::TYPE_DOUBLE, - 'double precision' => self::TYPE_DOUBLE, - 'monetary' => self::TYPE_MONEY, - // Date/Time data types - 'date' => self::TYPE_DATE, - 'time' => self::TYPE_TIME, - 'timestamp' => self::TYPE_TIMESTAMP, - 'datetime' => self::TYPE_DATETIME, - // String data types - 'char' => self::TYPE_CHAR, - 'varchar' => self::TYPE_STRING, - 'char varying' => self::TYPE_STRING, - 'nchar' => self::TYPE_CHAR, - 'nchar varying' => self::TYPE_STRING, - 'string' => self::TYPE_STRING, - // BLOB/CLOB data types - 'blob' => self::TYPE_BINARY, - 'clob' => self::TYPE_BINARY, - // Bit string data types - 'bit' => self::TYPE_INTEGER, - 'bit varying' => self::TYPE_INTEGER, - // Collection data types (considered strings for now) - 'set' => self::TYPE_STRING, - 'multiset' => self::TYPE_STRING, - 'list' => self::TYPE_STRING, - 'sequence' => self::TYPE_STRING, - 'enum' => self::TYPE_STRING, - ]; - /** - * @var array map of DB errors and corresponding exceptions - * If left part is found in DB error message exception class from the right part is used. - */ - public $exceptionMap = [ - 'Operation would have caused one or more unique constraint violations' => 'yii\db\IntegrityException', - ]; - - /** - * {@inheritdoc} - */ - protected $tableQuoteCharacter = '"'; - - - /** - * {@inheritdoc} - */ - protected function findTableNames($schema = '') - { - $pdo = $this->db->getSlavePdo(true); - $tables = $pdo->cubrid_schema(\PDO::CUBRID_SCH_TABLE); - $tableNames = []; - foreach ($tables as $table) { - // do not list system tables - if ($table['TYPE'] != 0) { - $tableNames[] = $table['NAME']; - } - } - - return $tableNames; - } - - /** - * {@inheritdoc} - */ - protected function loadTableSchema($name) - { - $pdo = $this->db->getSlavePdo(true); - - $tableInfo = $pdo->cubrid_schema(\PDO::CUBRID_SCH_TABLE, $name); - - if (!isset($tableInfo[0]['NAME'])) { - return null; - } - - $table = new TableSchema(); - $table->fullName = $table->name = $tableInfo[0]['NAME']; - - $sql = 'SHOW FULL COLUMNS FROM ' . $this->quoteSimpleTableName($table->name); - $columns = $this->db->createCommand($sql)->queryAll(); - - foreach ($columns as $info) { - $column = $this->loadColumnSchema($info); - $table->columns[$column->name] = $column; - } - - $primaryKeys = $pdo->cubrid_schema(\PDO::CUBRID_SCH_PRIMARY_KEY, $table->name); - foreach ($primaryKeys as $key) { - $column = $table->columns[$key['ATTR_NAME']]; - $column->isPrimaryKey = true; - $table->primaryKey[] = $column->name; - if ($column->autoIncrement) { - $table->sequenceName = ''; - } - } - - $foreignKeys = $pdo->cubrid_schema(\PDO::CUBRID_SCH_IMPORTED_KEYS, $table->name); - foreach ($foreignKeys as $key) { - if (isset($table->foreignKeys[$key['FK_NAME']])) { - $table->foreignKeys[$key['FK_NAME']][$key['FKCOLUMN_NAME']] = $key['PKCOLUMN_NAME']; - } else { - $table->foreignKeys[$key['FK_NAME']] = [ - $key['PKTABLE_NAME'], - $key['FKCOLUMN_NAME'] => $key['PKCOLUMN_NAME'], - ]; - } - } - - return $table; - } - - /** - * {@inheritdoc} - */ - protected function loadTablePrimaryKey($tableName) - { - $primaryKey = $this->db->getSlavePdo(true)->cubrid_schema(\PDO::CUBRID_SCH_PRIMARY_KEY, $tableName); - if (empty($primaryKey)) { - return null; - } - - ArrayHelper::multisort($primaryKey, 'KEY_SEQ', SORT_ASC, SORT_NUMERIC); - return new Constraint([ - 'name' => $primaryKey[0]['KEY_NAME'], - 'columnNames' => ArrayHelper::getColumn($primaryKey, 'ATTR_NAME'), - ]); - } - - /** - * {@inheritdoc} - */ - protected function loadTableForeignKeys($tableName) - { - static $actionTypes = [ - 0 => 'CASCADE', - 1 => 'RESTRICT', - 2 => 'NO ACTION', - 3 => 'SET NULL', - ]; - - $foreignKeys = $this->db->getSlavePdo(true)->cubrid_schema(\PDO::CUBRID_SCH_IMPORTED_KEYS, $tableName); - $foreignKeys = ArrayHelper::index($foreignKeys, null, 'FK_NAME'); - ArrayHelper::multisort($foreignKeys, 'KEY_SEQ', SORT_ASC, SORT_NUMERIC); - $result = []; - foreach ($foreignKeys as $name => $foreignKey) { - $result[] = new ForeignKeyConstraint([ - 'name' => $name, - 'columnNames' => ArrayHelper::getColumn($foreignKey, 'FKCOLUMN_NAME'), - 'foreignTableName' => $foreignKey[0]['PKTABLE_NAME'], - 'foreignColumnNames' => ArrayHelper::getColumn($foreignKey, 'PKCOLUMN_NAME'), - 'onDelete' => isset($actionTypes[$foreignKey[0]['DELETE_RULE']]) ? $actionTypes[$foreignKey[0]['DELETE_RULE']] : null, - 'onUpdate' => isset($actionTypes[$foreignKey[0]['UPDATE_RULE']]) ? $actionTypes[$foreignKey[0]['UPDATE_RULE']] : null, - ]); - } - - return $result; - } - - /** - * {@inheritdoc} - */ - protected function loadTableIndexes($tableName) - { - return $this->loadTableConstraints($tableName, 'indexes'); - } - - /** - * {@inheritdoc} - */ - protected function loadTableUniques($tableName) - { - return $this->loadTableConstraints($tableName, 'uniques'); - } - - /** - * {@inheritdoc} - * @throws NotSupportedException if this method is called. - */ - protected function loadTableChecks($tableName) - { - throw new NotSupportedException('CUBRID does not support check constraints.'); - } - - /** - * {@inheritdoc} - * @throws NotSupportedException if this method is called. - */ - protected function loadTableDefaultValues($tableName) - { - throw new NotSupportedException('CUBRID does not support default value constraints.'); - } - - /** - * {@inheritdoc} - */ - public function releaseSavepoint($name) - { - // does nothing as cubrid does not support this - } - - /** - * Creates a query builder for the CUBRID database. - * @return QueryBuilder query builder instance - */ - public function createQueryBuilder() - { - return Yii::createObject(QueryBuilder::className(), [$this->db]); - } - - /** - * Loads the column information into a [[ColumnSchema]] object. - * @param array $info column information - * @return \yii\db\ColumnSchema the column schema object - */ - protected function loadColumnSchema($info) - { - $column = $this->createColumnSchema(); - - $column->name = $info['Field']; - $column->allowNull = $info['Null'] === 'YES'; - $column->isPrimaryKey = false; // primary key will be set by loadTableSchema() later - $column->autoIncrement = stripos($info['Extra'], 'auto_increment') !== false; - - $column->dbType = $info['Type']; - $column->unsigned = strpos($column->dbType, 'unsigned') !== false; - - $column->type = self::TYPE_STRING; - if (preg_match('/^([\w ]+)(?:\(([^\)]+)\))?$/', $column->dbType, $matches)) { - $type = strtolower($matches[1]); - $column->dbType = $type . (isset($matches[2]) ? "({$matches[2]})" : ''); - if (isset($this->typeMap[$type])) { - $column->type = $this->typeMap[$type]; - } - if (!empty($matches[2])) { - if ($type === 'enum') { - $values = preg_split('/\s*,\s*/', $matches[2]); - foreach ($values as $i => $value) { - $values[$i] = trim($value, "'"); - } - $column->enumValues = $values; - } else { - $values = explode(',', $matches[2]); - $column->size = $column->precision = (int) $values[0]; - if (isset($values[1])) { - $column->scale = (int) $values[1]; - } - if ($column->size === 1 && $type === 'bit') { - $column->type = 'boolean'; - } elseif ($type === 'bit') { - if ($column->size > 32) { - $column->type = 'bigint'; - } elseif ($column->size === 32) { - $column->type = 'integer'; - } - } - } - } - } - - $column->phpType = $this->getColumnPhpType($column); - - if ($column->isPrimaryKey) { - return $column; - } - - if ( - $column->type === 'timestamp' && $info['Default'] === 'SYS_TIMESTAMP' || - $column->type === 'datetime' && $info['Default'] === 'SYS_DATETIME' || - $column->type === 'date' && $info['Default'] === 'SYS_DATE' || - $column->type === 'time' && $info['Default'] === 'SYS_TIME' - ) { - $column->defaultValue = new Expression($info['Default']); - } elseif (isset($type) && $type === 'bit') { - $column->defaultValue = hexdec(trim($info['Default'], 'X\'')); - } else { - $column->defaultValue = $column->phpTypecast($info['Default']); - } - - return $column; - } - - /** - * Determines the PDO type for the given PHP data value. - * @param mixed $data the data whose PDO type is to be determined - * @return int the PDO type - * @see https://www.php.net/manual/en/pdo.constants.php - */ - public function getPdoType($data) - { - static $typeMap = [ - // php type => PDO type - 'boolean' => \PDO::PARAM_INT, // PARAM_BOOL is not supported by CUBRID PDO - 'integer' => \PDO::PARAM_INT, - 'string' => \PDO::PARAM_STR, - 'resource' => \PDO::PARAM_LOB, - 'NULL' => \PDO::PARAM_NULL, - ]; - $type = gettype($data); - - return isset($typeMap[$type]) ? $typeMap[$type] : \PDO::PARAM_STR; - } - - /** - * {@inheritdoc} - * @see https://www.cubrid.org/manual/en/9.3.0/sql/transaction.html#database-concurrency - */ - public function setTransactionIsolationLevel($level) - { - // translate SQL92 levels to CUBRID levels: - switch ($level) { - case Transaction::SERIALIZABLE: - $level = '6'; // SERIALIZABLE - break; - case Transaction::REPEATABLE_READ: - $level = '5'; // REPEATABLE READ CLASS with REPEATABLE READ INSTANCES - break; - case Transaction::READ_COMMITTED: - $level = '4'; // REPEATABLE READ CLASS with READ COMMITTED INSTANCES - break; - case Transaction::READ_UNCOMMITTED: - $level = '3'; // REPEATABLE READ CLASS with READ UNCOMMITTED INSTANCES - break; - } - parent::setTransactionIsolationLevel($level); - } - - /** - * {@inheritdoc} - */ - public function createColumnSchemaBuilder($type, $length = null) - { - return new ColumnSchemaBuilder($type, $length, $this->db); - } - - /** - * Loads multiple types of constraints and returns the specified ones. - * @param string $tableName table name. - * @param string $returnType return type: - * - indexes - * - uniques - * @return mixed constraints. - */ - private function loadTableConstraints($tableName, $returnType) - { - $constraints = $this->db->getSlavePdo(true)->cubrid_schema(\PDO::CUBRID_SCH_CONSTRAINT, $tableName); - $constraints = ArrayHelper::index($constraints, null, ['TYPE', 'NAME']); - ArrayHelper::multisort($constraints, 'KEY_ORDER', SORT_ASC, SORT_NUMERIC); - $result = [ - 'indexes' => [], - 'uniques' => [], - ]; - foreach ($constraints as $type => $names) { - foreach ($names as $name => $constraint) { - $isUnique = in_array((int) $type, [0, 2], true); - $result['indexes'][] = new IndexConstraint([ - 'isPrimary' => (bool) $constraint[0]['PRIMARY_KEY'], - 'isUnique' => $isUnique, - 'name' => $name, - 'columnNames' => ArrayHelper::getColumn($constraint, 'ATTR_NAME'), - ]); - if ($isUnique) { - $result['uniques'][] = new Constraint([ - 'name' => $name, - 'columnNames' => ArrayHelper::getColumn($constraint, 'ATTR_NAME'), - ]); - } - } - } - foreach ($result as $type => $data) { - $this->setTableMetadata($tableName, $type, $data); - } - - return $result[$returnType]; - } -} diff --git a/db/cubrid/conditions/LikeConditionBuilder.php b/db/cubrid/conditions/LikeConditionBuilder.php deleted file mode 100644 index 80cd27173..000000000 --- a/db/cubrid/conditions/LikeConditionBuilder.php +++ /dev/null @@ -1,29 +0,0 @@ - '!%', - '_' => '!_', - '!' => '!!', - ]; -} diff --git a/db/mssql/QueryBuilder.php b/db/mssql/QueryBuilder.php index 1605e4452..f17817f85 100644 --- a/db/mssql/QueryBuilder.php +++ b/db/mssql/QueryBuilder.php @@ -430,17 +430,6 @@ protected function getAllColumnNames($modelClass = null) return array_keys($schema->columns); } - /** - * @return bool whether the version of the MSSQL being used is older than 2012. - * @throws \yii\base\InvalidConfigException - * @throws \yii\db\Exception - * @deprecated 2.0.14 Use [[Schema::getServerVersion]] with [[\version_compare()]]. - */ - protected function isOldMssql() - { - return version_compare($this->db->getSchema()->getServerVersion(), '11', '<'); - } - /** * {@inheritdoc} * @since 2.0.8 diff --git a/db/mssql/Schema.php b/db/mssql/Schema.php index 1b1fb267e..a8d6045d5 100644 --- a/db/mssql/Schema.php +++ b/db/mssql/Schema.php @@ -332,7 +332,7 @@ public function rollBackSavepoint($name) */ public function createQueryBuilder() { - return Yii::createObject(QueryBuilder::className(), [$this->db]); + return Yii::createObject(QueryBuilder::class, [$this->db]); } /** @@ -387,10 +387,11 @@ protected function loadColumnSchema($info) $column->isComputed = (bool)$info['is_computed']; $column->unsigned = stripos($column->dbType, 'unsigned') !== false; $column->comment = $info['comment'] === null ? '' : $info['comment']; - $column->type = self::TYPE_STRING; + if (preg_match('/^(\w+)(?:\(([^\)]+)\))?/', $column->dbType, $matches)) { $type = $matches[1]; + if (isset($this->typeMap[$type])) { $column->type = $this->typeMap[$type]; } @@ -821,6 +822,6 @@ public function insert($table, $columns) */ public function createColumnSchemaBuilder($type, $length = null) { - return Yii::createObject(ColumnSchemaBuilder::className(), [$type, $length, $this->db]); + return Yii::createObject(ColumnSchemaBuilder::class, [$type, $length, $this->db]); } } diff --git a/db/mysql/ColumnSchema.php b/db/mysql/ColumnSchema.php index ca9c48703..074335688 100644 --- a/db/mysql/ColumnSchema.php +++ b/db/mysql/ColumnSchema.php @@ -18,17 +18,6 @@ */ class ColumnSchema extends \yii\db\ColumnSchema { - /** - * @var bool whether the column schema should OMIT using JSON support feature. - * You can use this property to make upgrade to Yii 2.0.14 easier. - * Default to `false`, meaning JSON support is enabled. - * - * @since 2.0.14.1 - * @deprecated Since 2.0.14.1 and will be removed in 2.1. - */ - public $disableJsonSupport = false; - - /** * {@inheritdoc} */ @@ -42,7 +31,7 @@ public function dbTypecast($value) return $value; } - if (!$this->disableJsonSupport && $this->dbType === Schema::TYPE_JSON) { + if ($this->dbType === Schema::TYPE_JSON) { return new JsonExpression($value, $this->type); } @@ -58,7 +47,7 @@ public function phpTypecast($value) return null; } - if (!$this->disableJsonSupport && $this->type === Schema::TYPE_JSON) { + if ($this->type === Schema::TYPE_JSON) { return json_decode($value, true); } diff --git a/db/mysql/Schema.php b/db/mysql/Schema.php index 5e0fd9e21..4c47aadeb 100644 --- a/db/mysql/Schema.php +++ b/db/mysql/Schema.php @@ -258,7 +258,7 @@ protected function loadTableDefaultValues($tableName) */ public function createQueryBuilder() { - return Yii::createObject(QueryBuilder::className(), [$this->db]); + return Yii::createObject(QueryBuilder::class, [$this->db]); } /** @@ -519,7 +519,7 @@ public function findUniqueIndexes($table) */ public function createColumnSchemaBuilder($type, $length = null) { - return Yii::createObject(ColumnSchemaBuilder::className(), [$type, $length, $this->db]); + return Yii::createObject(ColumnSchemaBuilder::class, [$type, $length, $this->db]); } /** diff --git a/db/oci/Schema.php b/db/oci/Schema.php index e0e4c05e2..05b3cb5ea 100644 --- a/db/oci/Schema.php +++ b/db/oci/Schema.php @@ -262,7 +262,7 @@ public function quoteSimpleTableName($name) */ public function createQueryBuilder() { - return Yii::createObject(QueryBuilder::className(), [$this->db]); + return Yii::createObject(QueryBuilder::class, [$this->db]); } /** @@ -270,7 +270,7 @@ public function createQueryBuilder() */ public function createColumnSchemaBuilder($type, $length = null) { - return Yii::createObject(ColumnSchemaBuilder::className(), [$type, $length]); + return Yii::createObject(ColumnSchemaBuilder::class, [$type, $length]); } /** diff --git a/db/pgsql/ColumnSchema.php b/db/pgsql/ColumnSchema.php index 33d97bbdf..271c5f30c 100644 --- a/db/pgsql/ColumnSchema.php +++ b/db/pgsql/ColumnSchema.php @@ -22,33 +22,6 @@ class ColumnSchema extends \yii\db\ColumnSchema * @var int the dimension of array. Defaults to 0, means this column is not an array. */ public $dimension = 0; - /** - * @var bool whether the column schema should OMIT using JSON support feature. - * You can use this property to make upgrade to Yii 2.0.14 easier. - * Default to `false`, meaning JSON support is enabled. - * - * @since 2.0.14.1 - * @deprecated Since 2.0.14.1 and will be removed in 2.1. - */ - public $disableJsonSupport = false; - /** - * @var bool whether the column schema should OMIT using PgSQL Arrays support feature. - * You can use this property to make upgrade to Yii 2.0.14 easier. - * Default to `false`, meaning Arrays support is enabled. - * - * @since 2.0.14.1 - * @deprecated Since 2.0.14.1 and will be removed in 2.1. - */ - public $disableArraySupport = false; - /** - * @var bool whether the Array column value should be unserialized to an [[ArrayExpression]] object. - * You can use this property to make upgrade to Yii 2.0.14 easier. - * Default to `true`, meaning arrays are unserialized to [[ArrayExpression]] objects. - * - * @since 2.0.14.1 - * @deprecated Since 2.0.14.1 and will be removed in 2.1. - */ - public $deserializeArrayColumnToArrayExpression = true; /** * @var string name of associated sequence if column is auto-incremental * @since 2.0.29 @@ -70,11 +43,9 @@ public function dbTypecast($value) } if ($this->dimension > 0) { - return $this->disableArraySupport - ? (string) $value - : new ArrayExpression($value, $this->dbType, $this->dimension); + return new ArrayExpression($value, $this->dbType, $this->dimension); } - if (!$this->disableJsonSupport && in_array($this->dbType, [Schema::TYPE_JSON, Schema::TYPE_JSONB], true)) { + if (in_array($this->dbType, [Schema::TYPE_JSON, Schema::TYPE_JSONB], true)) { return new JsonExpression($value, $this->dbType); } @@ -87,9 +58,6 @@ public function dbTypecast($value) public function phpTypecast($value) { if ($this->dimension > 0) { - if ($this->disableArraySupport) { - return $value; - } if (!is_array($value)) { $value = $this->getArrayParser()->parse($value); } @@ -101,9 +69,7 @@ public function phpTypecast($value) return null; } - return $this->deserializeArrayColumnToArrayExpression - ? new ArrayExpression($value, $this->dbType, $this->dimension) - : $value; + return $value; } return $this->phpTypecastValue($value); @@ -133,7 +99,7 @@ protected function phpTypecastValue($value) } return (bool) $value; case Schema::TYPE_JSON: - return $this->disableJsonSupport ? $value : json_decode($value, true); + return json_decode($value, true); } return parent::phpTypecast($value); diff --git a/db/pgsql/Schema.php b/db/pgsql/Schema.php index 46547318b..62f91dac5 100644 --- a/db/pgsql/Schema.php +++ b/db/pgsql/Schema.php @@ -289,7 +289,7 @@ protected function loadTableDefaultValues($tableName) */ public function createQueryBuilder() { - return Yii::createObject(QueryBuilder::className(), [$this->db]); + return Yii::createObject(QueryBuilder::class, [$this->db]); } /** diff --git a/db/sqlite/Schema.php b/db/sqlite/Schema.php index 32b209b22..2ff7ba835 100644 --- a/db/sqlite/Schema.php +++ b/db/sqlite/Schema.php @@ -207,7 +207,7 @@ protected function loadTableDefaultValues($tableName) */ public function createQueryBuilder() { - return Yii::createObject(QueryBuilder::className(), [$this->db]); + return Yii::createObject(QueryBuilder::class, [$this->db]); } /** @@ -216,7 +216,7 @@ public function createQueryBuilder() */ public function createColumnSchemaBuilder($type, $length = null) { - return Yii::createObject(ColumnSchemaBuilder::className(), [$type, $length]); + return Yii::createObject(ColumnSchemaBuilder::class, [$type, $length]); } /** diff --git a/filters/AccessControl.php b/filters/AccessControl.php index 7ec2c5e55..a648feb77 100644 --- a/filters/AccessControl.php +++ b/filters/AccessControl.php @@ -99,7 +99,7 @@ public function init() { parent::init(); if ($this->user !== false) { - $this->user = Instance::ensure($this->user, User::className()); + $this->user = Instance::ensure($this->user, User::class); } foreach ($this->rules as $i => $rule) { if (is_array($rule)) { diff --git a/grid/GridView.php b/grid/GridView.php index 7ee0e06bb..8b5afefe7 100644 --- a/grid/GridView.php +++ b/grid/GridView.php @@ -547,7 +547,7 @@ protected function initColumns() $column = $this->createDataColumn($column); } else { $column = Yii::createObject(array_merge([ - 'class' => $this->dataColumnClass ?: DataColumn::className(), + 'class' => $this->dataColumnClass ?: DataColumn::class, 'grid' => $this, ], $column)); } @@ -572,7 +572,7 @@ protected function createDataColumn($text) } return Yii::createObject([ - 'class' => $this->dataColumnClass ?: DataColumn::className(), + 'class' => $this->dataColumnClass ?: DataColumn::class, 'grid' => $this, 'attribute' => $matches[1], 'format' => isset($matches[3]) ? $matches[3] : 'text', diff --git a/i18n/DbMessageSource.php b/i18n/DbMessageSource.php index e7934be35..9630699f0 100644 --- a/i18n/DbMessageSource.php +++ b/i18n/DbMessageSource.php @@ -38,12 +38,6 @@ */ class DbMessageSource extends MessageSource { - /** - * Prefix which would be used when generating cache key. - * @deprecated This constant has never been used and will be removed in 2.1.0. - */ - const CACHE_KEY_PREFIX = 'DbMessageSource'; - /** * @var Connection|array|string the DB connection object or the application component ID of the DB connection. * @@ -95,7 +89,7 @@ class DbMessageSource extends MessageSource public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); if ($this->enableCaching) { $this->cache = Instance::ensure($this->cache, 'yii\caching\CacheInterface'); } diff --git a/log/DbTarget.php b/log/DbTarget.php index d32c292c4..dadb08f4d 100644 --- a/log/DbTarget.php +++ b/log/DbTarget.php @@ -52,7 +52,7 @@ class DbTarget extends Target public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); } /** diff --git a/log/FileTarget.php b/log/FileTarget.php index d860c4014..8b9851901 100644 --- a/log/FileTarget.php +++ b/log/FileTarget.php @@ -20,9 +20,6 @@ * files are moved backwards by one place, i.e., '.2' to '.3', '.1' to '.2', and so on. * The property [[maxLogFiles]] specifies how many history files to keep. * - * Since 2.0.46 rotation of the files is done only by copy and the - * `rotateByCopy` property is deprecated. - * * @author Qiang Xue * @since 2.0 */ @@ -61,22 +58,6 @@ class FileTarget extends Target * but read-only for other users. */ public $dirMode = 0775; - /** - * @var bool Whether to rotate log files by copy and truncate in contrast to rotation by - * renaming files. Defaults to `true` to be more compatible with log tailers and windows - * systems which do not play well with rename on open files. Rotation by renaming however is - * a bit faster. - * - * The problem with windows systems where the [rename()](https://www.php.net/manual/en/function.rename.php) - * function does not work with files that are opened by some process is described in a - * [comment by Martin Pelletier](https://www.php.net/manual/en/function.rename.php#102274) in - * the PHP documentation. By setting rotateByCopy to `true` you can work - * around this. - * @deprecated since 2.0.46 and setting it to false has no effect anymore - * since rotating is now always done by copy. - */ - public $rotateByCopy = true; - /** * Initializes the route. diff --git a/mail/BaseMailer.php b/mail/BaseMailer.php index c5f76fb75..e334d74aa 100644 --- a/mail/BaseMailer.php +++ b/mail/BaseMailer.php @@ -142,7 +142,7 @@ public function getView() protected function createView(array $config) { if (!array_key_exists('class', $config)) { - $config['class'] = View::className(); + $config['class'] = View::class; } return Yii::createObject($config); diff --git a/mutex/DbMutex.php b/mutex/DbMutex.php index 593cff4e0..a19a1adf8 100644 --- a/mutex/DbMutex.php +++ b/mutex/DbMutex.php @@ -37,6 +37,6 @@ abstract class DbMutex extends Mutex public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); } } diff --git a/package.json b/package.json new file mode 100644 index 000000000..09a66d2bc --- /dev/null +++ b/package.json @@ -0,0 +1,20 @@ +{ + "name": "yii2", + "description": "a modern PHP framework designed for professional Web development", + "dependencies": { + "inputmask": "^5.0.8", + "jquery-pjax": "^2.0.1", + "jquery": "~3.6.4", + "punycode": "^1.4.0", + "yii2-pjax": "^2.0.8" + }, + "keywords": [ + "php", + "framework" + ], + "license": "BSD-3-Clause", + "bugs": { + "url": "https://github.com/yiisoft/yii2/issues" + }, + "homepage": "https://github.com/yiisoft/yii2" +} diff --git a/rbac/CheckAccessInterface.php b/rbac/CheckAccessInterface.php index 38d86ee7a..7f4dce00b 100644 --- a/rbac/CheckAccessInterface.php +++ b/rbac/CheckAccessInterface.php @@ -23,7 +23,7 @@ interface CheckAccessInterface * @param array $params name-value pairs that will be passed to the rules associated * with the roles and permissions assigned to the user. * @return bool whether the user has the specified permission. - * @throws \yii\base\InvalidParamException if $permissionName does not refer to an existing permission + * @throws \yii\base\InvalidArgumentException if $permissionName does not refer to an existing permission */ public function checkAccess($userId, $permissionName, $params = []); } diff --git a/rbac/DbManager.php b/rbac/DbManager.php index 2685ad5a1..240914838 100644 --- a/rbac/DbManager.php +++ b/rbac/DbManager.php @@ -119,7 +119,7 @@ class DbManager extends BaseManager public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); if ($this->cache !== null) { $this->cache = Instance::ensure($this->cache, 'yii\caching\CacheInterface'); } @@ -449,7 +449,7 @@ protected function getItems($type) */ protected function populateItem($row) { - $class = $row['type'] == Item::TYPE_PERMISSION ? Permission::className() : Role::className(); + $class = $row['type'] == Item::TYPE_PERMISSION ? Permission::class : Role::class; if (!isset($row['data']) || ($data = @unserialize(is_resource($row['data']) ? stream_get_contents($row['data']) : $row['data'])) === false) { $data = null; diff --git a/rbac/ManagerInterface.php b/rbac/ManagerInterface.php index e4d2c7029..fec06fdc0 100644 --- a/rbac/ManagerInterface.php +++ b/rbac/ManagerInterface.php @@ -83,7 +83,7 @@ public function getRolesByUser($userId); * @param string $roleName name of the role to file child roles for * @return Role[] Child roles. The array is indexed by the role names. * First element is an instance of the parent Role itself. - * @throws \yii\base\InvalidParamException if Role was not found that are getting by $roleName + * @throws \yii\base\InvalidArgumentException if Role was not found that are getting by $roleName * @since 2.0.10 */ public function getChildRoles($roleName); diff --git a/rbac/PhpManager.php b/rbac/PhpManager.php index 291d72976..9411a7f93 100644 --- a/rbac/PhpManager.php +++ b/rbac/PhpManager.php @@ -724,7 +724,7 @@ protected function load() $rules = $this->loadFromFile($this->ruleFile); foreach ($items as $name => $item) { - $class = $item['type'] == Item::TYPE_PERMISSION ? Permission::className() : Role::className(); + $class = $item['type'] == Item::TYPE_PERMISSION ? Permission::class : Role::class; $this->items[$name] = new $class([ 'name' => $name, diff --git a/rest/Controller.php b/rest/Controller.php index 9512ee75e..3705417ac 100644 --- a/rest/Controller.php +++ b/rest/Controller.php @@ -49,21 +49,21 @@ public function behaviors() { return [ 'contentNegotiator' => [ - 'class' => ContentNegotiator::className(), + 'class' => ContentNegotiator::class, 'formats' => [ 'application/json' => Response::FORMAT_JSON, 'application/xml' => Response::FORMAT_XML, ], ], 'verbFilter' => [ - 'class' => VerbFilter::className(), + 'class' => VerbFilter::class, 'actions' => $this->verbs(), ], 'authenticator' => [ - 'class' => CompositeAuth::className(), + 'class' => CompositeAuth::class, ], 'rateLimiter' => [ - 'class' => RateLimiter::className(), + 'class' => RateLimiter::class, ], ]; } diff --git a/rest/IndexAction.php b/rest/IndexAction.php index 81b19cab7..ab3e53293 100644 --- a/rest/IndexAction.php +++ b/rest/IndexAction.php @@ -183,7 +183,7 @@ protected function prepareDataProvider() } return Yii::createObject([ - 'class' => ActiveDataProvider::className(), + 'class' => ActiveDataProvider::class, 'query' => $query, 'pagination' => $pagination, 'sort' => $sort, diff --git a/rest/UrlRule.php b/rest/UrlRule.php index 48b1bbe79..8f32e32c4 100644 --- a/rest/UrlRule.php +++ b/rest/UrlRule.php @@ -233,7 +233,7 @@ public function parseRequest($manager, $request) Yii::debug([ 'rule' => method_exists($rule, '__toString') ? $rule->__toString() : get_class($rule), 'match' => $result !== false, - 'parent' => self::className(), + 'parent' => self::class, ], __METHOD__); } if ($result !== false) { diff --git a/test/DbFixture.php b/test/DbFixture.php index d5a6322f9..0a9b090e9 100644 --- a/test/DbFixture.php +++ b/test/DbFixture.php @@ -38,6 +38,6 @@ abstract class DbFixture extends Fixture public function init() { parent::init(); - $this->db = Instance::ensure($this->db, BaseObject::className()); + $this->db = Instance::ensure($this->db, BaseObject::class); } } diff --git a/validators/PunycodeAsset.php b/validators/PunycodeAsset.php index 8d928838c..0e5917a5b 100644 --- a/validators/PunycodeAsset.php +++ b/validators/PunycodeAsset.php @@ -17,7 +17,7 @@ */ class PunycodeAsset extends AssetBundle { - public $sourcePath = '@bower/punycode'; + public $sourcePath = '@npm/punycode'; public $js = [ 'punycode.js', ]; diff --git a/validators/UniqueValidator.php b/validators/UniqueValidator.php index 74edcfd66..dadc8b4ed 100644 --- a/validators/UniqueValidator.php +++ b/validators/UniqueValidator.php @@ -189,7 +189,11 @@ private function modelExists($targetClass, $conditions, $model) /** @var ActiveRecordInterface|\yii\base\BaseObject $targetClass $query */ $query = $this->prepareQuery($targetClass, $conditions); - if (!$model instanceof ActiveRecordInterface || $model->getIsNewRecord() || $model::className() !== $targetClass::className()) { + if ( + !$model instanceof ActiveRecordInterface || + $model->getIsNewRecord() || + !$model instanceof $targetClass + ) { // if current $model isn't in the database yet, then it's OK just to call exists() // also there's no need to run check based on primary keys, when $targetClass is not the same as $model's class $exists = $query->exists(); diff --git a/web/AssetManager.php b/web/AssetManager.php index 2eceddb4d..c8fe7e4c8 100644 --- a/web/AssetManager.php +++ b/web/AssetManager.php @@ -412,10 +412,10 @@ protected function resolveAsset($bundle, $asset) public function getConverter() { if ($this->_converter === null) { - $this->_converter = Yii::createObject(AssetConverter::className()); + $this->_converter = Yii::createObject(AssetConverter::class); } elseif (is_array($this->_converter) || is_string($this->_converter)) { if (is_array($this->_converter) && !isset($this->_converter['class'])) { - $this->_converter['class'] = AssetConverter::className(); + $this->_converter['class'] = AssetConverter::class; } $this->_converter = Yii::createObject($this->_converter); } diff --git a/web/CompositeUrlRule.php b/web/CompositeUrlRule.php index 30d08e189..f43cbcbbc 100644 --- a/web/CompositeUrlRule.php +++ b/web/CompositeUrlRule.php @@ -60,7 +60,7 @@ public function parseRequest($manager, $request) Yii::debug([ 'rule' => method_exists($rule, '__toString') ? $rule->__toString() : get_class($rule), 'match' => $result !== false, - 'parent' => self::className(), + 'parent' => self::class, ], __METHOD__); } if ($result !== false) { diff --git a/web/DbSession.php b/web/DbSession.php index 1ef79cb7c..b2e48b9ef 100644 --- a/web/DbSession.php +++ b/web/DbSession.php @@ -90,7 +90,7 @@ class DbSession extends MultiFieldSession public function init() { parent::init(); - $this->db = Instance::ensure($this->db, Connection::className()); + $this->db = Instance::ensure($this->db, Connection::class); } /** diff --git a/web/ErrorHandler.php b/web/ErrorHandler.php index 570a84b41..201eaef9d 100644 --- a/web/ErrorHandler.php +++ b/web/ErrorHandler.php @@ -487,7 +487,7 @@ public function argumentsToString($args) */ public function getExceptionName($exception) { - if ($exception instanceof \yii\base\Exception || $exception instanceof \yii\base\InvalidCallException || $exception instanceof \yii\base\InvalidParamException || $exception instanceof \yii\base\UnknownMethodException) { + if ($exception instanceof \yii\base\Exception || $exception instanceof \yii\base\InvalidCallException || $exception instanceof \yii\base\InvalidArgumentException || $exception instanceof \yii\base\UnknownMethodException) { return $exception->getName(); } diff --git a/web/JqueryAsset.php b/web/JqueryAsset.php index df365d768..e7a534671 100644 --- a/web/JqueryAsset.php +++ b/web/JqueryAsset.php @@ -15,7 +15,7 @@ */ class JqueryAsset extends AssetBundle { - public $sourcePath = '@bower/jquery/dist'; + public $sourcePath = '@npm/jquery/dist'; public $js = [ 'jquery.js', ]; diff --git a/web/Request.php b/web/Request.php index 7b9645d53..c795c6b43 100644 --- a/web/Request.php +++ b/web/Request.php @@ -95,11 +95,6 @@ class Request extends \yii\base\Request * Default name of the HTTP header for sending CSRF token. */ const CSRF_HEADER = 'X-CSRF-Token'; - /** - * The length of the CSRF token mask. - * @deprecated since 2.0.12. The mask length is now equal to the token length. - */ - const CSRF_MASK_LENGTH = 8; /** * @var bool whether to enable CSRF (Cross-Site Request Forgery) validation. Defaults to true. diff --git a/web/UrlManager.php b/web/UrlManager.php index 71c38f85d..1244a6cbb 100644 --- a/web/UrlManager.php +++ b/web/UrlManager.php @@ -178,7 +178,7 @@ public function init() if ($this->normalizer !== false) { $this->normalizer = Yii::createObject($this->normalizer); if (!$this->normalizer instanceof UrlNormalizer) { - throw new InvalidConfigException('`' . get_class($this) . '::normalizer` should be an instance of `' . UrlNormalizer::className() . '` or its DI compatible configuration.'); + throw new InvalidConfigException('`' . get_class($this) . '::normalizer` should be an instance of `' . UrlNormalizer::class . '` or its DI compatible configuration.'); } } diff --git a/web/UrlRule.php b/web/UrlRule.php index fbbf6ffe1..170a2f24c 100644 --- a/web/UrlRule.php +++ b/web/UrlRule.php @@ -195,7 +195,7 @@ public function init() throw new InvalidConfigException('UrlRule::route must be set.'); } if (is_array($this->normalizer)) { - $normalizerConfig = array_merge(['class' => UrlNormalizer::className()], $this->normalizer); + $normalizerConfig = array_merge(['class' => UrlNormalizer::class], $this->normalizer); $this->normalizer = Yii::createObject($normalizerConfig); } if ($this->normalizer !== null && $this->normalizer !== false && !$this->normalizer instanceof UrlNormalizer) { diff --git a/web/User.php b/web/User.php index 7b075ed49..0488014a8 100644 --- a/web/User.php +++ b/web/User.php @@ -789,20 +789,6 @@ public function checkRedirectAcceptable() return false; } - /** - * Returns auth manager associated with the user component. - * - * By default this is the `authManager` application component. - * You may override this method to return a different auth manager instance if needed. - * @return \yii\rbac\ManagerInterface - * @since 2.0.6 - * @deprecated since version 2.0.9, to be removed in 2.1. Use [[getAccessChecker()]] instead. - */ - protected function getAuthManager() - { - return Yii::$app->getAuthManager(); - } - /** * Returns the access checker used for checking access. * @return CheckAccessInterface @@ -810,6 +796,6 @@ protected function getAuthManager() */ protected function getAccessChecker() { - return $this->accessChecker !== null ? $this->accessChecker : $this->getAuthManager(); + return $this->accessChecker !== null ? $this->accessChecker : Yii::$app->getAuthManager(); } } diff --git a/web/View.php b/web/View.php index bd730475d..a1c09ea68 100644 --- a/web/View.php +++ b/web/View.php @@ -558,7 +558,7 @@ private function registerFile($type, $url, $options = [], $key = null) } } else { $this->getAssetManager()->bundles[$key] = Yii::createObject([ - 'class' => AssetBundle::className(), + 'class' => AssetBundle::class, 'baseUrl' => '', 'basePath' => '@webroot', (string)$type => [ArrayHelper::merge([!Url::isRelative($url) ? $url : ltrim($url, '/')], $originalOptions)], diff --git a/widgets/BaseListView.php b/widgets/BaseListView.php index cee83fcaf..4aa9b7826 100644 --- a/widgets/BaseListView.php +++ b/widgets/BaseListView.php @@ -253,7 +253,7 @@ public function renderPager() } /* @var $class LinkPager */ $pager = $this->pager; - $class = ArrayHelper::remove($pager, 'class', LinkPager::className()); + $class = ArrayHelper::remove($pager, 'class', LinkPager::class); $pager['pagination'] = $pagination; $pager['view'] = $this->getView(); @@ -272,7 +272,7 @@ public function renderSorter() } /* @var $class LinkSorter */ $sorter = $this->sorter; - $class = ArrayHelper::remove($sorter, 'class', LinkSorter::className()); + $class = ArrayHelper::remove($sorter, 'class', LinkSorter::class); $sorter['sort'] = $sort; $sorter['view'] = $this->getView(); diff --git a/widgets/MaskedInputAsset.php b/widgets/MaskedInputAsset.php index 473f4315f..2a0a6a197 100644 --- a/widgets/MaskedInputAsset.php +++ b/widgets/MaskedInputAsset.php @@ -19,7 +19,7 @@ */ class MaskedInputAsset extends AssetBundle { - public $sourcePath = '@bower/inputmask/dist'; + public $sourcePath = '@npm/inputmask/dist'; public $js = [ 'jquery.inputmask.js', ]; diff --git a/widgets/PjaxAsset.php b/widgets/PjaxAsset.php index 47795f683..c084763f9 100644 --- a/widgets/PjaxAsset.php +++ b/widgets/PjaxAsset.php @@ -17,7 +17,7 @@ */ class PjaxAsset extends AssetBundle { - public $sourcePath = '@bower/yii2-pjax'; + public $sourcePath = '@npm/yii2-pjax'; public $js = [ 'jquery.pjax.js', ]; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy