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 getViewPath($checkTheme=false) { $className=get_class($this); $scope=$checkTheme?'theme':'local'; if(isset(self::$_viewPaths[$className][$scope])) return self::$_viewPaths[$className][$scope]; else { if($checkTheme && ($theme=Yii::app()->getTheme())!==null) { $path=$theme->getViewPath().DIRECTORY_SEPARATOR; if(strpos($className,'\\')!==false) // namespaced class $path.=str_replace('\\','_',ltrim($className,'\\')); else $path.=$className; if(is_dir($path)) return self::$_viewPaths[$className]['theme']=$path; } $class=new ReflectionClass($className); return self::$_viewPaths[$className]['local']=dirname($class->getFileName()).DIRECTORY_SEPARATOR.'views'; } }
Returns the directory containing the view files for this widget. The default implementation returns the 'views' subdirectory of the directory containing the widget class file. If $checkTheme is set true, the directory "ThemeID/views/ClassName" will be returned when it exists. @param boolean $checkTheme whether to check if the theme contains a view path for the widget. @return string the directory containing the view files for this widget.
getViewPath
php
yiisoft/yii
framework/web/widgets/CWidget.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/CWidget.php
BSD-3-Clause
public function processOutput($output) { $output=$this->highlight($output); parent::processOutput($output); }
Processes the captured output. This method highlights the output according to the syntax of the specified {@link language}. @param string $output the captured output to be processed
processOutput
php
yiisoft/yii
framework/web/widgets/CTextHighlighter.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/CTextHighlighter.php
BSD-3-Clause
public function highlight($content) { $this->registerClientScript(); $options['use_language']=true; $options['tabsize']=$this->tabSize; if($this->showLineNumbers) $options['numbers']=($this->lineNumberStyle==='list')?HL_NUMBERS_LI:HL_NUMBERS_TABLE; $highlighter=empty($this->language)?false:Text_Highlighter::factory($this->language); if($highlighter===false) $o='<pre>'.CHtml::encode($content).'</pre>'; else { $highlighter->setRenderer(new Text_Highlighter_Renderer_Html($options)); $o=preg_replace('/<span\s+[^>]*>(\s*)<\/span>/','\1',$highlighter->highlight($content)); } return CHtml::tag('div',$this->containerOptions,$o); }
Highlights the content by the syntax of the specified language. @param string $content the content to be highlighted. @return string the highlighted content
highlight
php
yiisoft/yii
framework/web/widgets/CTextHighlighter.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/CTextHighlighter.php
BSD-3-Clause
public function generateValidationHash($code) { for($h=0,$i=strlen($code)-1;$i>=0;--$i) $h+=ord($code[$i]); return $h; }
Generates a hash code that can be used for client side validation. @param string $code the CAPTCHA code @return string a hash code generated from the CAPTCHA code @since 1.1.7
generateValidationHash
php
yiisoft/yii
framework/web/widgets/captcha/CCaptchaAction.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/captcha/CCaptchaAction.php
BSD-3-Clause
public function validate($input,$caseSensitive) { $code = $this->getVerifyCode(); $valid = $caseSensitive ? ($input === $code) : strcasecmp($input,$code)===0; $session = Yii::app()->session; $session->open(); $name = $this->getSessionKey() . 'count'; $session[$name] = $session[$name] + 1; if($session[$name] > $this->testLimit && $this->testLimit > 0) $this->getVerifyCode(true); return $valid; }
Validates the input to see if it matches the generated code. @param string $input user input @param boolean $caseSensitive whether the comparison should be case-sensitive @return boolean whether the input is valid
validate
php
yiisoft/yii
framework/web/widgets/captcha/CCaptchaAction.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/captcha/CCaptchaAction.php
BSD-3-Clause
protected function generateVerifyCode() { if($this->minLength > $this->maxLength) $this->maxLength = $this->minLength; if($this->minLength < 3) $this->minLength = 3; if($this->maxLength > 20) $this->maxLength = 20; $length = mt_rand($this->minLength,$this->maxLength); $letters = 'bcdfghjklmnpqrstvwxyz'; $vowels = 'aeiou'; $code = ''; for($i = 0; $i < $length; ++$i) { if($i % 2 && mt_rand(0,10) > 2 || !($i % 2) && mt_rand(0,10) > 9) $code.=$vowels[mt_rand(0,4)]; else $code.=$letters[mt_rand(0,20)]; } return $code; }
Generates a new verification code. @return string the generated verification code
generateVerifyCode
php
yiisoft/yii
framework/web/widgets/captcha/CCaptchaAction.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/captcha/CCaptchaAction.php
BSD-3-Clause
protected function getSessionKey() { return self::SESSION_VAR_PREFIX . Yii::app()->getId() . '.' . $this->getController()->getUniqueId() . '.' . $this->getId(); }
Returns the session variable name used to store verification code. @return string the session variable name
getSessionKey
php
yiisoft/yii
framework/web/widgets/captcha/CCaptchaAction.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/captcha/CCaptchaAction.php
BSD-3-Clause
protected function renderImageGD($code) { $image = imagecreatetruecolor($this->width,$this->height); $backColor = imagecolorallocate($image, (int)($this->backColor % 0x1000000 / 0x10000), (int)($this->backColor % 0x10000 / 0x100), $this->backColor % 0x100); imagefilledrectangle($image,0,0,$this->width,$this->height,$backColor); imagecolordeallocate($image,$backColor); if($this->transparent) imagecolortransparent($image,$backColor); $foreColor = imagecolorallocate($image, (int)($this->foreColor % 0x1000000 / 0x10000), (int)($this->foreColor % 0x10000 / 0x100), $this->foreColor % 0x100); if($this->fontFile === null) $this->fontFile = dirname(__FILE__).DIRECTORY_SEPARATOR.'SpicyRice.ttf'; $length = strlen($code); $box = imagettfbbox(30,0,$this->fontFile,$code); $w = $box[4] - $box[0] + $this->offset * ($length - 1); $h = $box[1] - $box[5]; $scale = min(($this->width - $this->padding * 2) / $w,($this->height - $this->padding * 2) / $h); $x = 10; $y = round($this->height * 27 / 40); for($i = 0; $i < $length; ++$i) { $fontSize = (int)(rand(26,32) * $scale * 0.8); $angle = rand(-10,10); $letter = $code[$i]; $box = imagettftext($image,$fontSize,$angle,$x,$y,$foreColor,$this->fontFile,$letter); $x = $box[2] + $this->offset; } imagecolordeallocate($image,$foreColor); header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Transfer-Encoding: binary'); header("Content-Type: image/png"); imagepng($image); imagedestroy($image); }
Renders the CAPTCHA image based on the code using GD library. @param string $code the verification code @since 1.1.13
renderImageGD
php
yiisoft/yii
framework/web/widgets/captcha/CCaptchaAction.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/captcha/CCaptchaAction.php
BSD-3-Clause
protected function renderImageImagick($code) { $backColor=$this->transparent ? new ImagickPixel('transparent') : new ImagickPixel(sprintf('#%06x',$this->backColor)); $foreColor=new ImagickPixel(sprintf('#%06x',$this->foreColor)); $image=new Imagick(); $image->newImage($this->width,$this->height,$backColor); if($this->fontFile===null) $this->fontFile=dirname(__FILE__).DIRECTORY_SEPARATOR.'SpicyRice.ttf'; $draw=new ImagickDraw(); $draw->setFont($this->fontFile); $draw->setFontSize(30); $fontMetrics=$image->queryFontMetrics($draw,$code); $length=strlen($code); $w=(int)($fontMetrics['textWidth'])-8+$this->offset*($length-1); $h=(int)($fontMetrics['textHeight'])-8; $scale=min(($this->width-$this->padding*2)/$w,($this->height-$this->padding*2)/$h); $x=10; $y=round($this->height*27/40); for($i=0; $i<$length; ++$i) { $draw=new ImagickDraw(); $draw->setFont($this->fontFile); $draw->setFontSize((int)(rand(26,32)*$scale*0.8)); $draw->setFillColor($foreColor); $image->annotateImage($draw,$x,$y,rand(-10,10),$code[$i]); $fontMetrics=$image->queryFontMetrics($draw,$code[$i]); $x+=(int)($fontMetrics['textWidth'])+$this->offset; } header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Content-Transfer-Encoding: binary'); header("Content-Type: image/png"); $image->setImageFormat('png'); echo $image->getImageBlob(); }
Renders the CAPTCHA image based on the code using ImageMagick library. @param string $code the verification code @since 1.1.13
renderImageImagick
php
yiisoft/yii
framework/web/widgets/captcha/CCaptchaAction.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/captcha/CCaptchaAction.php
BSD-3-Clause
public function registerClientScript() { $cs=Yii::app()->clientScript; $id=$this->imageOptions['id']; $url=$this->getController()->createUrl($this->captchaAction,array(CCaptchaAction::REFRESH_GET_VAR=>true)); $js=""; if($this->showRefreshButton) { // reserve a place in the registered script so that any enclosing button js code appears after the captcha js $cs->registerScript('Yii.CCaptcha#'.$id,'// dummy'); $label=$this->buttonLabel===null?Yii::t('yii','Get a new code'):$this->buttonLabel; $options=$this->buttonOptions; if(isset($options['id'])) $buttonID=$options['id']; else $buttonID=$options['id']=$id.'_button'; if($this->buttonType==='button') $html=CHtml::button($label, $options); else $html=CHtml::link($label, $url, $options); $js="jQuery('#$id').after(".CJSON::encode($html).");"; $selector="#$buttonID"; } if($this->clickableImage) $selector=isset($selector) ? "$selector, #$id" : "#$id"; if(!isset($selector)) return; $js.=" jQuery(document).on('click', '$selector', function(){ jQuery.ajax({ url: ".CJSON::encode($url).", dataType: 'json', cache: false, success: function(data) { jQuery('#$id').attr('src', data['url']); jQuery('body').data('{$this->captchaAction}.hash', [data['hash1'], data['hash2']]); } }); return false; }); "; $cs->registerScript('Yii.CCaptcha#'.$id,$js); }
Registers the needed client scripts.
registerClientScript
php
yiisoft/yii
framework/web/widgets/captcha/CCaptcha.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/captcha/CCaptcha.php
BSD-3-Clause
public static function checkRequirements($extension=null) { if(extension_loaded('imagick')) { $imagickFormats=Imagick::queryFormats('PNG'); } if(extension_loaded('gd')) { $gdInfo=gd_info(); } if($extension===null) { if(isset($imagickFormats) && in_array('PNG',$imagickFormats)) return true; if(isset($gdInfo) && $gdInfo['FreeType Support']) return true; } elseif($extension=='imagick' && isset($imagickFormats) && in_array('PNG',$imagickFormats)) return true; elseif($extension=='gd' && isset($gdInfo) && $gdInfo['FreeType Support']) return true; return false; }
Checks if specified graphic extension support is loaded. @param string $extension name to be checked. Possible values are 'gd', 'imagick' and null. Default value is null meaning that both extensions will be checked. This parameter is available since 1.1.13. @return boolean true if ImageMagick extension with PNG support or GD with FreeType support is loaded, otherwise false @since 1.1.5
checkRequirements
php
yiisoft/yii
framework/web/widgets/captcha/CCaptcha.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/captcha/CCaptcha.php
BSD-3-Clause
public function init() { if($this->nextPageLabel===null) $this->nextPageLabel=Yii::t('yii','Next &gt;'); if($this->prevPageLabel===null) $this->prevPageLabel=Yii::t('yii','&lt; Previous'); if($this->firstPageLabel===null) $this->firstPageLabel=Yii::t('yii','&lt;&lt; First'); if($this->lastPageLabel===null) $this->lastPageLabel=Yii::t('yii','Last &gt;&gt;'); if($this->header===null) $this->header=Yii::t('yii','Go to page: '); if(!isset($this->htmlOptions['id'])) $this->htmlOptions['id']=$this->getId(); if(!isset($this->htmlOptions['class'])) $this->htmlOptions['class']='yiiPager'; }
Initializes the pager by setting some default property values.
init
php
yiisoft/yii
framework/web/widgets/pagers/CLinkPager.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/pagers/CLinkPager.php
BSD-3-Clause
public function run() { $this->registerClientScript(); $buttons=$this->createPageButtons(); if(empty($buttons)) return; echo $this->header; echo CHtml::tag('ul',$this->htmlOptions,implode("\n",$buttons)); echo $this->footer; }
Executes the widget. This overrides the parent implementation by displaying the generated page buttons.
run
php
yiisoft/yii
framework/web/widgets/pagers/CLinkPager.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/pagers/CLinkPager.php
BSD-3-Clause
public function registerClientScript() { if($this->cssFile!==false) self::registerCssFile($this->cssFile); }
Registers the needed client scripts (mainly CSS file).
registerClientScript
php
yiisoft/yii
framework/web/widgets/pagers/CLinkPager.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/pagers/CLinkPager.php
BSD-3-Clause
public function getPages() { if($this->_pages===null) $this->_pages=$this->createPages(); return $this->_pages; }
Returns the pagination information used by this pager. @return CPagination the pagination information
getPages
php
yiisoft/yii
framework/web/widgets/pagers/CBasePager.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/pagers/CBasePager.php
BSD-3-Clause
public function setPages($pages) { $this->_pages=$pages; }
Sets the pagination information used by this pager. @param CPagination $pages the pagination information
setPages
php
yiisoft/yii
framework/web/widgets/pagers/CBasePager.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/pagers/CBasePager.php
BSD-3-Clause
protected function createPages() { return new CPagination; }
Creates the default pagination. This is called by {@link getPages} when the pagination is not set before. @return CPagination the default pagination instance.
createPages
php
yiisoft/yii
framework/web/widgets/pagers/CBasePager.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/pagers/CBasePager.php
BSD-3-Clause
protected function createPageUrl($page) { return $this->getPages()->createPageUrl($this->getController(),$page); }
Creates the URL suitable for pagination. @param integer $page the page that the URL should point to. @return string the created URL @see CPagination::createPageUrl
createPageUrl
php
yiisoft/yii
framework/web/widgets/pagers/CBasePager.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/pagers/CBasePager.php
BSD-3-Clause
protected function generatePageText($page) { if($this->pageTextFormat!==null) return sprintf($this->pageTextFormat,$page+1); else return $page+1; }
Generates the list option for the specified page number. You may override this method to customize the option display. @param integer $page zero-based page number @return string the list option for the page number
generatePageText
php
yiisoft/yii
framework/web/widgets/pagers/CListPager.php
https://github.com/yiisoft/yii/blob/master/framework/web/widgets/pagers/CListPager.php
BSD-3-Clause
public function getService() { return $this->_service; }
Returns the Web service instance currently being used. @return CWebService the Web service instance
getService
php
yiisoft/yii
framework/web/services/CWebServiceAction.php
https://github.com/yiisoft/yii/blob/master/framework/web/services/CWebServiceAction.php
BSD-3-Clause
protected function createWebService($provider,$wsdlUrl,$serviceUrl) { return new CWebService($provider,$wsdlUrl,$serviceUrl); }
Creates a {@link CWebService} instance. You may override this method to customize the created instance. @param mixed $provider the web service provider class name or object @param string $wsdlUrl the URL for WSDL. @param string $serviceUrl the URL for the Web service. @return CWebService the Web service instance
createWebService
php
yiisoft/yii
framework/web/services/CWebServiceAction.php
https://github.com/yiisoft/yii/blob/master/framework/web/services/CWebServiceAction.php
BSD-3-Clause
protected function injectDom(DOMDocument $dom, DOMElement $target, DOMNode $source) { if ($source->nodeType!=XML_ELEMENT_NODE) return; $import=$dom->createElement($source->nodeName); foreach($source->attributes as $attr) $import->setAttribute($attr->name,$attr->value); foreach($source->childNodes as $child) $this->injectDom($dom,$import,$child); $target->appendChild($import); }
Import custom XML source node into WSDL document under specified target node @param DOMDocument $dom XML WSDL document being generated @param DOMElement $target XML node, to which will be appended $source node @param DOMNode $source Source XML node to be imported
injectDom
php
yiisoft/yii
framework/web/services/CWsdlGenerator.php
https://github.com/yiisoft/yii/blob/master/framework/web/services/CWsdlGenerator.php
BSD-3-Clause
public function generateWsdl() { $providerClass=is_object($this->provider) ? get_class($this->provider) : Yii::import($this->provider,true); if($this->wsdlCacheDuration>0 && $this->cacheID!==false && ($cache=Yii::app()->getComponent($this->cacheID))!==null) { $key='Yii.CWebService.'.$providerClass.$this->serviceUrl.$this->encoding; if(($wsdl=$cache->get($key))!==false) return $wsdl; } $generator=Yii::createComponent($this->generatorConfig); $wsdl=$generator->generateWsdl($providerClass,$this->serviceUrl,$this->encoding); if(isset($key)) $cache->set($key,$wsdl,$this->wsdlCacheDuration); return $wsdl; }
Generates the WSDL as defined by the provider. The cached version may be used if the WSDL is found valid in cache. @return string the generated WSDL @see wsdlCacheDuration
generateWsdl
php
yiisoft/yii
framework/web/services/CWebService.php
https://github.com/yiisoft/yii/blob/master/framework/web/services/CWebService.php
BSD-3-Clause
public function run() { header('Content-Type: text/xml;charset='.$this->encoding); if(YII_DEBUG) ini_set("soap.wsdl_cache_enabled",0); $server=new SoapServer($this->wsdlUrl,$this->getOptions()); Yii::app()->attachEventHandler('onError',array($this,'handleError')); try { if($this->persistence!==null) $server->setPersistence($this->persistence); if(is_string($this->provider)) $provider=Yii::createComponent($this->provider); else $provider=$this->provider; if(method_exists($server,'setObject')) { if (is_array($this->generatorConfig) && isset($this->generatorConfig['bindingStyle']) && $this->generatorConfig['bindingStyle']==='document') { $server->setObject(new CDocumentSoapObjectWrapper($provider)); } else { $server->setObject($provider); } } else { if (is_array($this->generatorConfig) && isset($this->generatorConfig['bindingStyle']) && $this->generatorConfig['bindingStyle']==='document') { $server->setClass('CDocumentSoapObjectWrapper',$provider); } else { $server->setClass('CSoapObjectWrapper',$provider); } } if($provider instanceof IWebServiceProvider) { if($provider->beforeWebMethod($this)) { $server->handle(); $provider->afterWebMethod($this); } } else $server->handle(); } catch(Exception $e) { if($e->getCode()!==self::SOAP_ERROR) // non-PHP error { // only log for non-PHP-error case because application's error handler already logs it // php <5.2 doesn't support string conversion auto-magically Yii::log($e->__toString(),CLogger::LEVEL_ERROR,'application'); } $message=$e->getMessage(); if(YII_DEBUG) $message.=' ('.$e->getFile().':'.$e->getLine().")\n".$e->getTraceAsString(); // We need to end application explicitly because of // https://bugs.php.net/bug.php?id=49513 Yii::app()->onEndRequest(new CEvent($this)); $server->fault(get_class($e),$message); exit(1); } }
Handles the web service request.
run
php
yiisoft/yii
framework/web/services/CWebService.php
https://github.com/yiisoft/yii/blob/master/framework/web/services/CWebService.php
BSD-3-Clause
public function __call($name,$arguments) { return call_user_func_array(array($this->object,$name),$arguments); }
PHP __call magic method. This method calls the service provider to execute the actual logic. @param string $name method name @param array $arguments method arguments @return mixed method return value
__call
php
yiisoft/yii
framework/web/services/CWebService.php
https://github.com/yiisoft/yii/blob/master/framework/web/services/CWebService.php
BSD-3-Clause
public function createRole($name,$description='',$bizRule=null,$data=null) { return $this->createAuthItem($name,CAuthItem::TYPE_ROLE,$description,$bizRule,$data); }
Creates a role. This is a shortcut method to {@link IAuthManager::createAuthItem}. @param string $name the item name @param string $description the item description. @param string $bizRule the business rule associated with this item @param mixed $data additional data to be passed when evaluating the business rule @return CAuthItem the authorization item
createRole
php
yiisoft/yii
framework/web/auth/CAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAuthManager.php
BSD-3-Clause
public function createTask($name,$description='',$bizRule=null,$data=null) { return $this->createAuthItem($name,CAuthItem::TYPE_TASK,$description,$bizRule,$data); }
Creates a task. This is a shortcut method to {@link IAuthManager::createAuthItem}. @param string $name the item name @param string $description the item description. @param string $bizRule the business rule associated with this item @param mixed $data additional data to be passed when evaluating the business rule @return CAuthItem the authorization item
createTask
php
yiisoft/yii
framework/web/auth/CAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAuthManager.php
BSD-3-Clause
public function createOperation($name,$description='',$bizRule=null,$data=null) { return $this->createAuthItem($name,CAuthItem::TYPE_OPERATION,$description,$bizRule,$data); }
Creates an operation. This is a shortcut method to {@link IAuthManager::createAuthItem}. @param string $name the item name @param string $description the item description. @param string $bizRule the business rule associated with this item @param mixed $data additional data to be passed when evaluating the business rule @return CAuthItem the authorization item
createOperation
php
yiisoft/yii
framework/web/auth/CAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAuthManager.php
BSD-3-Clause
public function getRoles($userId=null) { return $this->getAuthItems(CAuthItem::TYPE_ROLE,$userId); }
Returns roles. This is a shortcut method to {@link IAuthManager::getAuthItems}. @param mixed $userId the user ID. If not null, only the roles directly assigned to the user will be returned. Otherwise, all roles will be returned. @return array roles (name=>CAuthItem)
getRoles
php
yiisoft/yii
framework/web/auth/CAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAuthManager.php
BSD-3-Clause
public function getTasks($userId=null) { return $this->getAuthItems(CAuthItem::TYPE_TASK,$userId); }
Returns tasks. This is a shortcut method to {@link IAuthManager::getAuthItems}. @param mixed $userId the user ID. If not null, only the tasks directly assigned to the user will be returned. Otherwise, all tasks will be returned. @return array tasks (name=>CAuthItem)
getTasks
php
yiisoft/yii
framework/web/auth/CAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAuthManager.php
BSD-3-Clause
public function getOperations($userId=null) { return $this->getAuthItems(CAuthItem::TYPE_OPERATION,$userId); }
Returns operations. This is a shortcut method to {@link IAuthManager::getAuthItems}. @param mixed $userId the user ID. If not null, only the operations directly assigned to the user will be returned. Otherwise, all operations will be returned. @return array operations (name=>CAuthItem)
getOperations
php
yiisoft/yii
framework/web/auth/CAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAuthManager.php
BSD-3-Clause
public function executeBizRule($bizRule,$params,$data) { if($bizRule==='' || $bizRule===null) return true; if ($this->showErrors) return eval($bizRule)!=0; else { try { return @eval($bizRule)!=0; } catch (ParseError $e) { return false; } } }
Executes the specified business rule. @param string $bizRule the business rule to be executed. @param array $params parameters passed to {@link IAuthManager::checkAccess}. @param mixed $data additional data associated with the authorization item or assignment. @return boolean whether the business rule returns true. If the business rule is empty, it will still return true.
executeBizRule
php
yiisoft/yii
framework/web/auth/CAuthManager.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAuthManager.php
BSD-3-Clause
protected function resolveErrorMessage($rule) { if($rule->message!==null) return $rule->message; elseif($this->message!==null) return $this->message; else return Yii::t('yii','You are not authorized to perform this action.'); }
Resolves the error message to be displayed. This method will check {@link message} and {@link CAccessRule::message} to see what error message should be displayed. @param CAccessRule $rule the access rule @return string the error message @since 1.1.1
resolveErrorMessage
php
yiisoft/yii
framework/web/auth/CAccessControlFilter.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAccessControlFilter.php
BSD-3-Clause
protected function accessDenied($user,$message) { if($user->getIsGuest()) $user->loginRequired(); else throw new CHttpException(403,$message); }
Denies the access of the user. This method is invoked when access check fails. @param IWebUser $user the current user @param string $message the error message to be displayed @throws CHttpException
accessDenied
php
yiisoft/yii
framework/web/auth/CAccessControlFilter.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAccessControlFilter.php
BSD-3-Clause
public function isUserAllowed($user,$controller,$action,$ip,$verb) { if($this->isActionMatched($action) && $this->isUserMatched($user) && $this->isRoleMatched($user) && $this->isIpMatched($ip) && $this->isVerbMatched($verb) && $this->isControllerMatched($controller) && $this->isExpressionMatched($user)) return $this->allow ? 1 : -1; else return 0; }
Checks whether the Web user is allowed to perform the specified action. @param CWebUser $user the user object @param CController $controller the controller currently being executed @param CAction $action the action to be performed @param string $ip the request IP address @param string $verb the request verb (GET, POST, etc.) @return integer 1 if the user is allowed, -1 if the user is denied, 0 if the rule does not apply to the user
isUserAllowed
php
yiisoft/yii
framework/web/auth/CAccessControlFilter.php
https://github.com/yiisoft/yii/blob/master/framework/web/auth/CAccessControlFilter.php
BSD-3-Clause
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 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 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 __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