code
stringlengths 17
247k
| 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 |
---|---|---|---|---|---|---|---|
public function init()
{
parent::init();
if(empty($this->updateSelector))
throw new CException(Yii::t('zii','The property updateSelector should be defined.'));
if(empty($this->filterSelector))
throw new CException(Yii::t('zii','The property filterSelector should be defined.'));
if(!isset($this->htmlOptions['class']))
$this->htmlOptions['class']='grid-view';
if($this->baseScriptUrl===null)
$this->baseScriptUrl=Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('zii.widgets.assets')).'/gridview';
if($this->cssFile!==false)
{
if($this->cssFile===null)
$this->cssFile=$this->baseScriptUrl.'/styles.css';
Yii::app()->getClientScript()->registerCssFile($this->cssFile);
}
$this->initColumns();
} | Initializes the grid view.
This method will initialize required property values and instantiate {@link columns} objects. | init | php | yiisoft/yii | framework/zii/widgets/grid/CGridView.php | https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/grid/CGridView.php | BSD-3-Clause |
public function renderItems()
{
if($this->dataProvider->getItemCount()>0 || $this->showTableOnEmpty)
{
echo "<table class=\"{$this->itemsCssClass}\">\n";
$this->renderTableHeader();
ob_start();
$this->renderTableBody();
$body=ob_get_clean();
$this->renderTableFooter();
echo $body; // TFOOT must appear before TBODY according to the standard.
echo "</table>";
}
else
$this->renderEmptyText();
} | Renders the data items for the grid view. | renderItems | php | yiisoft/yii | framework/zii/widgets/grid/CGridView.php | https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/grid/CGridView.php | BSD-3-Clause |
protected function renderDataCell($column, $row)
{
$column->renderDataCell($row);
} | A seam for people extending CGridView to be able to hook onto the data cell rendering process.
By overriding only this method we will not need to copypaste and modify the whole entirety of `renderTableRow`.
Or override `renderDataCell()` method of all possible CGridColumn descendants.
@param CGridColumn $column The Column instance to
@param integer $row
@since 1.1.16 | renderDataCell | php | yiisoft/yii | framework/zii/widgets/grid/CGridView.php | https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/grid/CGridView.php | BSD-3-Clause |
protected function registerClientScript()
{
$js=array();
foreach($this->buttons as $id=>$button)
{
if(isset($button['click']))
{
$function=CJavaScript::encode($button['click']);
$class=preg_replace('/\s+/','.',$button['options']['class']);
$js[]="jQuery(document).on('click','#{$this->grid->id} a.{$class}',$function);";
}
}
if($js!==array())
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$this->id, implode("\n",$js));
} | Registers the client scripts for the button column. | registerClientScript | php | yiisoft/yii | framework/zii/widgets/grid/CButtonColumn.php | https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/grid/CButtonColumn.php | BSD-3-Clause |
public function getHeaderCellContent()
{
return $this->header!==null && trim($this->header)!=='' ? $this->header : $this->grid->blankDisplay;
} | Returns the header cell content.
The default implementation simply returns {@link header}.
This method may be overridden to customize the rendering of the header cell.
@return string the header cell content.
@since 1.1.16 | getHeaderCellContent | php | yiisoft/yii | framework/zii/widgets/grid/CGridColumn.php | https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/grid/CGridColumn.php | BSD-3-Clause |
protected function renderHeaderCellContent()
{
echo $this->getHeaderCellContent();
} | Renders the header cell content.
@deprecated since 1.1.16. Use {@link getHeaderCellContent()} instead. | renderHeaderCellContent | php | yiisoft/yii | framework/zii/widgets/grid/CGridColumn.php | https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/grid/CGridColumn.php | BSD-3-Clause |
public function getFooterCellContent()
{
return $this->footer!==null && trim($this->footer)!=='' ? $this->footer : $this->grid->blankDisplay;
} | Returns the footer cell content.
The default implementation simply returns {@link footer}.
This method may be overridden to customize the rendering of the footer cell.
@return string the footer cell content.
@since 1.1.16 | getFooterCellContent | php | yiisoft/yii | framework/zii/widgets/grid/CGridColumn.php | https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/grid/CGridColumn.php | BSD-3-Clause |
protected function renderFooterCellContent()
{
echo $this->getFooterCellContent();
} | Renders the footer cell content.
@deprecated since 1.1.16. Use {@link getFooterCellContent()} instead. | renderFooterCellContent | php | yiisoft/yii | framework/zii/widgets/grid/CGridColumn.php | https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/grid/CGridColumn.php | BSD-3-Clause |
public function getDataCellContent($row)
{
return $this->grid->blankDisplay;
} | Returns the data cell content.
This method SHOULD be overridden to customize the rendering of the data cell.
@param integer $row the row number (zero-based)
The data for this row is available via <code>$this->grid->dataProvider->data[$row];</code>
@return string the data cell content.
@since 1.1.16 | getDataCellContent | php | yiisoft/yii | framework/zii/widgets/grid/CGridColumn.php | https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/grid/CGridColumn.php | BSD-3-Clause |
protected function renderDataCellContent($row,$data)
{
echo $this->getDataCellContent($row);
} | Renders the data cell content.
@param integer $row the row number (zero-based)
@param mixed $data the data associated with the row
@deprecated since 1.1.16. Use {@link getDataCellContent()} instead. | renderDataCellContent | php | yiisoft/yii | framework/zii/widgets/grid/CGridColumn.php | https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/grid/CGridColumn.php | BSD-3-Clause |
public function getFilterCellContent()
{
return $this->grid->blankDisplay;
} | Returns the filter cell content.
The default implementation simply returns an empty column.
This method may be overridden to customize the rendering of the filter cell (if any).
@return string the filter cell content.
@since 1.1.16 | getFilterCellContent | php | yiisoft/yii | framework/zii/widgets/grid/CGridColumn.php | https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/grid/CGridColumn.php | BSD-3-Clause |
protected function renderFilterCellContent()
{
echo $this->getFilterCellContent();
} | Renders the filter cell content.
@since 1.1.1
@deprecated since 1.1.16. Use {@link getFilterCellContent()} instead. | renderFilterCellContent | php | yiisoft/yii | framework/zii/widgets/grid/CGridColumn.php | https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/grid/CGridColumn.php | BSD-3-Clause |
public function getHeaderCellContent()
{
if(trim($this->headerTemplate)==='')
return $this->grid->blankDisplay;
if($this->selectableRows===null && $this->grid->selectableRows>1)
$item=CHtml::checkBox($this->id.'_all',false,array('class'=>'select-on-check-all'));
elseif($this->selectableRows>1)
$item=CHtml::checkBox($this->id.'_all',false);
else
$item=parent::getHeaderCellContent();
return strtr($this->headerTemplate,array(
'{item}'=>$item,
));
} | Returns the header cell content.
This method will render a checkbox in the header when {@link selectableRows} is greater than 1
or in case {@link selectableRows} is null when {@link CGridView::selectableRows} is greater than 1.
@return string the header cell content.
@since 1.1.16 | getHeaderCellContent | php | yiisoft/yii | framework/zii/widgets/grid/CCheckBoxColumn.php | https://github.com/yiisoft/yii/blob/master/framework/zii/widgets/grid/CCheckBoxColumn.php | BSD-3-Clause |
public function init()
{
parent::init();
if($this->keyPrefix===null)
$this->keyPrefix=Yii::app()->getId();
} | Initializes the application component.
This method overrides the parent implementation by setting default cache key prefix. | init | php | yiisoft/yii | framework/caching/CDummyCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CDummyCache.php | BSD-3-Clause |
public function get($id)
{
return false;
} | Retrieves a value from cache with a specified key.
@param string $id a key identifying the cached value
@return mixed the value stored in cache, false if the value is not in the cache, expired or the dependency has changed. | get | php | yiisoft/yii | framework/caching/CDummyCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CDummyCache.php | BSD-3-Clause |
public function mget($ids)
{
$results=array();
foreach($ids as $id)
$results[$id]=false;
return $results;
} | Retrieves multiple values from cache with the specified keys.
Some caches (such as memcache, apc) allow retrieving multiple cached values at one time,
which may improve the performance since it reduces the communication cost.
In case a cache doesn't support this feature natively, it will be simulated by this method.
@param array $ids list of 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. | mget | php | yiisoft/yii | framework/caching/CDummyCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CDummyCache.php | BSD-3-Clause |
public function set($id,$value,$expire=0,$dependency=null)
{
return true;
} | Stores a value identified by a key into cache.
If the cache already contains such a key, the existing value and
expiration time will be replaced with the new ones.
@param string $id the key identifying the value to be cached
@param mixed $value the value to be cached
@param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
@param ICacheDependency $dependency dependency of the cached item. If the dependency changes, the item is labeled invalid.
@return boolean true if the value is successfully stored into cache, false otherwise | set | php | yiisoft/yii | framework/caching/CDummyCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CDummyCache.php | BSD-3-Clause |
public function add($id,$value,$expire=0,$dependency=null)
{
return true;
} | Stores a value identified by a key into cache if the cache does not contain this key.
Nothing will be done if the cache already contains the key.
@param string $id the key identifying the value to be cached
@param mixed $value the value to be cached
@param integer $expire the number of seconds in which the cached value will expire. 0 means never expire.
@param ICacheDependency $dependency dependency of the cached item. If the dependency changes, the item is labeled invalid.
@return boolean true if the value is successfully stored into cache, false otherwise | add | php | yiisoft/yii | framework/caching/CDummyCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CDummyCache.php | BSD-3-Clause |
public function delete($id)
{
return true;
} | Deletes a value with the specified key from cache
@param string $id the key of the value to be deleted
@return boolean if no error happens during deletion | delete | php | yiisoft/yii | framework/caching/CDummyCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CDummyCache.php | BSD-3-Clause |
public function flush()
{
return true;
} | Deletes all values from cache.
Be careful of performing this operation if the cache is shared by multiple applications.
@return boolean whether the flush operation was successful.
@throws CException if this method is not overridden by child classes | flush | php | yiisoft/yii | framework/caching/CDummyCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CDummyCache.php | BSD-3-Clause |
public function offsetExists($id)
{
return false;
} | Returns whether there is a cache entry with a specified key.
This method is required by the interface ArrayAccess.
@param string $id a key identifying the cached value
@return boolean | offsetExists | php | yiisoft/yii | framework/caching/CDummyCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CDummyCache.php | BSD-3-Clause |
public function offsetGet($id)
{
return false;
} | Retrieves the value from cache with a specified key.
This method is required by the interface ArrayAccess.
@param string $id a key identifying the cached value
@return mixed the value stored in cache, false if the value is not in the cache or expired. | offsetGet | php | yiisoft/yii | framework/caching/CDummyCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CDummyCache.php | BSD-3-Clause |
public function offsetSet($id, $value)
{
} | Stores the value identified by a key into cache.
If the cache already contains such a key, the existing value will be
replaced with the new ones. To add expiration and dependencies, use the set() method.
This method is required by the interface ArrayAccess.
@param string $id the key identifying the value to be cached
@param mixed $value the value to be cached | offsetSet | php | yiisoft/yii | framework/caching/CDummyCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CDummyCache.php | BSD-3-Clause |
public function offsetUnset($id)
{
} | Deletes the value with the specified key from cache
This method is required by the interface ArrayAccess.
@param string $id the key of the value to be deleted | offsetUnset | php | yiisoft/yii | framework/caching/CDummyCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CDummyCache.php | BSD-3-Clause |
public function init()
{
parent::init();
$extension=$this->useApcu ? 'apcu' : 'apc';
if(!extension_loaded($extension))
throw new CException(Yii::t('yii',"CApcCache requires PHP {extension} extension to be loaded.",
array('{extension}'=>$extension)));
} | Initializes this application component.
This method is required by the {@link IApplicationComponent} interface.
It checks the availability of APC.
@throws CException if APC cache extension is not loaded or is disabled. | init | php | yiisoft/yii | framework/caching/CApcCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CApcCache.php | BSD-3-Clause |
protected function getValue($key)
{
return $this->useApcu ? apcu_fetch($key) : apc_fetch($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/CApcCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CApcCache.php | BSD-3-Clause |
protected function getValues($keys)
{
return $this->useApcu ? apcu_fetch($keys) : apc_fetch($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/CApcCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CApcCache.php | BSD-3-Clause |
protected function setValue($key,$value,$expire)
{
return $this->useApcu ? apcu_store($key,$value,$expire) : apc_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/CApcCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CApcCache.php | BSD-3-Clause |
protected function addValue($key,$value,$expire)
{
return $this->useApcu ? apcu_add($key,$value,$expire) : apc_add($key,$value,$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 $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/CApcCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CApcCache.php | BSD-3-Clause |
protected function deleteValue($key)
{
return $this->useApcu ? apcu_delete($key) : apc_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/CApcCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CApcCache.php | BSD-3-Clause |
protected function flushValues()
{
return $this->useApcu ? apcu_clear_cache() : apc_clear_cache('user');
} | 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/CApcCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CApcCache.php | BSD-3-Clause |
public function init()
{
parent::init();
if(!extension_loaded('wincache'))
throw new CException(Yii::t('yii', 'CWinCache requires PHP wincache extension to be loaded.'));
if(!ini_get('wincache.ucenabled'))
throw new CException(Yii::t('yii', 'CWinCache user cache is disabled. Please set wincache.ucenabled to On in your php.ini.'));
} | Initializes this application component.
This method is required by the {@link IApplicationComponent} interface.
It checks the availability of WinCache extension and WinCache user cache.
@throws CException if WinCache extension is not loaded or user cache is disabled | init | php | yiisoft/yii | framework/caching/CWinCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CWinCache.php | BSD-3-Clause |
public function mget($ids)
{
$uids = array();
foreach ($ids as $id)
$uids[$id] = $this->generateUniqueKey($id);
$values = $this->getValues($uids);
$results = array();
if($this->serializer === false)
{
foreach ($uids as $id => $uid)
$results[$id] = isset($values[$uid]) ? $values[$uid] : false;
}
else
{
foreach($uids as $id => $uid)
{
$results[$id] = false;
if(isset($values[$uid]))
{
$value = $this->serializer === null ? unserialize($values[$uid]) : call_user_func($this->serializer[1], $values[$uid]);
if(is_array($value) && (!$value[1] instanceof ICacheDependency || !$value[1]->getHasChanged()))
{
Yii::trace('Serving "'.$id.'" from cache','system.caching.'.get_class($this));
$results[$id] = $value[0];
}
}
}
}
return $results;
} | Retrieves multiple values from cache with the specified keys.
Some caches (such as memcache, apc) allow retrieving multiple cached values at one time,
which may improve the performance since it reduces the communication cost.
In case a cache does not support this feature natively, it will be simulated by this method.
@param array $ids list of 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. | mget | php | yiisoft/yii | framework/caching/CCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CCache.php | BSD-3-Clause |
public function flush()
{
Yii::trace('Flushing cache','system.caching.'.get_class($this));
return $this->flushValues();
} | Deletes all values from cache.
Be careful of performing this operation if the cache is shared by multiple applications.
@return boolean whether the flush operation was successful. | flush | php | yiisoft/yii | framework/caching/CCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CCache.php | BSD-3-Clause |
protected function getValue($key)
{
throw new CException(Yii::t('yii','{className} does not support get() functionality.',
array('{className}'=>get_class($this))));
} | Retrieves a value from cache with a specified key.
This method should be implemented by child classes to retrieve the data
from specific cache storage. The uniqueness and dependency are handled
in {@link get()} already. So only the implementation of data retrieval
is needed.
@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.
@throws CException if this method is not overridden by child classes | getValue | php | yiisoft/yii | framework/caching/CCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CCache.php | BSD-3-Clause |
protected function getValues($keys)
{
$results=array();
foreach($keys as $key)
$results[$key]=$this->getValue($key);
return $results;
} | Retrieves multiple values from cache with the specified keys.
The default implementation simply calls {@link getValue} multiple
times to retrieve the cached values one by one.
If the underlying cache storage supports multiget, this method should
be overridden to exploit that feature.
@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/CCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CCache.php | BSD-3-Clause |
protected function setValue($key,$value,$expire)
{
throw new CException(Yii::t('yii','{className} does not support set() functionality.',
array('{className}'=>get_class($this))));
} | Stores a value identified by a key in cache.
This method should be implemented by child classes to store the data
in specific cache storage. The uniqueness and dependency are handled
in {@link set()} already. So only the implementation of data storage
is needed.
@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
@throws CException if this method is not overridden by child classes | setValue | php | yiisoft/yii | framework/caching/CCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CCache.php | BSD-3-Clause |
protected function addValue($key,$value,$expire)
{
throw new CException(Yii::t('yii','{className} does not support add() functionality.',
array('{className}'=>get_class($this))));
} | Stores a value identified by a key into cache if the cache does not contain this key.
This method should be implemented by child classes to store the data
in specific cache storage. The uniqueness and dependency are handled
in {@link add()} already. So only the implementation of data storage
is needed.
@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
@throws CException if this method is not overridden by child classes | addValue | php | yiisoft/yii | framework/caching/CCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CCache.php | BSD-3-Clause |
protected function deleteValue($key)
{
throw new CException(Yii::t('yii','{className} does not support delete() functionality.',
array('{className}'=>get_class($this))));
} | Deletes a value with the specified key from cache
This method should be implemented by child classes to delete the data from actual cache storage.
@param string $key the key of the value to be deleted
@return boolean if no error happens during deletion
@throws CException if this method is not overridden by child classes | deleteValue | php | yiisoft/yii | framework/caching/CCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CCache.php | BSD-3-Clause |
protected function flushValues()
{
throw new CException(Yii::t('yii','{className} does not support flushValues() functionality.',
array('{className}'=>get_class($this))));
} | Deletes all values from cache.
Child classes may implement this method to realize the flush operation.
@return boolean whether the flush operation was successful.
@throws CException if this method is not overridden by child classes
@since 1.1.5 | flushValues | php | yiisoft/yii | framework/caching/CCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CCache.php | BSD-3-Clause |
public function init()
{
parent::init();
if(!function_exists('xcache_isset'))
throw new CException(Yii::t('yii','CXCache requires PHP XCache extension to be loaded.'));
} | Initializes this application component.
This method is required by the {@link IApplicationComponent} interface.
It checks the availability of memcache.
@throws CException if memcache extension is not loaded or is disabled. | init | php | yiisoft/yii | framework/caching/CXCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CXCache.php | BSD-3-Clause |
protected function connect()
{
$address = $this->unixSocket ? 'unix://'.$this->unixSocket : $this->hostname.':'.$this->port;
$this->_socket=@stream_socket_client(
$address,
$errorNumber,
$errorDescription,
$this->timeout ? $this->timeout : ini_get("default_socket_timeout"),
$this->options
);
if ($this->_socket)
{
if($this->ssl)
stream_socket_enable_crypto($this->_socket,true,STREAM_CRYPTO_METHOD_TLS_CLIENT);
if ($this->password !== null) {
if ($this->username !== null) {
$this->executeCommand('AUTH',array($this->username, $this->password));
} else {
$this->executeCommand('AUTH',array($this->password));
}
}
$this->executeCommand('SELECT',array($this->database));
}
else
{
$this->_socket = null;
throw new CException('Failed to connect to redis: '.$errorDescription,(int)$errorNumber);
}
} | Establishes a connection to the redis server.
It does nothing if the connection has already been established.
@throws CException if connecting fails | connect | php | yiisoft/yii | framework/caching/CRedisCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CRedisCache.php | BSD-3-Clause |
private function parseResponse()
{
if(($line=fgets($this->_socket))===false)
throw new CException('Failed reading data from redis connection socket.');
$type=$line[0];
$line=substr($line,1,-2);
switch($type)
{
case '+': // Status reply
return true;
case '-': // Error reply
throw new CException('Redis error: '.$line);
case ':': // Integer reply
// no cast to int as it is in the range of a signed 64 bit integer
return $line;
case '$': // Bulk replies
if($line=='-1')
return null;
$length=$line+2;
$data='';
while($length>0)
{
if(($block=fread($this->_socket,$length))===false)
throw new CException('Failed reading data from redis connection socket.');
$data.=$block;
$length-=$this->byteLength($block);
}
return substr($data,0,-2);
case '*': // Multi-bulk replies
$count=(int)$line;
$data=array();
for($i=0;$i<$count;$i++)
$data[]=$this->parseResponse();
return $data;
default:
throw new CException('Unable to parse data received from redis.');
}
} | Reads the result from socket and parses it
@return array|bool|null|string
@throws CException socket or data problems | parseResponse | php | yiisoft/yii | framework/caching/CRedisCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CRedisCache.php | BSD-3-Clause |
private function byteLength($str)
{
return function_exists('mb_strlen') ? mb_strlen($str, '8bit') : strlen($str);
} | Counting amount of bytes in a string.
@param string $str
@return int | byteLength | php | yiisoft/yii | framework/caching/CRedisCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CRedisCache.php | BSD-3-Clause |
protected function flushValues()
{
return $this->executeCommand('FLUSHDB');
} | 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. | flushValues | php | yiisoft/yii | framework/caching/CRedisCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CRedisCache.php | BSD-3-Clause |
public function init()
{
parent::init();
if(!function_exists('eaccelerator_get'))
throw new CException(Yii::t('yii','CEAcceleratorCache requires PHP eAccelerator extension to be loaded, enabled or compiled with the "--with-eaccelerator-shared-memory" option.'));
} | Initializes this application component.
This method is required by the {@link IApplicationComponent} interface.
It checks the availability of eAccelerator.
@throws CException if eAccelerator extension is not loaded, is disabled or the cache functions are not compiled in. | init | php | yiisoft/yii | framework/caching/CEAcceleratorCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CEAcceleratorCache.php | BSD-3-Clause |
public function init()
{
parent::init();
if($this->cachePath===null)
$this->cachePath=Yii::app()->getRuntimePath().DIRECTORY_SEPARATOR.'cache';
if(!is_dir($this->cachePath))
{
mkdir($this->cachePath,$this->cachePathMode,true);
chmod($this->cachePath,$this->cachePathMode);
}
} | Initializes this application component.
This method is required by the {@link IApplicationComponent} interface. | init | php | yiisoft/yii | framework/caching/CFileCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CFileCache.php | BSD-3-Clause |
public function getGCProbability()
{
return $this->_gcProbability;
} | @return integer the probability (parts per million) that garbage collection (GC) should be performed
when storing a piece of data in the cache. Defaults to 100, meaning 0.01% chance. | getGCProbability | php | yiisoft/yii | framework/caching/CFileCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CFileCache.php | BSD-3-Clause |
public function setGCProbability($value)
{
$value=(int)$value;
if($value<0)
$value=0;
if($value>1000000)
$value=1000000;
$this->_gcProbability=$value;
} | @param integer $value the probability (parts per million) that garbage collection (GC) should be performed
when storing a piece of data in the cache. Defaults to 100, meaning 0.01% chance.
This number should be between 0 and 1000000. A value 0 meaning no GC will be performed at all. | setGCProbability | php | yiisoft/yii | framework/caching/CFileCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CFileCache.php | BSD-3-Clause |
protected function getCacheFile($key)
{
if($this->directoryLevel>0)
{
$base=$this->cachePath;
for($i=0;$i<$this->directoryLevel;++$i)
{
if(($prefix=substr($key,$i+$i,2))!==false)
$base.=DIRECTORY_SEPARATOR.$prefix;
}
return $base.DIRECTORY_SEPARATOR.$key.$this->cacheFileSuffix;
}
else
return $this->cachePath.DIRECTORY_SEPARATOR.$key.$this->cacheFileSuffix;
} | Returns the cache file path given the cache key.
@param string $key cache key
@return string the cache file path | getCacheFile | php | yiisoft/yii | framework/caching/CFileCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CFileCache.php | BSD-3-Clause |
public function gc($expiredOnly=true,$path=null)
{
if($path===null)
$path=$this->cachePath;
if(($handle=opendir($path))===false)
return;
while(($file=readdir($handle))!==false)
{
if($file[0]==='.')
continue;
$fullPath=$path.DIRECTORY_SEPARATOR.$file;
if(is_dir($fullPath))
$this->gc($expiredOnly,$fullPath);
elseif($expiredOnly && $this->filemtime($fullPath)<time() || !$expiredOnly)
@unlink($fullPath);
}
closedir($handle);
} | Removes expired cache files.
@param boolean $expiredOnly whether only expired cache files should be removed.
If false, all cache files under {@link cachePath} will be removed.
@param string $path the path to clean with. If null, it will be {@link cachePath}. | gc | php | yiisoft/yii | framework/caching/CFileCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CFileCache.php | BSD-3-Clause |
public function init()
{
parent::init();
$db=$this->getDbConnection();
$db->setActive(true);
if($this->autoCreateCacheTable)
{
$sql="DELETE FROM {$this->cacheTableName} WHERE expire>0 AND expire<".time();
try
{
$db->createCommand($sql)->execute();
}
catch(Exception $e)
{
$this->createCacheTable($db,$this->cacheTableName);
}
}
} | Initializes this application component.
This method is required by the {@link IApplicationComponent} interface.
It ensures the existence of the cache DB table.
It also removes expired data items from the cache. | init | php | yiisoft/yii | framework/caching/CDbCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CDbCache.php | BSD-3-Clause |
public function setDbConnection($value)
{
$this->_db=$value;
} | Sets the DB connection used by the cache component.
@param CDbConnection $value the DB connection instance
@since 1.1.5 | setDbConnection | php | yiisoft/yii | framework/caching/CDbCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CDbCache.php | BSD-3-Clause |
protected function gc()
{
$this->getDbConnection()->createCommand("DELETE FROM {$this->cacheTableName} WHERE expire>0 AND expire<".time())->execute();
} | Removes the expired data values. | gc | php | yiisoft/yii | framework/caching/CDbCache.php | https://github.com/yiisoft/yii/blob/master/framework/caching/CDbCache.php | BSD-3-Clause |
public function init()
{
parent::init();
if(!function_exists('zend_shm_cache_store'))
throw new CException(Yii::t('yii','CZendDataCache requires PHP Zend Data Cache extension to be loaded.'));
} | Initializes this application component.
This method is required by the {@link IApplicationComponent} interface.
It checks the availability of Zend Data Cache.
@throws CException if Zend Data Cache extension is not loaded. | init | 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 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 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 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 |
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 |
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 |
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 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 |
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 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.