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
public function authenticate() { throw new CException(Yii::t('yii','{class}::authenticate() must be implemented.',array('{class}'=>get_class($this)))); }
Authenticates a user based on {@link username} and {@link password}. Derived classes should override this method, or an exception will be thrown. This method is required by {@link IUserIdentity}. @return boolean whether authentication succeeds. @throws CException
authenticate
php
yiisoft/yii
framework/web/auth/CUserIdentity.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CUserIdentity.php
BSD-3-Clause
public function getId() { return $this->username; }
Returns the unique identifier for the identity. The default implementation simply returns {@link username}. This method is required by {@link IUserIdentity}. @return string the unique identifier for the identity.
getId
php
yiisoft/yii
framework/web/auth/CUserIdentity.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CUserIdentity.php
BSD-3-Clause
public function getName() { return $this->username; }
Returns the display name for the identity. The default implementation simply returns {@link username}. This method is required by {@link IUserIdentity}. @return string the display name for the identity.
getName
php
yiisoft/yii
framework/web/auth/CUserIdentity.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CUserIdentity.php
BSD-3-Clause
public function getId() { return $this->getName(); }
Returns a value that uniquely represents the identity. @return mixed a value that uniquely represents the identity (e.g. primary key value). The default implementation simply returns {@link name}.
getId
php
yiisoft/yii
framework/web/auth/CBaseUserIdentity.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CBaseUserIdentity.php
BSD-3-Clause
public function getName() { return ''; }
Returns the display name for the identity (e.g. username). @return string the display name for the identity. The default implementation simply returns empty string.
getName
php
yiisoft/yii
framework/web/auth/CBaseUserIdentity.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CBaseUserIdentity.php
BSD-3-Clause
public function getPersistentStates() { return $this->_state; }
Returns the identity states that should be persisted. This method is required by {@link IUserIdentity}. @return array the identity states that should be persisted.
getPersistentStates
php
yiisoft/yii
framework/web/auth/CBaseUserIdentity.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CBaseUserIdentity.php
BSD-3-Clause
public function setPersistentStates($states) { $this->_state = $states; }
Sets an array of persistent states. @param array $states the identity states that should be persisted.
setPersistentStates
php
yiisoft/yii
framework/web/auth/CBaseUserIdentity.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CBaseUserIdentity.php
BSD-3-Clause
public function getIsAuthenticated() { return $this->errorCode==self::ERROR_NONE; }
Returns a value indicating whether the identity is authenticated. This method is required by {@link IUserIdentity}. @return boolean whether the authentication is successful.
getIsAuthenticated
php
yiisoft/yii
framework/web/auth/CBaseUserIdentity.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CBaseUserIdentity.php
BSD-3-Clause
public function getState($name,$defaultValue=null) { return isset($this->_state[$name])?$this->_state[$name]:$defaultValue; }
Gets the persisted state by the specified name. @param string $name the name of the state @param mixed $defaultValue the default value to be returned if the named state does not exist @return mixed the value of the named state
getState
php
yiisoft/yii
framework/web/auth/CBaseUserIdentity.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CBaseUserIdentity.php
BSD-3-Clause
public function setState($name,$value) { $this->_state[$name]=$value; }
Sets the named state with a given value. @param string $name the name of the state @param mixed $value the value of the named state
setState
php
yiisoft/yii
framework/web/auth/CBaseUserIdentity.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CBaseUserIdentity.php
BSD-3-Clause
public function init() { parent::init(); if($this->authFile===null) $this->authFile=Yii::getPathOfAlias('application.data.auth').'.php'; $this->load(); }
Initializes the application component. This method overrides parent implementation by loading the authorization data from PHP script.
init
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
public function removeItemChild($itemName,$childName) { if(isset($this->_children[$itemName][$childName])) { unset($this->_children[$itemName][$childName]); return true; } else return false; }
Removes a child from its parent. Note, the child item is not deleted. Only the parent-child relationship is removed. @param string $itemName the parent item name @param string $childName the child item name @return boolean whether the removal is successful
removeItemChild
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
public function hasItemChild($itemName,$childName) { return isset($this->_children[$itemName][$childName]); }
Returns a value indicating whether a child exists within a parent. @param string $itemName the parent item name @param string $childName the child item name @return boolean whether the child exists
hasItemChild
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
public function revoke($itemName,$userId) { if(isset($this->_assignments[$userId][$itemName])) { unset($this->_assignments[$userId][$itemName]); return true; } else return false; }
Revokes an authorization assignment from a user. @param string $itemName the item name @param mixed $userId the user ID (see {@link IWebUser::getId}) @return boolean whether removal is successful
revoke
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
public function isAssigned($itemName,$userId) { return isset($this->_assignments[$userId][$itemName]); }
Returns a value indicating whether the item has been assigned to the user. @param string $itemName the item name @param mixed $userId the user ID (see {@link IWebUser::getId}) @return boolean whether the item has been assigned to the user.
isAssigned
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
public function getAuthAssignment($itemName,$userId) { return isset($this->_assignments[$userId][$itemName])?$this->_assignments[$userId][$itemName]:null; }
Returns the item assignment information. @param string $itemName the item name @param mixed $userId the user ID (see {@link IWebUser::getId}) @return CAuthAssignment the item assignment information. Null is returned if the item is not assigned to the user.
getAuthAssignment
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
public function getAuthAssignments($userId) { return isset($this->_assignments[$userId])?$this->_assignments[$userId]:array(); }
Returns the item assignments for the specified user. @param mixed $userId the user ID (see {@link IWebUser::getId}) @return array the item assignment information for the user. An empty array will be returned if there is no item assigned to the user.
getAuthAssignments
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
public function getAuthItems($type=null,$userId=null) { if($type===null && $userId===null) return $this->_items; $items=array(); if($userId===null) { foreach($this->_items as $name=>$item) { if($item->getType()==$type) $items[$name]=$item; } } elseif(isset($this->_assignments[$userId])) { foreach($this->_assignments[$userId] as $assignment) { $name=$assignment->getItemName(); if(isset($this->_items[$name]) && ($type===null || $this->_items[$name]->getType()==$type)) $items[$name]=$this->_items[$name]; } } return $items; }
Returns the authorization items of the specific type and user. @param integer $type the item type (0: operation, 1: task, 2: role). Defaults to null, meaning returning all items regardless of their type. @param mixed $userId the user ID. Defaults to null, meaning returning all items even if they are not assigned to a user. @return array the authorization items of the specific type.
getAuthItems
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
public function createAuthItem($name,$type,$description='',$bizRule=null,$data=null) { if(isset($this->_items[$name])) throw new CException(Yii::t('yii','Unable to add an item whose name is the same as an existing item.')); return $this->_items[$name]=new CAuthItem($this,$name,$type,$description,$bizRule,$data); }
Creates an authorization item. An authorization item represents an action permission (e.g. creating a post). It has three types: operation, task and role. Authorization items form a hierarchy. Higher level items inherit permissions representing by lower level items. @param string $name the item name. This must be a unique identifier. @param integer $type the item type (0: operation, 1: task, 2: role). @param string $description description of the item @param string $bizRule business rule associated with the item. This is a piece of PHP code that will be executed when {@link checkAccess} is called for the item. @param mixed $data additional data associated with the item. @return CAuthItem the authorization item @throws CException if an item with the same name already exists
createAuthItem
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
public function removeAuthItem($name) { if(isset($this->_items[$name])) { foreach($this->_children as &$children) unset($children[$name]); foreach($this->_assignments as &$assignments) unset($assignments[$name]); unset($this->_items[$name]); return true; } else return false; }
Removes the specified authorization item. @param string $name the name of the item to be removed @return boolean whether the item exists in the storage and has been removed
removeAuthItem
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
public function getAuthItem($name) { return isset($this->_items[$name])?$this->_items[$name]:null; }
Returns the authorization item with the specified name. @param string $name the name of the item @return CAuthItem the authorization item. Null if the item cannot be found.
getAuthItem
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
public function saveAuthItem($item,$oldName=null) { if($oldName!==null && ($newName=$item->getName())!==$oldName) // name changed { if(isset($this->_items[$newName])) throw new CException(Yii::t('yii','Unable to change the item name. The name "{name}" is already used by another item.',array('{name}'=>$newName))); if(isset($this->_items[$oldName]) && $this->_items[$oldName]===$item) { unset($this->_items[$oldName]); $this->_items[$newName]=$item; if(isset($this->_children[$oldName])) { $this->_children[$newName]=$this->_children[$oldName]; unset($this->_children[$oldName]); } foreach($this->_children as &$children) { if(isset($children[$oldName])) { $children[$newName]=$children[$oldName]; unset($children[$oldName]); } } foreach($this->_assignments as &$assignments) { if(isset($assignments[$oldName])) { $assignments[$newName]=$assignments[$oldName]; unset($assignments[$oldName]); } } } } }
Saves an authorization item to persistent storage. @param CAuthItem $item the item to be saved. @param string $oldName the old item name. If null, it means the item name is not changed. @throws CException
saveAuthItem
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
public function saveAuthAssignment($assignment) { }
Saves the changes to an authorization assignment. @param CAuthAssignment $assignment the assignment that has been changed.
saveAuthAssignment
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
public function clearAll() { $this->clearAuthAssignments(); $this->_children=array(); $this->_items=array(); }
Removes all authorization data.
clearAll
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
public function clearAuthAssignments() { $this->_assignments=array(); }
Removes all authorization assignments.
clearAuthAssignments
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
protected function detectLoop($itemName,$childName) { if($childName===$itemName) return true; if(!isset($this->_children[$childName], $this->_items[$itemName])) return false; foreach($this->_children[$childName] as $child) { if($this->detectLoop($itemName,$child->getName())) return true; } return false; }
Checks whether there is a loop in the authorization item hierarchy. @param string $itemName parent item name @param string $childName the name of the child item that is to be added to the hierarchy @return boolean whether a loop exists
detectLoop
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
protected function loadFromFile($file) { if(is_file($file)) return require($file); else return array(); }
Loads the authorization data from a PHP script file. @param string $file the file path. @return array the authorization data @see saveToFile
loadFromFile
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
protected function saveToFile($data,$file) { file_put_contents($file,"<?php\nreturn ".var_export($data,true).";\n"); }
Saves the authorization data to a PHP script file. @param array $data the authorization data @param string $file the file path. @see loadFromFile
saveToFile
php
yiisoft/yii
framework/web/auth/CPhpAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CPhpAuthManager.php
BSD-3-Clause
public function init() { parent::init(); $this->_usingSqlite=!strncmp($this->getDbConnection()->getDriverName(),'sqlite',6); }
Initializes the application component. This method overrides the parent implementation by establishing the database connection.
init
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
protected function checkAccessRecursive($itemName,$userId,$params,$assignments) { if(($item=$this->getAuthItem($itemName))===null) return false; Yii::trace('Checking permission "'.$item->getName().'"','system.web.auth.CDbAuthManager'); if(!isset($params['userId'])) $params['userId'] = $userId; if($this->executeBizRule($item->getBizRule(),$params,$item->getData())) { if(in_array($itemName,$this->defaultRoles)) return true; if(isset($assignments[$itemName])) { $assignment=$assignments[$itemName]; if($this->executeBizRule($assignment->getBizRule(),$params,$assignment->getData())) return true; } $parents=$this->db->createCommand() ->select('parent') ->from($this->itemChildTable) ->where('child=:name', array(':name'=>$itemName)) ->queryColumn(); foreach($parents as $parent) { if($this->checkAccessRecursive($parent,$userId,$params,$assignments)) return true; } } return false; }
Performs access check for the specified user. This method is internally called by {@link checkAccess}. @param string $itemName the name of the operation that need access check @param mixed $userId the user ID. This should can be either an integer and a string representing the unique identifier of a user. See {@link IWebUser::getId}. @param array $params name-value pairs that would be passed to biz rules associated with the tasks and roles assigned to the user. Since version 1.1.11 a param with name 'userId' is added to this array, which holds the value of <code>$userId</code>. @param array $assignments the assignments to the specified user @return boolean whether the operations can be performed by the user. @since 1.1.3
checkAccessRecursive
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
public function removeItemChild($itemName,$childName) { return $this->db->createCommand() ->delete($this->itemChildTable, 'parent=:parent AND child=:child', array( ':parent'=>$itemName, ':child'=>$childName )) > 0; }
Removes a child from its parent. Note, the child item is not deleted. Only the parent-child relationship is removed. @param string $itemName the parent item name @param string $childName the child item name @return boolean whether the removal is successful
removeItemChild
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
public function hasItemChild($itemName,$childName) { return $this->db->createCommand() ->select('parent') ->from($this->itemChildTable) ->where('parent=:parent AND child=:child', array( ':parent'=>$itemName, ':child'=>$childName)) ->queryScalar() !== false; }
Returns a value indicating whether a child exists within a parent. @param string $itemName the parent item name @param string $childName the child item name @return boolean whether the child exists
hasItemChild
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
public function assign($itemName,$userId,$bizRule=null,$data=null) { if($this->usingSqlite() && $this->getAuthItem($itemName)===null) throw new CException(Yii::t('yii','The item "{name}" does not exist.',array('{name}'=>$itemName))); $this->db->createCommand() ->insert($this->assignmentTable, array( 'itemname'=>$itemName, 'userid'=>$userId, 'bizrule'=>$bizRule, 'data'=>serialize($data) )); return new CAuthAssignment($this,$itemName,$userId,$bizRule,$data); }
Assigns an authorization item to a user. @param string $itemName the item name @param mixed $userId the user ID (see {@link IWebUser::getId}) @param string $bizRule the business rule to be executed when {@link checkAccess} is called for this particular authorization item. @param mixed $data additional data associated with this assignment @return CAuthAssignment the authorization assignment information. @throws CException if the item does not exist or if the item has already been assigned to the user
assign
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
public function revoke($itemName,$userId) { return $this->db->createCommand() ->delete($this->assignmentTable, 'itemname=:itemname AND userid=:userid', array( ':itemname'=>$itemName, ':userid'=>$userId )) > 0; }
Revokes an authorization assignment from a user. @param string $itemName the item name @param mixed $userId the user ID (see {@link IWebUser::getId}) @return boolean whether removal is successful
revoke
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
public function isAssigned($itemName,$userId) { return $this->db->createCommand() ->select('itemname') ->from($this->assignmentTable) ->where('itemname=:itemname AND userid=:userid', array( ':itemname'=>$itemName, ':userid'=>$userId)) ->queryScalar() !== false; }
Returns a value indicating whether the item has been assigned to the user. @param string $itemName the item name @param mixed $userId the user ID (see {@link IWebUser::getId}) @return boolean whether the item has been assigned to the user.
isAssigned
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
public function getAuthAssignment($itemName,$userId) { $row=$this->db->createCommand() ->select() ->from($this->assignmentTable) ->where('itemname=:itemname AND userid=:userid', array( ':itemname'=>$itemName, ':userid'=>$userId)) ->queryRow(); if($row!==false) { if(($data=@unserialize($row['data']))===false) $data=null; return new CAuthAssignment($this,$row['itemname'],$row['userid'],$row['bizrule'],$data); } else return null; }
Returns the item assignment information. @param string $itemName the item name @param mixed $userId the user ID (see {@link IWebUser::getId}) @return CAuthAssignment the item assignment information. Null is returned if the item is not assigned to the user.
getAuthAssignment
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
public function saveAuthAssignment($assignment) { $this->db->createCommand() ->update($this->assignmentTable, array( 'bizrule'=>$assignment->getBizRule(), 'data'=>serialize($assignment->getData()), ), 'itemname=:itemname AND userid=:userid', array( 'itemname'=>$assignment->getItemName(), 'userid'=>$assignment->getUserId() )); }
Saves the changes to an authorization assignment. @param CAuthAssignment $assignment the assignment that has been changed.
saveAuthAssignment
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
public function createAuthItem($name,$type,$description='',$bizRule=null,$data=null) { $this->db->createCommand() ->insert($this->itemTable, array( 'name'=>$name, 'type'=>$type, 'description'=>$description, 'bizrule'=>$bizRule, 'data'=>serialize($data) )); return new CAuthItem($this,$name,$type,$description,$bizRule,$data); }
Creates an authorization item. An authorization item represents an action permission (e.g. creating a post). It has three types: operation, task and role. Authorization items form a hierarchy. Higher level items inherit permissions representing by lower level items. @param string $name the item name. This must be a unique identifier. @param integer $type the item type (0: operation, 1: task, 2: role). @param string $description description of the item @param string $bizRule business rule associated with the item. This is a piece of PHP code that will be executed when {@link checkAccess} is called for the item. @param mixed $data additional data associated with the item. @return CAuthItem the authorization item @throws CException if an item with the same name already exists
createAuthItem
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
public function removeAuthItem($name) { if($this->usingSqlite()) { $this->db->createCommand() ->delete($this->itemChildTable, 'parent=:name1 OR child=:name2', array( ':name1'=>$name, ':name2'=>$name )); $this->db->createCommand() ->delete($this->assignmentTable, 'itemname=:name', array( ':name'=>$name, )); } return $this->db->createCommand() ->delete($this->itemTable, 'name=:name', array( ':name'=>$name )) > 0; }
Removes the specified authorization item. @param string $name the name of the item to be removed @return boolean whether the item exists in the storage and has been removed
removeAuthItem
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
public function getAuthItem($name) { $row=$this->db->createCommand() ->select() ->from($this->itemTable) ->where('name=:name', array(':name'=>$name)) ->queryRow(); if($row!==false) { if(($data=@unserialize($row['data']))===false) $data=null; return new CAuthItem($this,$row['name'],$row['type'],$row['description'],$row['bizrule'],$data); } else return null; }
Returns the authorization item with the specified name. @param string $name the name of the item @return CAuthItem the authorization item. Null if the item cannot be found.
getAuthItem
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
public function saveAuthItem($item,$oldName=null) { if($this->usingSqlite() && $oldName!==null && $item->getName()!==$oldName) { $this->db->createCommand() ->update($this->itemChildTable, array( 'parent'=>$item->getName(), ), 'parent=:whereName', array( ':whereName'=>$oldName, )); $this->db->createCommand() ->update($this->itemChildTable, array( 'child'=>$item->getName(), ), 'child=:whereName', array( ':whereName'=>$oldName, )); $this->db->createCommand() ->update($this->assignmentTable, array( 'itemname'=>$item->getName(), ), 'itemname=:whereName', array( ':whereName'=>$oldName, )); } $this->db->createCommand() ->update($this->itemTable, array( 'name'=>$item->getName(), 'type'=>$item->getType(), 'description'=>$item->getDescription(), 'bizrule'=>$item->getBizRule(), 'data'=>serialize($item->getData()), ), 'name=:whereName', array( ':whereName'=>$oldName===null?$item->getName():$oldName, )); }
Saves an authorization item to persistent storage. @param CAuthItem $item the item to be saved. @param string $oldName the old item name. If null, it means the item name is not changed.
saveAuthItem
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
public function save() { }
Saves the authorization data to persistent storage.
save
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
public function clearAll() { $this->clearAuthAssignments(); $this->db->createCommand()->delete($this->itemChildTable); $this->db->createCommand()->delete($this->itemTable); }
Removes all authorization data.
clearAll
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
public function clearAuthAssignments() { $this->db->createCommand()->delete($this->assignmentTable); }
Removes all authorization assignments.
clearAuthAssignments
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
protected function detectLoop($itemName,$childName) { if($childName===$itemName) return true; foreach($this->getItemChildren($childName) as $child) { if($this->detectLoop($itemName,$child->getName())) return true; } return false; }
Checks whether there is a loop in the authorization item hierarchy. @param string $itemName parent item name @param string $childName the name of the child item that is to be added to the hierarchy @return boolean whether a loop exists
detectLoop
php
yiisoft/yii
framework/web/auth/CDbAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CDbAuthManager.php
BSD-3-Clause
public function __get($name) { if($this->hasState($name)) return $this->getState($name); else return parent::__get($name); }
PHP magic method. This method is overridden so that persistent states can be accessed like properties. @param string $name property name @return mixed property value
__get
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function __set($name,$value) { if($this->hasState($name)) $this->setState($name,$value); else parent::__set($name,$value); }
PHP magic method. This method is overridden so that persistent states can be set like properties. @param string $name property name @param mixed $value property value @throws CException
__set
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function __isset($name) { if($this->hasState($name)) return $this->getState($name)!==null; else return parent::__isset($name); }
PHP magic method. This method is overridden so that persistent states can also be checked for null value. @param string $name property name @return boolean
__isset
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function __unset($name) { if($this->hasState($name)) $this->setState($name,null); else parent::__unset($name); }
PHP magic method. This method is overridden so that persistent states can also be unset. @param string $name property name @throws CException if the property is read only.
__unset
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function init() { parent::init(); Yii::app()->getSession()->open(); if($this->getIsGuest() && $this->allowAutoLogin) $this->restoreFromCookie(); elseif($this->autoRenewCookie && $this->allowAutoLogin) $this->renewCookie(); if($this->autoUpdateFlash) $this->updateFlash(); $this->updateAuthStatus(); }
Initializes the application component. This method overrides the parent implementation by starting session, performing cookie-based authentication if enabled, and updating the flash variables.
init
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function logout($destroySession=true) { if($this->beforeLogout()) { if($this->allowAutoLogin) { Yii::app()->getRequest()->getCookies()->remove($this->getStateKeyPrefix()); if($this->identityCookie!==null) { $cookie=$this->createIdentityCookie($this->getStateKeyPrefix()); $cookie->value=''; $cookie->expire=0; Yii::app()->getRequest()->getCookies()->add($cookie->name,$cookie); } } if($destroySession) Yii::app()->getSession()->destroy(); else $this->clearStates(); $this->_access=array(); $this->afterLogout(); } }
Logs out the current user. This will remove authentication-related session data. If the parameter is true, the whole session will be destroyed as well. @param boolean $destroySession whether to destroy the whole session. Defaults to true. If false, then {@link clearStates} will be called, which removes only the data stored via {@link setState}.
logout
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function getIsGuest() { return $this->getState('__id')===null; }
Returns a value indicating whether the user is a guest (not authenticated). @return boolean whether the current application user is a guest.
getIsGuest
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function getId() { return $this->getState('__id'); }
Returns a value that uniquely represents the user. @return mixed the unique identifier for the user. If null, it means the user is a guest.
getId
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function getName() { if(($name=$this->getState('__name'))!==null) return $name; else return $this->guestName; }
Returns the unique identifier for the user (e.g. username). This is the unique identifier that is mainly used for display purpose. @return string the user name. If the user is not logged in, this will be {@link guestName}.
getName
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function setName($value) { $this->setState('__name',$value); }
Sets the unique identifier for the user (e.g. username). @param string $value the user name. @see getName
setName
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function getReturnUrl($defaultUrl=null) { if($defaultUrl===null) { $defaultReturnUrl=Yii::app()->getUrlManager()->showScriptName ? Yii::app()->getRequest()->getScriptUrl() : Yii::app()->getRequest()->getBaseUrl().'/'; } else { $defaultReturnUrl=CHtml::normalizeUrl($defaultUrl); } return $this->getState('__returnUrl',$defaultReturnUrl); }
Returns the URL that the user should be redirected to after successful login. This property is usually used by the login action. If the login is successful, the action should read this property and use it to redirect the user browser. @param string $defaultUrl the default return URL in case it was not set previously. If this is null, the application entry URL will be considered as the default return URL. @return string the URL that the user should be redirected to after login. @see loginRequired
getReturnUrl
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
protected function beforeLogin($id,$states,$fromCookie) { return true; }
This method is called before logging in a user. You may override this method to provide additional security check. For example, when the login is cookie-based, you may want to verify that the user ID together with a random token in the states can be found in the database. This will prevent hackers from faking arbitrary identity cookies even if they crack down the server private key. @param mixed $id the user ID. This is the same as returned by {@link getId()}. @param array $states a set of name-value pairs that are provided by the user identity. @param boolean $fromCookie whether the login is based on cookie @return boolean whether the user should be logged in @since 1.1.3
beforeLogin
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
protected function afterLogin($fromCookie) { }
This method is called after the user is successfully logged in. You may override this method to do some postprocessing (e.g. log the user login IP and time; load the user permission information). @param boolean $fromCookie whether the login is based on cookie. @since 1.1.3
afterLogin
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
protected function beforeLogout() { return true; }
This method is invoked when calling {@link logout} to log out a user. If this method return false, the logout action will be cancelled. You may override this method to provide additional check before logging out a user. @return boolean whether to log out the user @since 1.1.3
beforeLogout
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
protected function afterLogout() { }
This method is invoked right after a user is logged out. You may override this method to do some extra cleanup work for the user. @since 1.1.3
afterLogout
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
protected function restoreFromCookie() { $app=Yii::app(); $request=$app->getRequest(); $cookie=$request->getCookies()->itemAt($this->getStateKeyPrefix()); if($cookie && !empty($cookie->value) && is_string($cookie->value) && ($data=$app->getSecurityManager()->validateData($cookie->value))!==false) { $data=@unserialize($data); if(is_array($data) && isset($data[0],$data[1],$data[2],$data[3])) { list($id,$name,$duration,$states)=$data; if($this->beforeLogin($id,$states,true)) { $this->changeIdentity($id,$name,$states); if($this->autoRenewCookie) { $this->saveToCookie($duration); } $this->afterLogin(true); } } } }
Populates the current user object with the information obtained from cookie. This method is used when automatic login ({@link allowAutoLogin}) is enabled. The user identity information is recovered from cookie. Sufficient security measures are used to prevent cookie data from being tampered. @see saveToCookie
restoreFromCookie
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
protected function renewCookie() { $request=Yii::app()->getRequest(); $cookies=$request->getCookies(); $cookie=$cookies->itemAt($this->getStateKeyPrefix()); if($cookie && !empty($cookie->value) && ($data=Yii::app()->getSecurityManager()->validateData($cookie->value))!==false) { $data=@unserialize($data); if(is_array($data) && isset($data[0],$data[1],$data[2],$data[3])) { $this->saveToCookie($data[2]); } } }
Renews the identity cookie. This method will set the expiration time of the identity cookie to be the current time plus the originally specified cookie duration. @since 1.1.3
renewCookie
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
protected function saveToCookie($duration) { $app=Yii::app(); $cookie=$this->createIdentityCookie($this->getStateKeyPrefix()); $cookie->expire=time()+$duration; $data=array( $this->getId(), $this->getName(), $duration, $this->saveIdentityStates(), ); $cookie->value=$app->getSecurityManager()->hashData(serialize($data)); $app->getRequest()->getCookies()->add($cookie->name,$cookie); }
Saves necessary user data into a cookie. This method is used when automatic login ({@link allowAutoLogin}) is enabled. This method saves user ID, username, other identity states and a validation key to cookie. These information are used to do authentication next time when user visits the application. @param integer $duration number of seconds that the user can remain in logged-in status. Defaults to 0, meaning login till the user closes the browser. @see restoreFromCookie
saveToCookie
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
protected function createIdentityCookie($name) { $cookie=new CHttpCookie($name,''); if(is_array($this->identityCookie)) { foreach($this->identityCookie as $name=>$value) $cookie->$name=$value; } return $cookie; }
Creates a cookie to store identity information. @param string $name the cookie name @return CHttpCookie the cookie used to store identity information
createIdentityCookie
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function getState($key,$defaultValue=null) { $key=$this->getStateKeyPrefix().$key; return isset($_SESSION[$key]) ? $_SESSION[$key] : $defaultValue; }
Returns the value of a variable that is stored in user session. This function is designed to be used by CWebUser descendant classes who want to store additional user information in user session. A variable, if stored in user session using {@link setState} can be retrieved back using this function. @param string $key variable name @param mixed $defaultValue default value @return mixed the value of the variable. If it doesn't exist in the session, the provided default value will be returned @see setState
getState
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function setState($key,$value,$defaultValue=null) { $key=$this->getStateKeyPrefix().$key; if($value===$defaultValue) unset($_SESSION[$key]); else $_SESSION[$key]=$value; }
Stores a variable in user session. This function is designed to be used by CWebUser descendant classes who want to store additional user information in user session. By storing a variable using this function, the variable may be retrieved back later using {@link getState}. The variable will be persistent across page requests during a user session. @param string $key variable name @param mixed $value variable value @param mixed $defaultValue default value. If $value===$defaultValue, the variable will be removed from the session @see getState
setState
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function hasState($key) { $key=$this->getStateKeyPrefix().$key; return isset($_SESSION[$key]); }
Returns a value indicating whether there is a state of the specified name. @param string $key state name @return boolean whether there is a state of the specified name.
hasState
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function getFlashes($delete=true) { $flashes=array(); $prefix=$this->getStateKeyPrefix().self::FLASH_KEY_PREFIX; $keys=array_keys($_SESSION); $n=strlen($prefix); foreach($keys as $key) { if(!strncmp($key,$prefix,$n)) { $flashes[substr($key,$n)]=$_SESSION[$key]; if($delete) unset($_SESSION[$key]); } } if($delete) $this->setState(self::FLASH_COUNTERS,array()); return $flashes; }
Returns all flash messages. This method is similar to {@link getFlash} except that it returns all currently available flash messages. @param boolean $delete whether to delete the flash messages after calling this method. @return array flash messages (key => message). @since 1.1.3
getFlashes
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function getFlash($key,$defaultValue=null,$delete=true) { $value=$this->getState(self::FLASH_KEY_PREFIX.$key,$defaultValue); if($delete) $this->setFlash($key,null); return $value; }
Returns a flash message. A flash message is available only in the current and the next requests. @param string $key key identifying the flash message @param mixed $defaultValue value to be returned if the flash message is not available. @param boolean $delete whether to delete this flash message after accessing it. Defaults to true. @return mixed the message message
getFlash
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function setFlash($key,$value,$defaultValue=null) { $this->setState(self::FLASH_KEY_PREFIX.$key,$value,$defaultValue); $counters=$this->getState(self::FLASH_COUNTERS,array()); if($value===$defaultValue) unset($counters[$key]); else $counters[$key]=0; $this->setState(self::FLASH_COUNTERS,$counters,array()); }
Stores a flash message. A flash message is available only in the current and the next requests. @param string $key key identifying the flash message @param mixed $value flash message @param mixed $defaultValue if this value is the same as the flash message, the flash message will be removed. (Therefore, you can use setFlash('key',null) to remove a flash message.)
setFlash
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
protected function saveIdentityStates() { $states=array(); foreach($this->getState(self::STATES_VAR,array()) as $name=>$dummy) $states[$name]=$this->getState($name); return $states; }
Retrieves identity states from persistent storage and saves them as an array. @return array the identity states
saveIdentityStates
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
protected function updateAuthStatus() { if(($this->authTimeout!==null || $this->absoluteAuthTimeout!==null) && !$this->getIsGuest()) { $expires=$this->getState(self::AUTH_TIMEOUT_VAR); $expiresAbsolute=$this->getState(self::AUTH_ABSOLUTE_TIMEOUT_VAR); if ($expires!==null && $expires < time() || $expiresAbsolute!==null && $expiresAbsolute < time()) $this->logout(false); else $this->setState(self::AUTH_TIMEOUT_VAR,time()+$this->authTimeout); } }
Updates the authentication status according to {@link authTimeout}. If the user has been inactive for {@link authTimeout} seconds, or {link absoluteAuthTimeout} has passed, he will be automatically logged out. @since 1.1.7
updateAuthStatus
php
yiisoft/yii
framework/web/auth/CWebUser.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CWebUser.php
BSD-3-Clause
public function removeChild($name) { return $this->_auth->removeItemChild($this->_name,$name); }
Removes a child item. Note, the child item is not deleted. Only the parent-child relationship is removed. @param string $name the child item name @return boolean whether the removal is successful @see IAuthManager::removeItemChild
removeChild
php
yiisoft/yii
framework/web/auth/CAuthItem.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAuthItem.php
BSD-3-Clause
public function hasChild($name) { return $this->_auth->hasItemChild($this->_name,$name); }
Returns a value indicating whether a child exists @param string $name the child item name @return boolean whether the child exists @see IAuthManager::hasItemChild
hasChild
php
yiisoft/yii
framework/web/auth/CAuthItem.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAuthItem.php
BSD-3-Clause
public function getChildren() { return $this->_auth->getItemChildren($this->_name); }
Returns the children of this item. @return array all child items of this item. @see IAuthManager::getItemChildren
getChildren
php
yiisoft/yii
framework/web/auth/CAuthItem.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAuthItem.php
BSD-3-Clause
public function assign($userId,$bizRule=null,$data=null) { return $this->_auth->assign($this->_name,$userId,$bizRule,$data); }
Assigns this item to a user. @param mixed $userId the user ID (see {@link IWebUser::getId}) @param string $bizRule the business rule to be executed when {@link checkAccess} is called for this particular authorization item. @param mixed $data additional data associated with this assignment @return CAuthAssignment the authorization assignment information. @throws CException if the item has already been assigned to the user @see IAuthManager::assign
assign
php
yiisoft/yii
framework/web/auth/CAuthItem.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAuthItem.php
BSD-3-Clause
public function revoke($userId) { return $this->_auth->revoke($this->_name,$userId); }
Revokes an authorization assignment from a user. @param mixed $userId the user ID (see {@link IWebUser::getId}) @return boolean whether removal is successful @see IAuthManager::revoke
revoke
php
yiisoft/yii
framework/web/auth/CAuthItem.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAuthItem.php
BSD-3-Clause
public function isAssigned($userId) { return $this->_auth->isAssigned($this->_name,$userId); }
Returns a value indicating whether this item has been assigned to the user. @param mixed $userId the user ID (see {@link IWebUser::getId}) @return boolean whether the item has been assigned to the user. @see IAuthManager::isAssigned
isAssigned
php
yiisoft/yii
framework/web/auth/CAuthItem.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAuthItem.php
BSD-3-Clause
public function getAssignment($userId) { return $this->_auth->getAuthAssignment($this->_name,$userId); }
Returns the item assignment information. @param mixed $userId the user ID (see {@link IWebUser::getId}) @return CAuthAssignment the item assignment information. Null is returned if this item is not assigned to the user. @see IAuthManager::getAuthAssignment
getAssignment
php
yiisoft/yii
framework/web/auth/CAuthItem.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAuthItem.php
BSD-3-Clause
public function renderFile($context,$sourceFile,$data,$return) { if(!is_file($sourceFile) || ($file=realpath($sourceFile))===false) throw new CException(Yii::t('yii','View file "{file}" does not exist.',array('{file}'=>$sourceFile))); $viewFile=$this->getViewFile($sourceFile); if(@filemtime($sourceFile)>@filemtime($viewFile)) { $this->generateViewFile($sourceFile,$viewFile); @chmod($viewFile,$this->filePermission); } return $context->renderInternal($viewFile,$data,$return); }
Renders a view file. This method is required by {@link IViewRenderer}. @param CBaseController $context the controller or widget who is rendering the view file. @param string $sourceFile the view file path @param mixed $data the data to be passed to the view @param boolean $return whether the rendering result should be returned @return mixed the rendering result, or null if the rendering result is not needed. @throws CException
renderFile
php
yiisoft/yii
framework/web/renderers/CViewRenderer.php
https://github.com/yiisoft/yii/blob/master/framework/web/renderers/CViewRenderer.php
BSD-3-Clause
protected function getViewFile($file) { if($this->useRuntimePath) { $crc=sprintf('%x', crc32(get_class($this).Yii::getVersion().dirname($file))); $viewFile=Yii::app()->getRuntimePath().DIRECTORY_SEPARATOR.'views'.DIRECTORY_SEPARATOR.$crc.DIRECTORY_SEPARATOR.basename($file); if(!is_file($viewFile)) @mkdir(dirname($viewFile),$this->filePermission,true); return $viewFile; } else return $file.'c'; }
Generates the resulting view file path. @param string $file source view file path @return string resulting view file path
getViewFile
php
yiisoft/yii
framework/web/renderers/CViewRenderer.php
https://github.com/yiisoft/yii/blob/master/framework/web/renderers/CViewRenderer.php
BSD-3-Clause
protected function setPermissions($targetDir) { @chmod($targetDir.'/assets',0777); @chmod($targetDir.'/protected/runtime',0777); @chmod($targetDir.'/protected/data',0777); @chmod($targetDir.'/protected/data/testdrive.db',0777); @chmod($targetDir.'/protected/yiic',0755); }
Adjusts created application file and directory permissions @param string $targetDir path to created application
setPermissions
php
yiisoft/yii
framework/cli/commands/WebAppCommand.php
https://github.com/yiisoft/yii/blob/master/framework/cli/commands/WebAppCommand.php
BSD-3-Clause
protected function addFileModificationCallbacks(&$fileList) { $fileList['index.php']['callback']=array($this,'generateIndex'); $fileList['index-test.php']['callback']=array($this,'generateIndex'); $fileList['protected/tests/bootstrap.php']['callback']=array($this,'generateTestBoostrap'); $fileList['protected/yiic.php']['callback']=array($this,'generateYiic'); }
Adds callbacks that will modify source files @param array $fileList
addFileModificationCallbacks
php
yiisoft/yii
framework/cli/commands/WebAppCommand.php
https://github.com/yiisoft/yii/blob/master/framework/cli/commands/WebAppCommand.php
BSD-3-Clause
public function generateIndex($source,$params) { $content=file_get_contents($source); $yii=realpath(dirname(__FILE__).'/../../yii.php'); $yii=$this->getRelativePath($yii,$this->_rootPath.DIRECTORY_SEPARATOR.'index.php'); $yii=str_replace('\\','\\\\',$yii); return preg_replace('/\$yii\s*=(.*?);/',"\$yii=$yii;",$content); }
Inserts path to framework's yii.php into application's index.php @param string $source source file path @param array $params @return string modified source file content
generateIndex
php
yiisoft/yii
framework/cli/commands/WebAppCommand.php
https://github.com/yiisoft/yii/blob/master/framework/cli/commands/WebAppCommand.php
BSD-3-Clause
public function generateTestBoostrap($source,$params) { $content=file_get_contents($source); $yii=realpath(dirname(__FILE__).'/../../yiit.php'); $yii=$this->getRelativePath($yii,$this->_rootPath.DIRECTORY_SEPARATOR.'protected'.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'bootstrap.php'); $yii=str_replace('\\','\\\\',$yii); return preg_replace('/\$yiit\s*=(.*?);/',"\$yiit=$yii;",$content); }
Inserts path to framework's yiit.php into application's index-test.php @param string $source source file path @param array $params @return string modified source file content
generateTestBoostrap
php
yiisoft/yii
framework/cli/commands/WebAppCommand.php
https://github.com/yiisoft/yii/blob/master/framework/cli/commands/WebAppCommand.php
BSD-3-Clause
public function generateYiic($source,$params) { $content=file_get_contents($source); $yiic=realpath(dirname(__FILE__).'/../../yiic.php'); $yiic=$this->getRelativePath($yiic,$this->_rootPath.DIRECTORY_SEPARATOR.'protected'.DIRECTORY_SEPARATOR.'yiic.php'); $yiic=str_replace('\\','\\\\',$yiic); return preg_replace('/\$yiic\s*=(.*?);/',"\$yiic=$yiic;",$content); }
Inserts path to framework's yiic.php into application's yiic.php @param string $source source file path @param array $params @return string modified source file content
generateYiic
php
yiisoft/yii
framework/cli/commands/WebAppCommand.php
https://github.com/yiisoft/yii/blob/master/framework/cli/commands/WebAppCommand.php
BSD-3-Clause
protected function getRelativePath($path1,$path2) { $segs1=explode(DIRECTORY_SEPARATOR,$path1); $segs2=explode(DIRECTORY_SEPARATOR,$path2); $n1=count($segs1); $n2=count($segs2); for($i=0;$i<$n1 && $i<$n2;++$i) { if($segs1[$i]!==$segs2[$i]) break; } if($i===0) return "'".$path1."'"; $up=''; for($j=$i;$j<$n2-1;++$j) $up.='/..'; for(;$i<$n1-1;++$i) $up.='/'.$segs1[$i]; return 'dirname(__FILE__).\''.$up.'/'.basename($path1).'\''; }
Returns variant of $path1 relative to $path2 @param string $path1 @param string $path2 @return string $path1 relative to $path2
getRelativePath
php
yiisoft/yii
framework/cli/commands/WebAppCommand.php
https://github.com/yiisoft/yii/blob/master/framework/cli/commands/WebAppCommand.php
BSD-3-Clause
protected function isRelationTable($table) { $pk=$table->primaryKey; return (count($pk) === 2 // we want 2 columns && isset($table->foreignKeys[$pk[0]]) // pk column 1 is also a foreign key && isset($table->foreignKeys[$pk[1]]) // pk column 2 is also a foreign key && $table->foreignKeys[$pk[0]][0] !== $table->foreignKeys[$pk[1]][0]); // and the foreign keys point different tables }
Checks if the given table is a "many to many" helper table. Their PK has 2 fields, and both of those fields are also FK to other separate tables. @param CDbTableSchema $table table to inspect @return boolean true if table matches description of helper table.
isRelationTable
php
yiisoft/yii
framework/cli/commands/shell/ModelCommand.php
https://github.com/yiisoft/yii/blob/master/framework/cli/commands/shell/ModelCommand.php
BSD-3-Clause
protected function generateClassName($tableName) { return str_replace(' ','', ucwords( trim( strtolower( str_replace(array('-','_'),' ', preg_replace('/(?<![A-Z])[A-Z]/', ' \0', $tableName)))))); }
Generates model class name based on a table name @param string $tableName the table name @return string the generated model class name
generateClassName
php
yiisoft/yii
framework/cli/commands/shell/ModelCommand.php
https://github.com/yiisoft/yii/blob/master/framework/cli/commands/shell/ModelCommand.php
BSD-3-Clause
public function getHelp() { return <<<EOD USAGE help [command-name] DESCRIPTION Display the help information for the specified command. If the command name is not given, all commands will be listed. PARAMETERS * command-name: optional, the name of the command to show help information. EOD; }
Provides the command description. @return string the command description.
getHelp
php
yiisoft/yii
framework/cli/commands/shell/HelpCommand.php
https://github.com/yiisoft/yii/blob/master/framework/cli/commands/shell/HelpCommand.php
BSD-3-Clause
public function actionIndex() { // renders the view file 'protected/views/site/index.php' // using the default layout 'protected/views/layouts/main.php' $this->render('index'); }
This is the default 'index' action that is invoked when an action is not explicitly requested by users.
actionIndex
php
yiisoft/yii
framework/cli/views/webapp/protected/controllers/SiteController.php
https://github.com/yiisoft/yii/blob/master/framework/cli/views/webapp/protected/controllers/SiteController.php
BSD-3-Clause
public function actionError() { if($error=Yii::app()->errorHandler->error) { if(Yii::app()->request->isAjaxRequest) echo $error['message']; else $this->render('error', $error); } }
This is the action to handle external exceptions.
actionError
php
yiisoft/yii
framework/cli/views/webapp/protected/controllers/SiteController.php
https://github.com/yiisoft/yii/blob/master/framework/cli/views/webapp/protected/controllers/SiteController.php
BSD-3-Clause
public function actionLogout() { Yii::app()->user->logout(); $this->redirect(Yii::app()->homeUrl); }
Logs out the current user and redirect to homepage.
actionLogout
php
yiisoft/yii
framework/cli/views/webapp/protected/controllers/SiteController.php
https://github.com/yiisoft/yii/blob/master/framework/cli/views/webapp/protected/controllers/SiteController.php
BSD-3-Clause
public function rules() { return array( // name, email, subject and body are required array('name, email, subject, body', 'required'), // email has to be a valid email address array('email', 'email'), // verifyCode needs to be entered correctly array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()), ); }
Declares the validation rules.
rules
php
yiisoft/yii
framework/cli/views/webapp/protected/models/ContactForm.php
https://github.com/yiisoft/yii/blob/master/framework/cli/views/webapp/protected/models/ContactForm.php
BSD-3-Clause
public function attributeLabels() { return array( 'verifyCode'=>'Verification Code', ); }
Declares customized attribute labels. If not declared here, an attribute would have a label that is the same as its name with the first letter in upper case.
attributeLabels
php
yiisoft/yii
framework/cli/views/webapp/protected/models/ContactForm.php
https://github.com/yiisoft/yii/blob/master/framework/cli/views/webapp/protected/models/ContactForm.php
BSD-3-Clause
public function rules() { return array( // username and password are required array('username, password', 'required'), // rememberMe needs to be a boolean array('rememberMe', 'boolean'), // password needs to be authenticated array('password', 'authenticate'), ); }
Declares the validation rules. The rules state that username and password are required, and password needs to be authenticated.
rules
php
yiisoft/yii
framework/cli/views/webapp/protected/models/LoginForm.php
https://github.com/yiisoft/yii/blob/master/framework/cli/views/webapp/protected/models/LoginForm.php
BSD-3-Clause
public function authenticate($attribute,$params) { if(!$this->hasErrors()) { $this->_identity=new UserIdentity($this->username,$this->password); if(!$this->_identity->authenticate()) $this->addError('password','Incorrect username or password.'); } }
Authenticates the password. This is the 'authenticate' validator as declared in rules(). @param string $attribute the name of the attribute to be validated. @param array $params additional parameters passed with rule when being executed.
authenticate
php
yiisoft/yii
framework/cli/views/webapp/protected/models/LoginForm.php
https://github.com/yiisoft/yii/blob/master/framework/cli/views/webapp/protected/models/LoginForm.php
BSD-3-Clause
public function login() { if($this->_identity===null) { $this->_identity=new UserIdentity($this->username,$this->password); $this->_identity->authenticate(); } if($this->_identity->errorCode===UserIdentity::ERROR_NONE) { $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days Yii::app()->user->login($this->_identity,$duration); return true; } else return false; }
Logs in the user using the given username and password in the model. @return boolean whether login is successful
login
php
yiisoft/yii
framework/cli/views/webapp/protected/models/LoginForm.php
https://github.com/yiisoft/yii/blob/master/framework/cli/views/webapp/protected/models/LoginForm.php
BSD-3-Clause
public function authenticate() { $users=array( // username => password 'demo'=>'demo', 'admin'=>'admin', ); if(!isset($users[$this->username])) $this->errorCode=self::ERROR_USERNAME_INVALID; elseif($users[$this->username]!==$this->password) $this->errorCode=self::ERROR_PASSWORD_INVALID; else $this->errorCode=self::ERROR_NONE; return !$this->errorCode; }
Authenticates a user. The example implementation makes sure if the username and password are both 'demo'. In practical applications, this should be changed to authenticate against some persistent user identity storage (e.g. database). @return boolean whether authentication succeeds.
authenticate
php
yiisoft/yii
framework/cli/views/webapp/protected/components/UserIdentity.php
https://github.com/yiisoft/yii/blob/master/framework/cli/views/webapp/protected/components/UserIdentity.php
BSD-3-Clause
public function filter(&$logs) { if (!empty($logs)) { if(($message=$this->getContext())!=='') array_unshift($logs,array($message,CLogger::LEVEL_INFO,'application',YII_BEGIN_TIME)); $this->format($logs); } return $logs; }
Filters the given log messages. This is the main method of CLogFilter. It processes the log messages by adding context information, etc. @param array $logs the log messages @return array
filter
php
yiisoft/yii
framework/logging/CLogFilter.php
https://github.com/yiisoft/yii/blob/master/framework/logging/CLogFilter.php
BSD-3-Clause