code
stringlengths 17
296k
| docstring
stringlengths 30
30.3k
| func_name
stringlengths 1
89
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
153
| url
stringlengths 51
209
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
protected function setValue($key,$value,$expire)
{
return zend_shm_cache_store($key,$value,$expire);
} | 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 string $value the value to be cached
@param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
@return boolean true if the value is successfully stored into cache, false otherwise | setValue | php | yiisoft/yii | framework/caching/CZendDataCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CZendDataCache.php | BSD-3-Clause |
protected function addValue($key,$value,$expire)
{
return (NULL === zend_shm_cache_fetch($key)) ? $this->setValue($key,$value,$expire) : false;
} | 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 string $value the value to be cached
@param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
@return boolean true if the value is successfully stored into cache, false otherwise | addValue | php | yiisoft/yii | framework/caching/CZendDataCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CZendDataCache.php | BSD-3-Clause |
protected function deleteValue($key)
{
return zend_shm_cache_delete($key);
} | 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 boolean if no error happens during deletion | deleteValue | php | yiisoft/yii | framework/caching/CZendDataCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CZendDataCache.php | BSD-3-Clause |
protected function flushValues()
{
return zend_shm_cache_clear();
} | Deletes all values from cache.
This is the implementation of the method declared in the parent class.
@return boolean whether the flush operation was successful.
@since 1.1.5 | flushValues | php | yiisoft/yii | framework/caching/CZendDataCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CZendDataCache.php | BSD-3-Clause |
public function setServers($config)
{
foreach($config as $c)
$this->_servers[]=new CMemCacheServerConfiguration($c);
} | @param array $config list of memcache server configurations. Each element must be an array
with the following keys: host, port, persistent, weight, timeout, retryInterval, status.
@see https://www.php.net/manual/en/function.Memcache-addServer.php | setServers | php | yiisoft/yii | framework/caching/CMemCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CMemCache.php | BSD-3-Clause |
protected function getValue($key)
{
return $this->_cache->get($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 string|boolean the value stored in cache, false if the value is not in the cache or expired. | getValue | php | yiisoft/yii | framework/caching/CMemCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CMemCache.php | BSD-3-Clause |
protected function getValues($keys)
{
return $this->useMemcached ? $this->_cache->getMulti($keys) : $this->_cache->get($keys);
} | Retrieves multiple values from cache with the specified keys.
@param array $keys a list of keys identifying the cached values
@return array a list of cached values indexed by the keys | getValues | php | yiisoft/yii | framework/caching/CMemCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CMemCache.php | BSD-3-Clause |
protected function setValue($key,$value,$duration)
{
$expire = $this->normalizeDuration($duration);
return $this->useMemcached ? $this->_cache->set($key,$value,$expire) : $this->_cache->set($key,$value,0,$expire);
} | 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 string $value the value to be cached
@param integer $duration the number of seconds in which the cached value will expire. 0 means never expire.
@return boolean true if the value is successfully stored into cache, false otherwise | setValue | php | yiisoft/yii | framework/caching/CMemCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CMemCache.php | BSD-3-Clause |
protected function addValue($key,$value,$duration)
{
$expire = $this->normalizeDuration($duration);
return $this->useMemcached ? $this->_cache->add($key,$value,$expire) : $this->_cache->add($key,$value,0,$expire);
} | 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 string $value the value to be cached
@param integer $duration the number of seconds in which the cached value will expire. 0 means never expire.
@return boolean true if the value is successfully stored into cache, false otherwise | addValue | php | yiisoft/yii | framework/caching/CMemCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CMemCache.php | BSD-3-Clause |
protected function normalizeDuration($duration)
{
if ($duration < 0) {
return 0;
}
if ($duration < 2592001) {
return $duration;
}
return $duration + time();
} | Normalizes duration value.
Ported code from yii2 after identifying issue with memcache falsely handling short term duration based on unix timestamps
@see https://github.com/yiisoft/yii2/issues/17710
@see https://secure.php.net/manual/en/memcache.set.php
@see https://secure.php.net/manual/en/memcached.expiration.php
@see https://github.com/php-memcached-dev/php-memcached/issues/368#issuecomment-359137077
@param int $duration
@return int | normalizeDuration | php | yiisoft/yii | framework/caching/CMemCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CMemCache.php | BSD-3-Clause |
protected function deleteValue($key)
{
return $this->_cache->delete($key, 0);
} | 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 boolean if no error happens during deletion | deleteValue | php | yiisoft/yii | framework/caching/CMemCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CMemCache.php | BSD-3-Clause |
protected function flushValues()
{
return $this->_cache->flush();
} | Deletes all values from cache.
This is the implementation of the method declared in the parent class.
@return boolean whether the flush operation was successful.
@since 1.1.5 | flushValues | php | yiisoft/yii | framework/caching/CMemCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CMemCache.php | BSD-3-Clause |
protected function generateDependentData()
{
if($this->directory!==null)
return $this->generateTimestamps($this->directory);
else
throw new CException(Yii::t('yii','CDirectoryCacheDependency.directory cannot be empty.'));
} | Generates the data needed to determine if dependency has been changed.
This method returns the modification timestamps for files under the directory.
@throws CException if {@link directory} is empty
@return mixed the data needed to determine if dependency has been changed. | generateDependentData | php | yiisoft/yii | framework/caching/dependencies/CDirectoryCacheDependency.php | https://github.com/yiisoft/yii/blob/master/framework/caching/dependencies/CDirectoryCacheDependency.php | BSD-3-Clause |
protected function generateTimestamps($directory,$level=0)
{
if(($dir=@opendir($directory))===false)
throw new CException(Yii::t('yii','"{path}" is not a valid directory.',
array('{path}'=>$directory)));
$timestamps=array();
while(($file=readdir($dir))!==false)
{
$path=$directory.DIRECTORY_SEPARATOR.$file;
if($file==='.' || $file==='..')
continue;
if($this->namePattern!==null && !preg_match($this->namePattern,$file))
continue;
if(is_file($path))
{
if($this->validateFile($path))
$timestamps[$path]=filemtime($path);
}
else
{
if(($this->recursiveLevel<0 || $level<$this->recursiveLevel) && $this->validateDirectory($path))
$timestamps=array_merge($timestamps, $this->generateTimestamps($path,$level+1));
}
}
closedir($dir);
return $timestamps;
} | Determines the last modification time for files under the directory.
This method may go recursively into subdirectories if {@link recursiveLevel} is not 0.
@param string $directory the directory name
@param integer $level level of the recursion
@throws CException if given directory is not valid
@return array list of file modification time indexed by the file path | generateTimestamps | php | yiisoft/yii | framework/caching/dependencies/CDirectoryCacheDependency.php | https://github.com/yiisoft/yii/blob/master/framework/caching/dependencies/CDirectoryCacheDependency.php | BSD-3-Clause |
protected function validateFile($fileName)
{
return true;
} | Checks to see if the file should be checked for dependency.
This method is invoked when dependency of the whole directory is being checked.
By default, it always returns true, meaning the file should be checked.
You may override this method to check only certain files.
@param string $fileName the name of the file that may be checked for dependency.
@return boolean whether this file should be checked. | validateFile | php | yiisoft/yii | framework/caching/dependencies/CDirectoryCacheDependency.php | https://github.com/yiisoft/yii/blob/master/framework/caching/dependencies/CDirectoryCacheDependency.php | BSD-3-Clause |
protected function validateDirectory($directory)
{
return true;
} | Checks to see if the specified subdirectory should be checked for dependency.
This method is invoked when dependency of the whole directory is being checked.
By default, it always returns true, meaning the subdirectory should be checked.
You may override this method to check only certain subdirectories.
@param string $directory the name of the subdirectory that may be checked for dependency.
@return boolean whether this subdirectory should be checked. | validateDirectory | php | yiisoft/yii | framework/caching/dependencies/CDirectoryCacheDependency.php | https://github.com/yiisoft/yii/blob/master/framework/caching/dependencies/CDirectoryCacheDependency.php | BSD-3-Clause |
public function evaluateDependency()
{
if ($this->reuseDependentData)
{
$hash=$this->getHash();
if(!isset(self::$_reusableData[$hash]['dependentData']))
self::$_reusableData[$hash]['dependentData']=$this->generateDependentData();
$this->_data=self::$_reusableData[$hash]['dependentData'];
}
else
$this->_data=$this->generateDependentData();
} | Evaluates the dependency by generating and saving the data related with dependency.
This method is invoked by cache before writing data into it. | evaluateDependency | php | yiisoft/yii | framework/caching/dependencies/CCacheDependency.php | https://github.com/yiisoft/yii/blob/master/framework/caching/dependencies/CCacheDependency.php | BSD-3-Clause |
public static function resetReusableData()
{
self::$_reusableData=array();
} | Resets cached data for reusable dependencies.
@since 1.1.14 | resetReusableData | php | yiisoft/yii | framework/caching/dependencies/CCacheDependency.php | https://github.com/yiisoft/yii/blob/master/framework/caching/dependencies/CCacheDependency.php | BSD-3-Clause |
protected function generateDependentData()
{
return null;
} | Generates the data needed to determine if dependency has been changed.
Derived classes should override this method to generate actual dependent data.
@return mixed the data needed to determine if dependency has been changed. | generateDependentData | php | yiisoft/yii | framework/caching/dependencies/CCacheDependency.php | https://github.com/yiisoft/yii/blob/master/framework/caching/dependencies/CCacheDependency.php | BSD-3-Clause |
private function getHash()
{
if($this->_hash===null)
$this->_hash=sha1(serialize($this));
return $this->_hash;
} | Generates a unique hash that identifies this cache dependency.
@return string the hash for this cache dependency | getHash | php | yiisoft/yii | framework/caching/dependencies/CCacheDependency.php | https://github.com/yiisoft/yii/blob/master/framework/caching/dependencies/CCacheDependency.php | BSD-3-Clause |
public function evaluateDependency()
{
if($this->_dependencies!==null)
{
foreach($this->_dependencies as $dependency)
$dependency->evaluateDependency();
}
} | Evaluates the dependency by generating and saving the data related with dependency. | evaluateDependency | php | yiisoft/yii | framework/caching/dependencies/CChainedCacheDependency.php | https://github.com/yiisoft/yii/blob/master/framework/caching/dependencies/CChainedCacheDependency.php | BSD-3-Clause |
public function getHasChanged()
{
if($this->_dependencies!==null)
{
foreach($this->_dependencies as $dependency)
if($dependency->getHasChanged())
return true;
}
return false;
} | Performs the actual dependency checking.
This method returns true if any of the dependency objects
reports a dependency change.
@return boolean whether the dependency is changed or not. | getHasChanged | php | yiisoft/yii | framework/caching/dependencies/CChainedCacheDependency.php | https://github.com/yiisoft/yii/blob/master/framework/caching/dependencies/CChainedCacheDependency.php | BSD-3-Clause |
public function __sleep()
{
$this->_db=null;
return array_keys((array)$this);
} | PHP sleep magic method.
This method ensures that the database instance is set null because it contains resource handles.
@return array | __sleep | php | yiisoft/yii | framework/caching/dependencies/CDbCacheDependency.php | https://github.com/yiisoft/yii/blob/master/framework/caching/dependencies/CDbCacheDependency.php | BSD-3-Clause |
protected function generateDependentData()
{
if($this->sql!==null)
{
$db=$this->getDbConnection();
$command=$db->createCommand($this->sql);
if(is_array($this->params))
{
foreach($this->params as $name=>$value)
$command->bindValue($name,$value);
}
if($db->queryCachingDuration>0)
{
// temporarily disable and re-enable query caching
$duration=$db->queryCachingDuration;
$db->queryCachingDuration=0;
$result=$command->queryRow();
$db->queryCachingDuration=$duration;
}
else
$result=$command->queryRow();
return $result;
}
else
throw new CException(Yii::t('yii','CDbCacheDependency.sql cannot be empty.'));
} | Generates the data needed to determine if dependency has been changed.
This method returns the value of the global state.
@throws CException if {@link sql} is empty
@return mixed the data needed to determine if dependency has been changed. | generateDependentData | php | yiisoft/yii | framework/caching/dependencies/CDbCacheDependency.php | https://github.com/yiisoft/yii/blob/master/framework/caching/dependencies/CDbCacheDependency.php | BSD-3-Clause |
protected function generateDependentData()
{
if($this->stateName!==null)
return Yii::app()->getGlobalState($this->stateName);
else
throw new CException(Yii::t('yii','CGlobalStateCacheDependency.stateName cannot be empty.'));
} | Generates the data needed to determine if dependency has been changed.
This method returns the value of the global state.
@throws CException if {@link stateName} is empty
@return mixed the data needed to determine if dependency has been changed. | generateDependentData | php | yiisoft/yii | framework/caching/dependencies/CGlobalStateCacheDependency.php | https://github.com/yiisoft/yii/blob/master/framework/caching/dependencies/CGlobalStateCacheDependency.php | BSD-3-Clause |
protected function generateDependentData()
{
if($this->fileName!==null)
return @filemtime($this->fileName);
else
throw new CException(Yii::t('yii','CFileCacheDependency.fileName cannot be empty.'));
} | Generates the data needed to determine if dependency has been changed.
This method returns the file's last modification time.
@throws CException if {@link fileName} is empty
@return mixed the data needed to determine if dependency has been changed. | generateDependentData | php | yiisoft/yii | framework/caching/dependencies/CFileCacheDependency.php | https://github.com/yiisoft/yii/blob/master/framework/caching/dependencies/CFileCacheDependency.php | BSD-3-Clause |
protected function generateDependentData()
{
return $this->evaluateExpression($this->expression);
} | Generates the data needed to determine if dependency has been changed.
This method returns the result of the PHP expression.
@return mixed the data needed to determine if dependency has been changed. | generateDependentData | php | yiisoft/yii | framework/caching/dependencies/CExpressionDependency.php | https://github.com/yiisoft/yii/blob/master/framework/caching/dependencies/CExpressionDependency.php | BSD-3-Clause |
protected function validateAttribute($object,$attribute)
{
if($this->filter===null || !is_callable($this->filter))
throw new CException(Yii::t('yii','The "filter" property must be specified with a valid callback.'));
$object->$attribute=call_user_func_array($this->filter,array($object->$attribute));
} | Validates the attribute of the object.
If there is any error, the error message is added to the object.
@param CModel $object the object being validated
@param string $attribute the attribute being validated
@throws CException if given {@link filter} is not callable | validateAttribute | php | yiisoft/yii | framework/validators/CFilterValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CFilterValidator.php | BSD-3-Clause |
protected function getModel($className)
{
return CActiveRecord::model($className);
} | Given active record class name returns new model instance.
@param string $className active record class name.
@return CActiveRecord active record model instance.
@since 1.1.14 | getModel | php | yiisoft/yii | framework/validators/CUniqueValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CUniqueValidator.php | BSD-3-Clause |
protected function validateAttribute($object,$attribute)
{
} | Validates the attribute of the object.
This validator does not do any validation as it is meant
to only mark attributes as unsafe.
@param CModel $object the object being validated
@param string $attribute the attribute being validated | validateAttribute | php | yiisoft/yii | framework/validators/CUnsafeValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CUnsafeValidator.php | BSD-3-Clause |
protected function validateAttribute($object,$attribute)
{
$value=$object->$attribute;
if($this->allowEmpty && $this->isEmpty($value))
return;
$captcha=$this->getCaptchaAction();
// reason of array checking is explained here: https://github.com/yiisoft/yii/issues/1955
if(is_array($value) || !$captcha->validate($value,$this->caseSensitive))
{
$message=$this->message!==null?$this->message:Yii::t('yii','The verification code is incorrect.');
$this->addError($object,$attribute,$message);
}
} | Validates the attribute of the object.
If there is any error, the error message is added to the object.
@param CModel $object the object being validated
@param string $attribute the attribute being validated | validateAttribute | php | yiisoft/yii | framework/validators/CCaptchaValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CCaptchaValidator.php | BSD-3-Clause |
protected function getCaptchaAction()
{
if(($captcha=Yii::app()->getController()->createAction($this->captchaAction))===null)
{
if(strpos($this->captchaAction,'/')!==false) // contains controller or module
{
if(($ca=Yii::app()->createController($this->captchaAction))!==null)
{
list($controller,$actionID)=$ca;
$captcha=$controller->createAction($actionID);
}
}
if($captcha===null)
throw new CException(Yii::t('yii','CCaptchaValidator.action "{id}" is invalid. Unable to find such an action in the current controller.',
array('{id}'=>$this->captchaAction)));
}
return $captcha;
} | Returns the CAPTCHA action object.
@throws CException if {@link action} is invalid
@return CCaptchaAction the action object
@since 1.1.7 | getCaptchaAction | php | yiisoft/yii | framework/validators/CCaptchaValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CCaptchaValidator.php | BSD-3-Clause |
public function clientValidateAttribute($object,$attribute)
{
} | Returns the JavaScript needed for performing client-side validation.
Do not override this method if the validator does not support client-side validation.
Two predefined JavaScript variables can be used:
<ul>
<li>value: the value to be validated</li>
<li>messages: an array used to hold the validation error messages for the value</li>
</ul>
@param CModel $object the data object being validated
@param string $attribute the name of the attribute to be validated.
@return string the client-side validation script. Null if the validator does not support client-side validation.
@see CActiveForm::enableClientValidation
@since 1.1.7 | clientValidateAttribute | php | yiisoft/yii | framework/validators/CValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CValidator.php | BSD-3-Clause |
public function applyTo($scenario)
{
if(isset($this->except[$scenario]))
return false;
return empty($this->on) || isset($this->on[$scenario]);
} | Returns a value indicating whether the validator applies to the specified scenario.
A validator applies to a scenario as long as any of the following conditions is met:
<ul>
<li>the validator's "on" property is empty</li>
<li>the validator's "on" property contains the specified scenario</li>
</ul>
@param string $scenario scenario name
@return boolean whether the validator applies to the specified scenario. | applyTo | php | yiisoft/yii | framework/validators/CValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CValidator.php | BSD-3-Clause |
protected function isEmpty($value,$trim=false)
{
return $value===null || $value===array() || $value==='' || $trim && is_scalar($value) && trim($value)==='';
} | Checks if the given value is empty.
A value is considered empty if it is null, an empty array, or the trimmed result is an empty string.
Note that this method is different from PHP empty(). It will return false when the value is 0.
@param mixed $value the value to be checked
@param boolean $trim whether to perform trimming before checking if the string is empty. Defaults to false.
@return boolean whether the value is empty | isEmpty | php | yiisoft/yii | framework/validators/CValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CValidator.php | BSD-3-Clause |
protected function validateAttribute($object,$attribute)
{
if(!$this->setOnEmpty)
$object->$attribute=$this->value;
else
{
$value=$object->$attribute;
if($value===null || $value==='')
$object->$attribute=$this->value;
}
} | Validates the attribute of the object.
@param CModel $object the object being validated
@param string $attribute the attribute being validated | validateAttribute | php | yiisoft/yii | framework/validators/CDefaultValueValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CDefaultValueValidator.php | BSD-3-Clause |
protected function validateAttribute($object,$attribute)
{
$value=$object->$attribute;
if($this->allowEmpty && $this->isEmpty($value))
return;
if(!is_numeric($value))
{
// https://github.com/yiisoft/yii/issues/1955
// https://github.com/yiisoft/yii/issues/1669
$message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must be a number.');
$this->addError($object,$attribute,$message);
return;
}
if($this->integerOnly)
{
if(!preg_match($this->integerPattern,"$value"))
{
$message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must be an integer.');
$this->addError($object,$attribute,$message);
}
}
else
{
if(!preg_match($this->numberPattern,"$value"))
{
$message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must be a number.');
$this->addError($object,$attribute,$message);
}
}
if($this->min!==null && $value<$this->min)
{
$message=$this->tooSmall!==null?$this->tooSmall:Yii::t('yii','{attribute} is too small (minimum is {min}).');
$this->addError($object,$attribute,$message,array('{min}'=>$this->min));
}
if($this->max!==null && $value>$this->max)
{
$message=$this->tooBig!==null?$this->tooBig:Yii::t('yii','{attribute} is too big (maximum is {max}).');
$this->addError($object,$attribute,$message,array('{max}'=>$this->max));
}
} | Validates the attribute of the object.
If there is any error, the error message is added to the object.
@param CModel $object the object being validated
@param string $attribute the attribute being validated | validateAttribute | php | yiisoft/yii | framework/validators/CNumberValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CNumberValidator.php | BSD-3-Clause |
public function clientValidateAttribute($object,$attribute)
{
$label=$object->getAttributeLabel($attribute);
if(($message=$this->message)===null)
$message=$this->integerOnly ? Yii::t('yii','{attribute} must be an integer.') : Yii::t('yii','{attribute} must be a number.');
$message=strtr($message, array(
'{attribute}'=>$label,
));
if(($tooBig=$this->tooBig)===null)
$tooBig=Yii::t('yii','{attribute} is too big (maximum is {max}).');
$tooBig=strtr($tooBig, array(
'{attribute}'=>$label,
'{max}'=>$this->max,
));
if(($tooSmall=$this->tooSmall)===null)
$tooSmall=Yii::t('yii','{attribute} is too small (minimum is {min}).');
$tooSmall=strtr($tooSmall, array(
'{attribute}'=>$label,
'{min}'=>$this->min,
));
$pattern=$this->integerOnly ? $this->integerPattern : $this->numberPattern;
$js="
if(!value.match($pattern)) {
messages.push(".CJSON::encode($message).");
}
";
if($this->min!==null)
{
$js.="
if(value<{$this->min}) {
messages.push(".CJSON::encode($tooSmall).");
}
";
}
if($this->max!==null)
{
$js.="
if(value>{$this->max}) {
messages.push(".CJSON::encode($tooBig).");
}
";
}
if($this->allowEmpty)
{
$js="
if(jQuery.trim(value)!='') {
$js
}
";
}
return $js;
} | Returns the JavaScript needed for performing client-side validation.
@param CModel $object the data object being validated
@param string $attribute the name of the attribute to be validated.
@return string the client-side validation script.
@see CActiveForm::enableClientValidation
@since 1.1.7 | clientValidateAttribute | php | yiisoft/yii | framework/validators/CNumberValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CNumberValidator.php | BSD-3-Clause |
protected function validateAttribute($object,$attribute)
{
$value=$object->$attribute;
if($this->allowEmpty && $this->isEmpty($value))
return;
if(($value=$this->validateValue($value))!==false)
$object->$attribute=$value;
else
{
$message=$this->message!==null?$this->message:Yii::t('yii','{attribute} is not a valid URL.');
$this->addError($object,$attribute,$message);
}
} | Validates the attribute of the object.
If there is any error, the error message is added to the object.
@param CModel $object the object being validated
@param string $attribute the attribute being validated | validateAttribute | php | yiisoft/yii | framework/validators/CUrlValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CUrlValidator.php | BSD-3-Clause |
public function validateValue($value)
{
if(is_string($value) && strlen($value)<2000) // make sure the length is limited to avoid DOS attacks
{
if($this->defaultScheme!==null && strpos($value,'://')===false)
$value=$this->defaultScheme.'://'.$value;
if($this->validateIDN)
$value=$this->encodeIDN($value);
if(strpos($this->pattern,'{schemes}')!==false)
$pattern=str_replace('{schemes}','('.implode('|',$this->validSchemes).')',$this->pattern);
else
$pattern=$this->pattern;
if(preg_match($pattern,$value))
return $this->validateIDN ? $this->decodeIDN($value) : $value;
}
return false;
} | Validates a static value to see if it is a valid URL.
Note that this method does not respect {@link allowEmpty} property.
This method is provided so that you can call it directly without going through the model validation rule mechanism.
@param string $value the value to be validated
@return mixed false if the the value is not a valid URL, otherwise the possibly modified value ({@see defaultScheme})
@since 1.1.1 | validateValue | php | yiisoft/yii | framework/validators/CUrlValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CUrlValidator.php | BSD-3-Clause |
public function clientValidateAttribute($object,$attribute)
{
if($this->validateIDN)
{
Yii::app()->getClientScript()->registerCoreScript('punycode');
// punycode.js works only with the domains - so we have to extract it before punycoding
$validateIDN='
var info = value.match(/^(.+:\/\/|)([^/]+)/);
if (info)
value = info[1] + punycode.toASCII(info[2]);
';
}
else
$validateIDN='';
$message=$this->message!==null ? $this->message : Yii::t('yii','{attribute} is not a valid URL.');
$message=strtr($message, array(
'{attribute}'=>$object->getAttributeLabel($attribute),
));
if(strpos($this->pattern,'{schemes}')!==false)
$pattern=str_replace('{schemes}','('.implode('|',$this->validSchemes).')',$this->pattern);
else
$pattern=$this->pattern;
$js="
$validateIDN
if(!value.match($pattern)) {
messages.push(".CJSON::encode($message).");
}
";
if($this->defaultScheme!==null)
{
$js="
if(!value.match(/:\\/\\//)) {
value=".CJSON::encode($this->defaultScheme)."+'://'+value;
}
$js
";
}
if($this->allowEmpty)
{
$js="
if(jQuery.trim(value)!='') {
$js
}
";
}
return $js;
} | Returns the JavaScript needed for performing client-side validation.
@param CModel $object the data object being validated
@param string $attribute the name of the attribute to be validated.
@return string the client-side validation script.
@see CActiveForm::enableClientValidation
@since 1.1.7 | clientValidateAttribute | php | yiisoft/yii | framework/validators/CUrlValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CUrlValidator.php | BSD-3-Clause |
private function encodeIDN($value)
{
if(preg_match_all('/^(.*):\/\/([^\/]+)(.*)$/',$value,$matches))
{
if(function_exists('idn_to_ascii'))
{
$value=$matches[1][0].'://';
if (defined('IDNA_NONTRANSITIONAL_TO_ASCII') && defined('INTL_IDNA_VARIANT_UTS46'))
{
$value.=idn_to_ascii($matches[2][0],IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
}
else
{
$value.=idn_to_ascii($matches[2][0]);
}
$value.=$matches[3][0];
}
else
{
require_once(Yii::getPathOfAlias('system.vendors.Net_IDNA2.Net').DIRECTORY_SEPARATOR.'IDNA2.php');
$idna=new Net_IDNA2();
$value=$matches[1][0].'://'.@$idna->encode($matches[2][0]).$matches[3][0];
}
}
return $value;
} | Converts given IDN to the punycode.
@param string $value IDN to be converted.
@return string resulting punycode.
@since 1.1.13 | encodeIDN | php | yiisoft/yii | framework/validators/CUrlValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CUrlValidator.php | BSD-3-Clause |
private function decodeIDN($value)
{
if(preg_match_all('/^(.*):\/\/([^\/]+)(.*)$/',$value,$matches))
{
if(function_exists('idn_to_utf8'))
{
$value=$matches[1][0].'://';
if (defined('IDNA_NONTRANSITIONAL_TO_ASCII') && defined('INTL_IDNA_VARIANT_UTS46'))
{
$value.=idn_to_utf8($matches[2][0],IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
}
else
{
$value.=idn_to_utf8($matches[2][0]);
}
$value.=$matches[3][0];
}
else
{
require_once(Yii::getPathOfAlias('system.vendors.Net_IDNA2.Net').DIRECTORY_SEPARATOR.'IDNA2.php');
$idna=new Net_IDNA2();
$value=$matches[1][0].'://'.@$idna->decode($matches[2][0]).$matches[3][0];
}
}
return $value;
} | Converts given punycode to the IDN.
@param string $value punycode to be converted.
@return string resulting IDN.
@since 1.1.13 | decodeIDN | php | yiisoft/yii | framework/validators/CUrlValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CUrlValidator.php | BSD-3-Clause |
public function clientValidateAttribute($object,$attribute)
{
$message=$this->message;
if($this->requiredValue!==null)
{
if($message===null)
$message=Yii::t('yii','{attribute} must be {value}.');
$message=strtr($message, array(
'{value}'=>$this->requiredValue,
'{attribute}'=>$object->getAttributeLabel($attribute),
));
return "
if(value!=" . CJSON::encode($this->requiredValue) . ") {
messages.push(".CJSON::encode($message).");
}
";
}
else
{
if($message===null)
$message=Yii::t('yii','{attribute} cannot be blank.');
$message=strtr($message, array(
'{attribute}'=>$object->getAttributeLabel($attribute),
));
if($this->trim)
$emptyCondition = "jQuery.trim(value)==''";
else
$emptyCondition = "value==''";
return "
if({$emptyCondition}) {
messages.push(".CJSON::encode($message).");
}
";
}
} | Returns the JavaScript needed for performing client-side validation.
@param CModel $object the data object being validated
@param string $attribute the name of the attribute to be validated.
@return string the client-side validation script.
@see CActiveForm::enableClientValidation
@since 1.1.7 | clientValidateAttribute | php | yiisoft/yii | framework/validators/CRequiredValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CRequiredValidator.php | BSD-3-Clause |
protected function validateAttribute($object,$attribute)
{
$value=$object->$attribute;
if($this->allowEmpty && $this->isEmpty($value))
return;
if(is_array($value))
{
// https://github.com/yiisoft/yii/issues/1955
$this->addError($object,$attribute,Yii::t('yii','{attribute} is invalid.'));
return;
}
if(function_exists('mb_strlen') && $this->encoding!==false)
$length=mb_strlen((string)$value, $this->encoding ? $this->encoding : Yii::app()->charset);
else
$length=strlen((string)$value);
if($this->min!==null && $length<$this->min)
{
$message=$this->tooShort!==null?$this->tooShort:Yii::t('yii','{attribute} is too short (minimum is {min} characters).');
$this->addError($object,$attribute,$message,array('{min}'=>$this->min));
}
if($this->max!==null && $length>$this->max)
{
$message=$this->tooLong!==null?$this->tooLong:Yii::t('yii','{attribute} is too long (maximum is {max} characters).');
$this->addError($object,$attribute,$message,array('{max}'=>$this->max));
}
if($this->is!==null && $length!==$this->is)
{
$message=$this->message!==null?$this->message:Yii::t('yii','{attribute} is of the wrong length (should be {length} characters).');
$this->addError($object,$attribute,$message,array('{length}'=>$this->is));
}
} | Validates the attribute of the object.
If there is any error, the error message is added to the object.
@param CModel $object the object being validated
@param string $attribute the attribute being validated | validateAttribute | php | yiisoft/yii | framework/validators/CStringValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CStringValidator.php | BSD-3-Clause |
public function clientValidateAttribute($object,$attribute)
{
$label=$object->getAttributeLabel($attribute);
if(($message=$this->message)===null)
$message=Yii::t('yii','{attribute} is of the wrong length (should be {length} characters).');
$message=strtr($message, array(
'{attribute}'=>$label,
'{length}'=>$this->is,
));
if(($tooShort=$this->tooShort)===null)
$tooShort=Yii::t('yii','{attribute} is too short (minimum is {min} characters).');
$tooShort=strtr($tooShort, array(
'{attribute}'=>$label,
'{min}'=>$this->min,
));
if(($tooLong=$this->tooLong)===null)
$tooLong=Yii::t('yii','{attribute} is too long (maximum is {max} characters).');
$tooLong=strtr($tooLong, array(
'{attribute}'=>$label,
'{max}'=>$this->max,
));
$js='';
if($this->min!==null)
{
$js.="
if(value.length<{$this->min}) {
messages.push(".CJSON::encode($tooShort).");
}
";
}
if($this->max!==null)
{
$js.="
if(value.length>{$this->max}) {
messages.push(".CJSON::encode($tooLong).");
}
";
}
if($this->is!==null)
{
$js.="
if(value.length!={$this->is}) {
messages.push(".CJSON::encode($message).");
}
";
}
if($this->allowEmpty)
{
$js="
if(jQuery.trim(value)!='') {
$js
}
";
}
return $js;
} | Returns the JavaScript needed for performing client-side validation.
@param CModel $object the data object being validated
@param string $attribute the name of the attribute to be validated.
@return string the client-side validation script.
@see CActiveForm::enableClientValidation
@since 1.1.7 | clientValidateAttribute | php | yiisoft/yii | framework/validators/CStringValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CStringValidator.php | BSD-3-Clause |
protected function getModel($className)
{
return CActiveRecord::model($className);
} | Given active record class name returns new model instance.
@param string $className active record class name.
@return CActiveRecord active record model instance.
@since 1.1.14 | getModel | php | yiisoft/yii | framework/validators/CExistValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CExistValidator.php | BSD-3-Clause |
protected function validateAttribute($object,$attribute)
{
$value=$object->$attribute;
if($this->allowEmpty && $this->isEmpty($value))
return;
if(!$this->validateValue($value))
{
$message=$this->message!==null?$this->message:Yii::t('yii','{attribute} must be either {true} or {false}.');
$this->addError($object,$attribute,$message,array(
'{true}'=>$this->trueValue,
'{false}'=>$this->falseValue,
));
}
} | Validates the attribute of the object.
If there is any error, the error message is added to the object.
@param CModel $object the object being validated
@param string $attribute the attribute being validated | validateAttribute | php | yiisoft/yii | framework/validators/CBooleanValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CBooleanValidator.php | BSD-3-Clause |
public function validateValue($value)
{
if ($this->strict)
return $value===$this->trueValue || $value===$this->falseValue;
else
return $value==$this->trueValue || $value==$this->falseValue;
} | Validates a static value to see if it is a valid boolean.
This method is provided so that you can call it directly without going
through the model validation rule mechanism.
Note that this method does not respect the {@link allowEmpty} property.
@param mixed $value the value to be validated
@return boolean whether the value is a valid boolean
@since 1.1.17 | validateValue | php | yiisoft/yii | framework/validators/CBooleanValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CBooleanValidator.php | BSD-3-Clause |
protected function validateAttribute($object,$attribute)
{
$value=$object->$attribute;
if($this->allowEmpty && $this->isEmpty($value))
return;
if($this->pattern===null)
throw new CException(Yii::t('yii','The "pattern" property must be specified with a valid regular expression.'));
// reason of array checking explained here: https://github.com/yiisoft/yii/issues/1955
if(is_array($value) ||
(!$this->not && !preg_match($this->pattern,$value)) ||
($this->not && preg_match($this->pattern,$value)))
{
$message=$this->message!==null?$this->message:Yii::t('yii','{attribute} is invalid.');
$this->addError($object,$attribute,$message);
}
} | Validates the attribute of the object.
If there is any error, the error message is added to the object.
@param CModel $object the object being validated
@param string $attribute the attribute being validated
@throws CException if given {@link pattern} is empty | validateAttribute | php | yiisoft/yii | framework/validators/CRegularExpressionValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CRegularExpressionValidator.php | BSD-3-Clause |
protected function validateAttribute($object,$attribute)
{
$value=$object->$attribute;
if($this->allowEmpty && $this->isEmpty($value))
return;
if(!$this->validateValue($value))
{
$message=$this->message!==null?$this->message : Yii::t('yii','{attribute} must be {type}.');
$this->addError($object,$attribute,$message,array('{type}'=>$this->type));
}
} | Validates the attribute of the object.
If there is any error, the error message is added to the object.
@param CModel $object the object being validated
@param string $attribute the attribute being validated | validateAttribute | php | yiisoft/yii | framework/validators/CTypeValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CTypeValidator.php | BSD-3-Clause |
protected function validateAttribute($object,$attribute)
{
$method=$this->method;
$object->$method($attribute,$this->params);
} | Validates the attribute of the object.
If there is any error, the error message is added to the object.
@param CModel $object the object being validated
@param string $attribute the attribute being validated | validateAttribute | php | yiisoft/yii | framework/validators/CInlineValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CInlineValidator.php | BSD-3-Clause |
public function clientValidateAttribute($object,$attribute)
{
if($this->compareValue !== null)
{
$compareTo=$this->compareValue;
$compareValue=CJSON::encode($this->compareValue);
}
else
{
$compareAttribute=$this->compareAttribute === null ? $attribute . '_repeat' : $this->compareAttribute;
$compareValue="jQuery('#" . (CHtml::activeId($object, $compareAttribute)) . "').val()";
$compareTo=$object->getAttributeLabel($compareAttribute);
} | Returns the JavaScript needed for performing client-side validation.
@param CModel $object the data object being validated
@param string $attribute the name of the attribute to be validated.
@throws CException if invalid operator is used
@return string the client-side validation script.
@see CActiveForm::enableClientValidation
@since 1.1.7 | clientValidateAttribute | php | yiisoft/yii | framework/validators/CCompareValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CCompareValidator.php | BSD-3-Clause |
protected function validateAttribute($object,$attribute)
{
} | Validates the attribute of the object.
If there is any error, the error message is added to the object.
@param CModel $object the object being validated
@param string $attribute the attribute being validated | validateAttribute | php | yiisoft/yii | framework/validators/CSafeValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CSafeValidator.php | BSD-3-Clause |
protected function emptyAttribute($object, $attribute)
{
if($this->safe)
$object->$attribute=null;
if(!$this->allowEmpty)
{
$message=$this->message!==null?$this->message : Yii::t('yii','{attribute} cannot be blank.');
$this->addError($object,$attribute,$message);
}
} | Raises an error to inform end user about blank attribute.
Sets the owner attribute to null to prevent setting arbitrary values.
@param CModel $object the object being validated
@param string $attribute the attribute being validated | emptyAttribute | php | yiisoft/yii | framework/validators/CFileValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CFileValidator.php | BSD-3-Clause |
protected function getSizeLimit()
{
$limit=ini_get('upload_max_filesize');
$limit=$this->sizeToBytes($limit);
if($this->maxSize!==null && $limit>0 && $this->maxSize<$limit)
$limit=$this->maxSize;
if(isset($_POST['MAX_FILE_SIZE']) && $_POST['MAX_FILE_SIZE']>0 && $_POST['MAX_FILE_SIZE']<$limit)
$limit=$_POST['MAX_FILE_SIZE'];
return $limit;
} | Returns the maximum size allowed for uploaded files.
This is determined based on three factors:
<ul>
<li>'upload_max_filesize' in php.ini</li>
<li>'MAX_FILE_SIZE' hidden field</li>
<li>{@link maxSize}</li>
</ul>
@return integer the size limit for uploaded files. | getSizeLimit | php | yiisoft/yii | framework/validators/CFileValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CFileValidator.php | BSD-3-Clause |
public function sizeToBytes($sizeStr)
{
// get the latest character
switch (strtolower(substr($sizeStr, -1)))
{
case 'm': return (int)$sizeStr * 1048576; // 1024 * 1024
case 'k': return (int)$sizeStr * 1024; // 1024
case 'g': return (int)$sizeStr * 1073741824; // 1024 * 1024 * 1024
default: return (int)$sizeStr; // do nothing
}
} | Converts php.ini style size to bytes.
Examples of size strings are: 150, 1g, 500k, 5M (size suffix
is case insensitive). If you pass here the number with a fractional part, then everything after
the decimal point will be ignored (php.ini values common behavior). For example 1.5G value would be
treated as 1G and 1073741824 number will be returned as a result. This method is public
(was private before) since 1.1.11.
@param string $sizeStr the size string to convert.
@return integer the byte count in the given size string.
@since 1.1.11 | sizeToBytes | php | yiisoft/yii | framework/validators/CFileValidator.php | https://github.com/yiisoft/yii/blob/master/framework/validators/CFileValidator.php | BSD-3-Clause |
public function up()
{
$transaction=$this->getDbConnection()->beginTransaction();
try
{
if($this->safeUp()===false)
{
$transaction->rollback();
return false;
}
$transaction->commit();
}
catch(Exception $e)
{
echo "Exception: ".$e->getMessage().' ('.$e->getFile().':'.$e->getLine().")\n";
echo $e->getTraceAsString()."\n";
$transaction->rollback();
return false;
}
} | This method contains the logic to be executed when applying this migration.
Child classes may implement this method to provide actual migration logic.
@return boolean Returning false means, the migration will not be applied. | up | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function down()
{
$transaction=$this->getDbConnection()->beginTransaction();
try
{
if($this->safeDown()===false)
{
$transaction->rollback();
return false;
}
$transaction->commit();
}
catch(Exception $e)
{
echo "Exception: ".$e->getMessage().' ('.$e->getFile().':'.$e->getLine().")\n";
echo $e->getTraceAsString()."\n";
$transaction->rollback();
return false;
}
} | This method contains the logic to be executed when removing this migration.
Child classes may override this method if the corresponding migrations can be removed.
@return boolean Returning false means, the migration will not be applied. | down | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function safeUp()
{
} | This method contains the logic to be executed when applying this migration.
This method differs from {@link up} in that the DB logic implemented here will
be enclosed within a DB transaction.
Child classes may implement this method instead of {@link up} if the DB logic
needs to be within a transaction.
@return boolean Returning false means, the migration will not be applied and
the transaction will be rolled back.
@since 1.1.7 | safeUp | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function safeDown()
{
} | This method contains the logic to be executed when removing this migration.
This method differs from {@link down} in that the DB logic implemented here will
be enclosed within a DB transaction.
Child classes may implement this method instead of {@link up} if the DB logic
needs to be within a transaction.
@return boolean Returning false means, the migration will not be applied and
the transaction will be rolled back.
@since 1.1.7 | safeDown | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function getDbConnection()
{
if($this->_db===null)
{
$this->_db=Yii::app()->getComponent('db');
if(!$this->_db instanceof CDbConnection)
throw new CException(Yii::t('yii', 'The "db" application component must be configured to be a CDbConnection object.'));
}
return $this->_db;
} | Returns the currently active database connection.
By default, the 'db' application component will be returned and activated.
You can call {@link setDbConnection} to switch to a different database connection.
Methods such as {@link insert}, {@link createTable} will use this database connection
to perform DB queries.
@throws CException if "db" application component is not configured
@return CDbConnection the currently active database connection | getDbConnection | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function setDbConnection($db)
{
$this->_db=$db;
} | Sets the currently active database connection.
The database connection will be used by the methods such as {@link insert}, {@link createTable}.
@param CDbConnection $db the database connection component | setDbConnection | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function insert($table, $columns)
{
echo " > insert into $table ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->insert($table, $columns);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Creates and executes an INSERT SQL statement.
The method will properly escape the column names, and bind the values to be inserted.
@param string $table the table that new rows will be inserted into.
@param array $columns the column data (name=>value) to be inserted into the table. | insert | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function insertMultiple($table, $data)
{
echo " > insert into $table ...";
$time=microtime(true);
$builder=$this->getDbConnection()->getSchema()->getCommandBuilder();
$command=$builder->createMultipleInsertCommand($table,$data);
$command->execute();
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Creates and executes an INSERT SQL statement with multiple data.
The method will properly escape the column names, and bind the values to be inserted.
@param string $table the table that new rows will be inserted into.
@param array $data an array of various column data (name=>value) to be inserted into the table.
@since 1.1.16 | insertMultiple | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function createTable($table, $columns, $options=null)
{
echo " > create table $table ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->createTable($table, $columns, $options);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Builds and executes a SQL statement for creating a new DB table.
The columns in the new table should be specified as name-definition pairs (e.g. 'name'=>'string'),
where name stands for a column name which will be properly quoted by the method, and definition
stands for the column type which can contain an abstract DB type.
The {@link getColumnType} method will be invoked to convert any abstract type into a physical one.
If a column is specified with definition only (e.g. 'PRIMARY KEY (name, type)'), it will be directly
inserted into the generated SQL.
@param string $table the name of the table to be created. The name will be properly quoted by the method.
@param array $columns the columns (name=>definition) in the new table.
@param string $options additional SQL fragment that will be appended to the generated SQL. | createTable | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function renameTable($table, $newName)
{
echo " > rename table $table to $newName ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->renameTable($table, $newName);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Builds and executes a SQL statement for renaming a DB table.
@param string $table the table to be renamed. The name will be properly quoted by the method.
@param string $newName the new table name. The name will be properly quoted by the method. | renameTable | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function dropTable($table)
{
echo " > drop table $table ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->dropTable($table);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Builds and executes a SQL statement for dropping a DB table.
@param string $table the table to be dropped. The name will be properly quoted by the method. | dropTable | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function truncateTable($table)
{
echo " > truncate table $table ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->truncateTable($table);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Builds and executes a SQL statement for truncating a DB table.
@param string $table the table to be truncated. The name will be properly quoted by the method. | truncateTable | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function addColumn($table, $column, $type)
{
echo " > add column $column $type to table $table ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->addColumn($table, $column, $type);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Builds and executes a SQL statement for adding a new DB column.
@param string $table the table that the new column will be added to. The table name will be properly quoted by the method.
@param string $column the name of the new column. The name will be properly quoted by the method.
@param string $type the column type. The {@link getColumnType} method will be invoked to convert abstract column type (if any)
into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL.
For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'. | addColumn | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function dropColumn($table, $column)
{
echo " > drop column $column from table $table ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->dropColumn($table, $column);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Builds and executes a SQL statement for dropping a DB column.
@param string $table the table whose column is to be dropped. The name will be properly quoted by the method.
@param string $column the name of the column to be dropped. The name will be properly quoted by the method. | dropColumn | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function renameColumn($table, $name, $newName)
{
echo " > rename column $name in table $table to $newName ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->renameColumn($table, $name, $newName);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Builds and executes a SQL statement for renaming a column.
@param string $table the table whose column is to be renamed. The name will be properly quoted by the method.
@param string $name the old name of the column. The name will be properly quoted by the method.
@param string $newName the new name of the column. The name will be properly quoted by the method. | renameColumn | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function alterColumn($table, $column, $type)
{
echo " > alter column $column in table $table to $type ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->alterColumn($table, $column, $type);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Builds and executes a SQL statement for changing the definition of a column.
@param string $table the table whose column is to be changed. The table name will be properly quoted by the method.
@param string $column the name of the column to be changed. The name will be properly quoted by the method.
@param string $type the new column type. The {@link getColumnType} method will be invoked to convert abstract column type (if any)
into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL.
For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'. | alterColumn | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function dropForeignKey($name, $table)
{
echo " > drop foreign key $name from table $table ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->dropForeignKey($name, $table);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Builds a SQL statement for dropping a foreign key constraint.
@param string $name the name of the foreign key constraint to be dropped. The name will be properly quoted by the method.
@param string $table the table whose foreign is to be dropped. The name will be properly quoted by the method. | dropForeignKey | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function dropIndex($name, $table)
{
echo " > drop index $name ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->dropIndex($name, $table);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Builds and executes a SQL statement for dropping an index.
@param string $name the name of the index to be dropped. The name will be properly quoted by the method.
@param string $table the table whose index is to be dropped. The name will be properly quoted by the method. | dropIndex | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function refreshTableSchema($table)
{
echo " > refresh table $table schema cache ...";
$time=microtime(true);
$this->getDbConnection()->getSchema()->getTable($table,true);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Refreshed schema cache for a table
@param string $table name of the table to refresh
@since 1.1.9 | refreshTableSchema | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function dropPrimaryKey($name,$table)
{
echo " > alter table $table drop primary key $name ...";
$time=microtime(true);
$this->getDbConnection()->createCommand()->dropPrimaryKey($name,$table);
echo " done (time: ".sprintf('%.3f', microtime(true)-$time)."s)\n";
} | Builds and executes a SQL statement for removing a primary key, supports composite primary keys.
@param string $name name of the constraint to remove
@param string $table name of the table to remove primary key from
@since 1.1.13 | dropPrimaryKey | php | yiisoft/yii | framework/db/CDbMigration.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbMigration.php | BSD-3-Clause |
public function bindColumn($column, &$value, $dataType=null)
{
if($dataType===null)
$this->_statement->bindColumn($column,$value);
else
$this->_statement->bindColumn($column,$value,$dataType);
} | Binds a column to a PHP variable.
When rows of data are being fetched, the corresponding column value
will be set in the variable. Note, the fetch mode must include PDO::FETCH_BOUND.
@param mixed $column Number of the column (1-indexed) or name of the column
in the result set. If using the column name, be aware that the name
should match the case of the column, as returned by the driver.
@param mixed $value Name of the PHP variable to which the column will be bound.
@param integer $dataType Data type of the parameter
@see https://www.php.net/manual/en/function.PDOStatement-bindColumn.php | bindColumn | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function setFetchMode($mode)
{
$params=func_get_args();
call_user_func_array(array($this->_statement,'setFetchMode'),$params);
} | Set the default fetch mode for this statement
@param mixed $mode fetch mode
@see https://www.php.net/manual/en/function.PDOStatement-setFetchMode.php | setFetchMode | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function read()
{
return $this->_statement->fetch();
} | Advances the reader to the next row in a result set.
@return array|false the current row, false if no more row available | read | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function readColumn($columnIndex)
{
return $this->_statement->fetchColumn($columnIndex);
} | Returns a single column from the next row of a result set.
@param integer $columnIndex zero-based column index
@return mixed|false the column of the current row, false if no more row available | readColumn | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function readObject($className,$fields)
{
return $this->_statement->fetchObject($className,$fields);
} | Returns an object populated with the next row of data.
@param string $className class name of the object to be created and populated
@param array $fields Elements of this array are passed to the constructor
@return mixed|false the populated object, false if no more row of data available | readObject | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function readAll()
{
return $this->_statement->fetchAll();
} | Reads the whole result set into an array.
@return array the result set (each array element represents a row of data).
An empty array will be returned if the result contains no row. | readAll | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function nextResult()
{
if(($result=$this->_statement->nextRowset())!==false)
$this->_index=-1;
return $result;
} | Advances the reader to the next result when reading the results of a batch of statements.
This method is only useful when there are multiple result sets
returned by the query. Not all DBMS support this feature.
@return boolean Returns true on success or false on failure. | nextResult | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function close()
{
$this->_statement->closeCursor();
$this->_closed=true;
} | Closes the reader.
This frees up the resources allocated for executing this SQL statement.
Read attempts after this method call are unpredictable. | close | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function getIsClosed()
{
return $this->_closed;
} | whether the reader is closed or not.
@return boolean whether the reader is closed or not. | getIsClosed | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function getRowCount()
{
return $this->_statement->rowCount();
} | Returns the number of rows in the result set.
Note, most DBMS may not give a meaningful count.
In this case, use "SELECT COUNT(*) FROM tableName" to obtain the number of rows.
@return integer number of rows contained in the result. | getRowCount | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function count()
{
return $this->getRowCount();
} | Returns the number of rows in the result set.
This method is required by the Countable interface.
Note, most DBMS may not give a meaningful count.
In this case, use "SELECT COUNT(*) FROM tableName" to obtain the number of rows.
@return integer number of rows contained in the result. | count | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function getColumnCount()
{
return $this->_statement->columnCount();
} | Returns the number of columns in the result set.
Note, even there's no row in the reader, this still gives correct column number.
@return integer the number of columns in the result set. | getColumnCount | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function rewind()
{
if($this->_index<0)
{
$this->_row=$this->_statement->fetch();
$this->_index=0;
}
else
throw new CDbException(Yii::t('yii','CDbDataReader cannot rewind. It is a forward-only reader.'));
} | Resets the iterator to the initial state.
This method is required by the interface Iterator.
@throws CException if this method is invoked twice | rewind | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function key()
{
return $this->_index;
} | Returns the index of the current row.
This method is required by the interface Iterator.
@return integer the index of the current row. | key | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function current()
{
return $this->_row;
} | Returns the current row.
This method is required by the interface Iterator.
@return mixed the current row. | current | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function next()
{
$this->_row=$this->_statement->fetch();
$this->_index++;
} | Moves the internal pointer to the next row.
This method is required by the interface Iterator. | next | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function valid()
{
return $this->_row!==false;
} | Returns whether there is a row of data at current position.
This method is required by the interface Iterator.
@return boolean whether there is a row of data at current position. | valid | php | yiisoft/yii | framework/db/CDbDataReader.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbDataReader.php | BSD-3-Clause |
public function __sleep()
{
$this->_statement=null;
return array_keys(get_object_vars($this));
} | Set the statement to null when serializing.
@return array | __sleep | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function setFetchMode($mode)
{
$params=func_get_args();
$this->_fetchMode = $params;
return $this;
} | Set the default fetch mode for this statement
@param mixed $mode fetch mode
@return static
@see https://www.php.net/manual/en/function.PDOStatement-setFetchMode.php
@since 1.1.7 | setFetchMode | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function reset()
{
$this->_text=null;
$this->_query=null;
$this->_statement=null;
$this->_paramLog=array();
$this->params=array();
return $this;
} | Cleans up the command and prepares for building a new query.
This method is mainly used when a command object is being reused
multiple times for building different queries.
Calling this method will clean up all internal states of the command object.
@return static this command instance
@since 1.1.6 | reset | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function setText($value)
{
if($this->_connection->tablePrefix!==null && $value!='')
$this->_text=preg_replace('/{{(.*?)}}/',$this->_connection->tablePrefix.'\1',$value);
else
$this->_text=$value;
$this->cancel();
return $this;
} | Specifies the SQL statement to be executed.
Any previous execution will be terminated or cancel.
@param string $value the SQL statement to be executed
@return static this command instance | setText | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function getPdoStatement()
{
return $this->_statement;
} | @return PDOStatement the underlying PDOStatement for this command
It could be null if the statement is not prepared yet. | getPdoStatement | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
public function prepare()
{
if($this->_statement==null)
{
try
{
$this->_statement=$this->getConnection()->getPdoInstance()->prepare($this->getText());
$this->_paramLog=array();
}
catch(Exception $e)
{
Yii::log('Error in preparing SQL: '.$this->getText(),CLogger::LEVEL_ERROR,'system.db.CDbCommand');
$errorInfo=$e instanceof PDOException ? $e->errorInfo : null;
throw new CDbException(Yii::t('yii','CDbCommand failed to prepare the SQL statement: {error}',
array('{error}'=>$e->getMessage())),(int)$e->getCode(),$errorInfo);
}
}
} | Prepares the SQL statement to be executed.
For complex SQL statement that is to be executed multiple times,
this may improve performance.
For SQL statement with binding parameters, this method is invoked
automatically.
@throws CDbException if CDbCommand failed to prepare the SQL statement | prepare | php | yiisoft/yii | framework/db/CDbCommand.php | https://github.com/yiisoft/yii/blob/master/framework/db/CDbCommand.php | BSD-3-Clause |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.