repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
yiisoft/yii
|
framework/gii/CCodeGenerator.php
|
CCodeGenerator.actionDiff
|
public function actionDiff()
{
Yii::import('gii.components.TextDiff');
$model=$this->prepare();
if(isset($_GET['id']) && isset($model->files[$_GET['id']]))
{
$file=$model->files[$_GET['id']];
if(!in_array($file->type,array('php', 'txt','js','css','sql')))
$diff=false;
elseif($file->operation===CCodeFile::OP_OVERWRITE)
$diff=TextDiff::compare(file_get_contents($file->path), $file->content);
else
$diff='';
$this->renderPartial('/common/diff',array(
'file'=>$file,
'diff'=>$diff,
));
}
else
throw new CHttpException(404,'Unable to find the code you requested.');
}
|
php
|
public function actionDiff()
{
Yii::import('gii.components.TextDiff');
$model=$this->prepare();
if(isset($_GET['id']) && isset($model->files[$_GET['id']]))
{
$file=$model->files[$_GET['id']];
if(!in_array($file->type,array('php', 'txt','js','css','sql')))
$diff=false;
elseif($file->operation===CCodeFile::OP_OVERWRITE)
$diff=TextDiff::compare(file_get_contents($file->path), $file->content);
else
$diff='';
$this->renderPartial('/common/diff',array(
'file'=>$file,
'diff'=>$diff,
));
}
else
throw new CHttpException(404,'Unable to find the code you requested.');
}
|
[
"public",
"function",
"actionDiff",
"(",
")",
"{",
"Yii",
"::",
"import",
"(",
"'gii.components.TextDiff'",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'id'",
"]",
")",
"&&",
"isset",
"(",
"$",
"model",
"->",
"files",
"[",
"$",
"_GET",
"[",
"'id'",
"]",
"]",
")",
")",
"{",
"$",
"file",
"=",
"$",
"model",
"->",
"files",
"[",
"$",
"_GET",
"[",
"'id'",
"]",
"]",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"file",
"->",
"type",
",",
"array",
"(",
"'php'",
",",
"'txt'",
",",
"'js'",
",",
"'css'",
",",
"'sql'",
")",
")",
")",
"$",
"diff",
"=",
"false",
";",
"elseif",
"(",
"$",
"file",
"->",
"operation",
"===",
"CCodeFile",
"::",
"OP_OVERWRITE",
")",
"$",
"diff",
"=",
"TextDiff",
"::",
"compare",
"(",
"file_get_contents",
"(",
"$",
"file",
"->",
"path",
")",
",",
"$",
"file",
"->",
"content",
")",
";",
"else",
"$",
"diff",
"=",
"''",
";",
"$",
"this",
"->",
"renderPartial",
"(",
"'/common/diff'",
",",
"array",
"(",
"'file'",
"=>",
"$",
"file",
",",
"'diff'",
"=>",
"$",
"diff",
",",
")",
")",
";",
"}",
"else",
"throw",
"new",
"CHttpException",
"(",
"404",
",",
"'Unable to find the code you requested.'",
")",
";",
"}"
] |
The code diff action.
This action shows up the difference between the newly generated code and the corresponding existing code.
@throws CHttpException if unable to find code generated.
|
[
"The",
"code",
"diff",
"action",
".",
"This",
"action",
"shows",
"up",
"the",
"difference",
"between",
"the",
"newly",
"generated",
"code",
"and",
"the",
"corresponding",
"existing",
"code",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/gii/CCodeGenerator.php#L98-L120
|
train
|
yiisoft/yii
|
framework/gii/CCodeGenerator.php
|
CCodeGenerator.getViewPath
|
public function getViewPath()
{
if($this->_viewPath===null)
{
$class=new ReflectionClass(get_class($this));
$this->_viewPath=dirname($class->getFileName()).DIRECTORY_SEPARATOR.'views';
}
return $this->_viewPath;
}
|
php
|
public function getViewPath()
{
if($this->_viewPath===null)
{
$class=new ReflectionClass(get_class($this));
$this->_viewPath=dirname($class->getFileName()).DIRECTORY_SEPARATOR.'views';
}
return $this->_viewPath;
}
|
[
"public",
"function",
"getViewPath",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_viewPath",
"===",
"null",
")",
"{",
"$",
"class",
"=",
"new",
"ReflectionClass",
"(",
"get_class",
"(",
"$",
"this",
")",
")",
";",
"$",
"this",
"->",
"_viewPath",
"=",
"dirname",
"(",
"$",
"class",
"->",
"getFileName",
"(",
")",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'views'",
";",
"}",
"return",
"$",
"this",
"->",
"_viewPath",
";",
"}"
] |
Returns the view path of the generator.
The "views" directory under the directory containing the generator class file will be returned.
@return string the view path of the generator
|
[
"Returns",
"the",
"view",
"path",
"of",
"the",
"generator",
".",
"The",
"views",
"directory",
"under",
"the",
"directory",
"containing",
"the",
"generator",
"class",
"file",
"will",
"be",
"returned",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/gii/CCodeGenerator.php#L127-L135
|
train
|
yiisoft/yii
|
framework/gii/CCodeGenerator.php
|
CCodeGenerator.prepare
|
protected function prepare()
{
if($this->codeModel===null)
throw new CException(get_class($this).'.codeModel property must be specified.');
$modelClass=Yii::import($this->codeModel,true);
$model=new $modelClass;
$model->loadStickyAttributes();
if(isset($_POST[$modelClass]))
{
$model->attributes=$_POST[$modelClass];
$model->status=CCodeModel::STATUS_PREVIEW;
if($model->validate())
{
$model->saveStickyAttributes();
$model->prepare();
}
}
return $model;
}
|
php
|
protected function prepare()
{
if($this->codeModel===null)
throw new CException(get_class($this).'.codeModel property must be specified.');
$modelClass=Yii::import($this->codeModel,true);
$model=new $modelClass;
$model->loadStickyAttributes();
if(isset($_POST[$modelClass]))
{
$model->attributes=$_POST[$modelClass];
$model->status=CCodeModel::STATUS_PREVIEW;
if($model->validate())
{
$model->saveStickyAttributes();
$model->prepare();
}
}
return $model;
}
|
[
"protected",
"function",
"prepare",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"codeModel",
"===",
"null",
")",
"throw",
"new",
"CException",
"(",
"get_class",
"(",
"$",
"this",
")",
".",
"'.codeModel property must be specified.'",
")",
";",
"$",
"modelClass",
"=",
"Yii",
"::",
"import",
"(",
"$",
"this",
"->",
"codeModel",
",",
"true",
")",
";",
"$",
"model",
"=",
"new",
"$",
"modelClass",
";",
"$",
"model",
"->",
"loadStickyAttributes",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"$",
"modelClass",
"]",
")",
")",
"{",
"$",
"model",
"->",
"attributes",
"=",
"$",
"_POST",
"[",
"$",
"modelClass",
"]",
";",
"$",
"model",
"->",
"status",
"=",
"CCodeModel",
"::",
"STATUS_PREVIEW",
";",
"if",
"(",
"$",
"model",
"->",
"validate",
"(",
")",
")",
"{",
"$",
"model",
"->",
"saveStickyAttributes",
"(",
")",
";",
"$",
"model",
"->",
"prepare",
"(",
")",
";",
"}",
"}",
"return",
"$",
"model",
";",
"}"
] |
Prepares the code model.
|
[
"Prepares",
"the",
"code",
"model",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/gii/CCodeGenerator.php#L148-L166
|
train
|
yiisoft/yii
|
framework/i18n/CChoiceFormat.php
|
CChoiceFormat.format
|
public static function format($messages, $number)
{
$n=preg_match_all('/\s*([^#]*)\s*#([^\|]*)\|/',$messages.'|',$matches);
if($n===0)
return $messages;
for($i=0;$i<$n;++$i)
{
$expression=$matches[1][$i];
$message=$matches[2][$i];
if($expression===(string)(int)$expression)
{
if($expression==$number)
return $message;
}
elseif(self::evaluate(str_replace('n','$n',$expression),$number))
return $message;
}
return $message; // return the last choice
}
|
php
|
public static function format($messages, $number)
{
$n=preg_match_all('/\s*([^#]*)\s*#([^\|]*)\|/',$messages.'|',$matches);
if($n===0)
return $messages;
for($i=0;$i<$n;++$i)
{
$expression=$matches[1][$i];
$message=$matches[2][$i];
if($expression===(string)(int)$expression)
{
if($expression==$number)
return $message;
}
elseif(self::evaluate(str_replace('n','$n',$expression),$number))
return $message;
}
return $message; // return the last choice
}
|
[
"public",
"static",
"function",
"format",
"(",
"$",
"messages",
",",
"$",
"number",
")",
"{",
"$",
"n",
"=",
"preg_match_all",
"(",
"'/\\s*([^#]*)\\s*#([^\\|]*)\\|/'",
",",
"$",
"messages",
".",
"'|'",
",",
"$",
"matches",
")",
";",
"if",
"(",
"$",
"n",
"===",
"0",
")",
"return",
"$",
"messages",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"n",
";",
"++",
"$",
"i",
")",
"{",
"$",
"expression",
"=",
"$",
"matches",
"[",
"1",
"]",
"[",
"$",
"i",
"]",
";",
"$",
"message",
"=",
"$",
"matches",
"[",
"2",
"]",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"$",
"expression",
"===",
"(",
"string",
")",
"(",
"int",
")",
"$",
"expression",
")",
"{",
"if",
"(",
"$",
"expression",
"==",
"$",
"number",
")",
"return",
"$",
"message",
";",
"}",
"elseif",
"(",
"self",
"::",
"evaluate",
"(",
"str_replace",
"(",
"'n'",
",",
"'$n'",
",",
"$",
"expression",
")",
",",
"$",
"number",
")",
")",
"return",
"$",
"message",
";",
"}",
"return",
"$",
"message",
";",
"// return the last choice",
"}"
] |
Formats a message according to the specified number value.
@param string $messages the candidate messages in the format of 'expr1#message1|expr2#message2|expr3#message3'.
See {@link CChoiceFormat} for more details.
@param mixed $number the number value
@return string the selected message
|
[
"Formats",
"a",
"message",
"according",
"to",
"the",
"specified",
"number",
"value",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CChoiceFormat.php#L46-L64
|
train
|
yiisoft/yii
|
demos/blog/protected/controllers/PostController.php
|
PostController.actionSuggestTags
|
public function actionSuggestTags()
{
if(isset($_GET['q']) && ($keyword=trim($_GET['q']))!=='')
{
$tags=Tag::model()->suggestTags($keyword);
if($tags!==array())
echo implode("\n",$tags);
}
}
|
php
|
public function actionSuggestTags()
{
if(isset($_GET['q']) && ($keyword=trim($_GET['q']))!=='')
{
$tags=Tag::model()->suggestTags($keyword);
if($tags!==array())
echo implode("\n",$tags);
}
}
|
[
"public",
"function",
"actionSuggestTags",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"'q'",
"]",
")",
"&&",
"(",
"$",
"keyword",
"=",
"trim",
"(",
"$",
"_GET",
"[",
"'q'",
"]",
")",
")",
"!==",
"''",
")",
"{",
"$",
"tags",
"=",
"Tag",
"::",
"model",
"(",
")",
"->",
"suggestTags",
"(",
"$",
"keyword",
")",
";",
"if",
"(",
"$",
"tags",
"!==",
"array",
"(",
")",
")",
"echo",
"implode",
"(",
"\"\\n\"",
",",
"$",
"tags",
")",
";",
"}",
"}"
] |
Suggests tags based on the current user input.
This is called via AJAX when the user is entering the tags input.
|
[
"Suggests",
"tags",
"based",
"on",
"the",
"current",
"user",
"input",
".",
"This",
"is",
"called",
"via",
"AJAX",
"when",
"the",
"user",
"is",
"entering",
"the",
"tags",
"input",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/demos/blog/protected/controllers/PostController.php#L156-L164
|
train
|
yiisoft/yii
|
demos/blog/protected/controllers/PostController.php
|
PostController.newComment
|
protected function newComment($post)
{
$comment=new Comment;
if(isset($_POST['ajax']) && $_POST['ajax']==='comment-form')
{
echo CActiveForm::validate($comment);
Yii::app()->end();
}
if(isset($_POST['Comment']))
{
$comment->attributes=$_POST['Comment'];
if($post->addComment($comment))
{
if($comment->status==Comment::STATUS_PENDING)
Yii::app()->user->setFlash('commentSubmitted','Thank you for your comment. Your comment will be posted once it is approved.');
$this->refresh();
}
}
return $comment;
}
|
php
|
protected function newComment($post)
{
$comment=new Comment;
if(isset($_POST['ajax']) && $_POST['ajax']==='comment-form')
{
echo CActiveForm::validate($comment);
Yii::app()->end();
}
if(isset($_POST['Comment']))
{
$comment->attributes=$_POST['Comment'];
if($post->addComment($comment))
{
if($comment->status==Comment::STATUS_PENDING)
Yii::app()->user->setFlash('commentSubmitted','Thank you for your comment. Your comment will be posted once it is approved.');
$this->refresh();
}
}
return $comment;
}
|
[
"protected",
"function",
"newComment",
"(",
"$",
"post",
")",
"{",
"$",
"comment",
"=",
"new",
"Comment",
";",
"if",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"'ajax'",
"]",
")",
"&&",
"$",
"_POST",
"[",
"'ajax'",
"]",
"===",
"'comment-form'",
")",
"{",
"echo",
"CActiveForm",
"::",
"validate",
"(",
"$",
"comment",
")",
";",
"Yii",
"::",
"app",
"(",
")",
"->",
"end",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"'Comment'",
"]",
")",
")",
"{",
"$",
"comment",
"->",
"attributes",
"=",
"$",
"_POST",
"[",
"'Comment'",
"]",
";",
"if",
"(",
"$",
"post",
"->",
"addComment",
"(",
"$",
"comment",
")",
")",
"{",
"if",
"(",
"$",
"comment",
"->",
"status",
"==",
"Comment",
"::",
"STATUS_PENDING",
")",
"Yii",
"::",
"app",
"(",
")",
"->",
"user",
"->",
"setFlash",
"(",
"'commentSubmitted'",
",",
"'Thank you for your comment. Your comment will be posted once it is approved.'",
")",
";",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"}",
"}",
"return",
"$",
"comment",
";",
"}"
] |
Creates a new comment.
This method attempts to create a new comment based on the user input.
If the comment is successfully created, the browser will be redirected
to show the created comment.
@param Post the post that the new comment belongs to
@return Comment the comment instance
|
[
"Creates",
"a",
"new",
"comment",
".",
"This",
"method",
"attempts",
"to",
"create",
"a",
"new",
"comment",
"based",
"on",
"the",
"user",
"input",
".",
"If",
"the",
"comment",
"is",
"successfully",
"created",
"the",
"browser",
"will",
"be",
"redirected",
"to",
"show",
"the",
"created",
"comment",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/demos/blog/protected/controllers/PostController.php#L196-L215
|
train
|
yiisoft/yii
|
framework/base/CSecurityManager.php
|
CSecurityManager.encrypt
|
public function encrypt($data,$key=null)
{
if($key===null)
$key=$this->getEncryptionKey();
$this->validateEncryptionKey($key);
$module=$this->openCryptModule();
srand();
$iv=@mcrypt_create_iv(mcrypt_enc_get_iv_size($module), MCRYPT_RAND);
@mcrypt_generic_init($module,$key,$iv);
$encrypted=$iv.@mcrypt_generic($module,$data);
@mcrypt_generic_deinit($module);
@mcrypt_module_close($module);
return $encrypted;
}
|
php
|
public function encrypt($data,$key=null)
{
if($key===null)
$key=$this->getEncryptionKey();
$this->validateEncryptionKey($key);
$module=$this->openCryptModule();
srand();
$iv=@mcrypt_create_iv(mcrypt_enc_get_iv_size($module), MCRYPT_RAND);
@mcrypt_generic_init($module,$key,$iv);
$encrypted=$iv.@mcrypt_generic($module,$data);
@mcrypt_generic_deinit($module);
@mcrypt_module_close($module);
return $encrypted;
}
|
[
"public",
"function",
"encrypt",
"(",
"$",
"data",
",",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"null",
")",
"$",
"key",
"=",
"$",
"this",
"->",
"getEncryptionKey",
"(",
")",
";",
"$",
"this",
"->",
"validateEncryptionKey",
"(",
"$",
"key",
")",
";",
"$",
"module",
"=",
"$",
"this",
"->",
"openCryptModule",
"(",
")",
";",
"srand",
"(",
")",
";",
"$",
"iv",
"=",
"@",
"mcrypt_create_iv",
"(",
"mcrypt_enc_get_iv_size",
"(",
"$",
"module",
")",
",",
"MCRYPT_RAND",
")",
";",
"@",
"mcrypt_generic_init",
"(",
"$",
"module",
",",
"$",
"key",
",",
"$",
"iv",
")",
";",
"$",
"encrypted",
"=",
"$",
"iv",
".",
"@",
"mcrypt_generic",
"(",
"$",
"module",
",",
"$",
"data",
")",
";",
"@",
"mcrypt_generic_deinit",
"(",
"$",
"module",
")",
";",
"@",
"mcrypt_module_close",
"(",
"$",
"module",
")",
";",
"return",
"$",
"encrypted",
";",
"}"
] |
Encrypts data.
@param string $data data to be encrypted.
@param string $key the decryption key. This defaults to null, meaning using {@link getEncryptionKey EncryptionKey}.
@return string the encrypted data
@throws CException if PHP Mcrypt extension is not loaded or key is invalid
|
[
"Encrypts",
"data",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/base/CSecurityManager.php#L218-L231
|
train
|
yiisoft/yii
|
framework/base/CSecurityManager.php
|
CSecurityManager.validateData
|
public function validateData($data,$key=null)
{
if (!is_string($data))
return false;
$len=$this->strlen($this->computeHMAC('test'));
if($this->strlen($data)>=$len)
{
$hmac=$this->substr($data,0,$len);
$data2=$this->substr($data,$len,$this->strlen($data));
return $this->compareString($hmac,$this->computeHMAC($data2,$key))?$data2:false;
}
else
return false;
}
|
php
|
public function validateData($data,$key=null)
{
if (!is_string($data))
return false;
$len=$this->strlen($this->computeHMAC('test'));
if($this->strlen($data)>=$len)
{
$hmac=$this->substr($data,0,$len);
$data2=$this->substr($data,$len,$this->strlen($data));
return $this->compareString($hmac,$this->computeHMAC($data2,$key))?$data2:false;
}
else
return false;
}
|
[
"public",
"function",
"validateData",
"(",
"$",
"data",
",",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"data",
")",
")",
"return",
"false",
";",
"$",
"len",
"=",
"$",
"this",
"->",
"strlen",
"(",
"$",
"this",
"->",
"computeHMAC",
"(",
"'test'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"strlen",
"(",
"$",
"data",
")",
">=",
"$",
"len",
")",
"{",
"$",
"hmac",
"=",
"$",
"this",
"->",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"$",
"len",
")",
";",
"$",
"data2",
"=",
"$",
"this",
"->",
"substr",
"(",
"$",
"data",
",",
"$",
"len",
",",
"$",
"this",
"->",
"strlen",
"(",
"$",
"data",
")",
")",
";",
"return",
"$",
"this",
"->",
"compareString",
"(",
"$",
"hmac",
",",
"$",
"this",
"->",
"computeHMAC",
"(",
"$",
"data2",
",",
"$",
"key",
")",
")",
"?",
"$",
"data2",
":",
"false",
";",
"}",
"else",
"return",
"false",
";",
"}"
] |
Validates if data is tampered.
@param string $data data to be validated. The data must be previously
generated using {@link hashData()}.
@param string $key the private key to be used for generating HMAC. Defaults to null, meaning using {@link validationKey}.
@return string the real data with HMAC stripped off. False if the data
is tampered.
|
[
"Validates",
"if",
"data",
"is",
"tampered",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/base/CSecurityManager.php#L298-L312
|
train
|
yiisoft/yii
|
framework/base/CSecurityManager.php
|
CSecurityManager.generateRandomBytes
|
public function generateRandomBytes($length,$cryptographicallyStrong=true)
{
$bytes='';
if(function_exists('openssl_random_pseudo_bytes'))
{
$bytes=openssl_random_pseudo_bytes($length,$strong);
if($this->strlen($bytes)>=$length && ($strong || !$cryptographicallyStrong))
return $this->substr($bytes,0,$length);
}
if(function_exists('mcrypt_create_iv') &&
($bytes=@mcrypt_create_iv($length, MCRYPT_DEV_URANDOM))!==false &&
$this->strlen($bytes)>=$length)
{
return $this->substr($bytes,0,$length);
}
if(($file=@fopen('/dev/urandom','rb'))!==false &&
($bytes=@fread($file,$length))!==false &&
(fclose($file) || true) &&
$this->strlen($bytes)>=$length)
{
return $this->substr($bytes,0,$length);
}
$i=0;
while($this->strlen($bytes)<$length &&
($byte=$this->generateSessionRandomBlock())!==false &&
++$i<3)
{
$bytes.=$byte;
}
if($this->strlen($bytes)>=$length)
return $this->substr($bytes,0,$length);
if ($cryptographicallyStrong)
return false;
while($this->strlen($bytes)<$length)
$bytes.=$this->generatePseudoRandomBlock();
return $this->substr($bytes,0,$length);
}
|
php
|
public function generateRandomBytes($length,$cryptographicallyStrong=true)
{
$bytes='';
if(function_exists('openssl_random_pseudo_bytes'))
{
$bytes=openssl_random_pseudo_bytes($length,$strong);
if($this->strlen($bytes)>=$length && ($strong || !$cryptographicallyStrong))
return $this->substr($bytes,0,$length);
}
if(function_exists('mcrypt_create_iv') &&
($bytes=@mcrypt_create_iv($length, MCRYPT_DEV_URANDOM))!==false &&
$this->strlen($bytes)>=$length)
{
return $this->substr($bytes,0,$length);
}
if(($file=@fopen('/dev/urandom','rb'))!==false &&
($bytes=@fread($file,$length))!==false &&
(fclose($file) || true) &&
$this->strlen($bytes)>=$length)
{
return $this->substr($bytes,0,$length);
}
$i=0;
while($this->strlen($bytes)<$length &&
($byte=$this->generateSessionRandomBlock())!==false &&
++$i<3)
{
$bytes.=$byte;
}
if($this->strlen($bytes)>=$length)
return $this->substr($bytes,0,$length);
if ($cryptographicallyStrong)
return false;
while($this->strlen($bytes)<$length)
$bytes.=$this->generatePseudoRandomBlock();
return $this->substr($bytes,0,$length);
}
|
[
"public",
"function",
"generateRandomBytes",
"(",
"$",
"length",
",",
"$",
"cryptographicallyStrong",
"=",
"true",
")",
"{",
"$",
"bytes",
"=",
"''",
";",
"if",
"(",
"function_exists",
"(",
"'openssl_random_pseudo_bytes'",
")",
")",
"{",
"$",
"bytes",
"=",
"openssl_random_pseudo_bytes",
"(",
"$",
"length",
",",
"$",
"strong",
")",
";",
"if",
"(",
"$",
"this",
"->",
"strlen",
"(",
"$",
"bytes",
")",
">=",
"$",
"length",
"&&",
"(",
"$",
"strong",
"||",
"!",
"$",
"cryptographicallyStrong",
")",
")",
"return",
"$",
"this",
"->",
"substr",
"(",
"$",
"bytes",
",",
"0",
",",
"$",
"length",
")",
";",
"}",
"if",
"(",
"function_exists",
"(",
"'mcrypt_create_iv'",
")",
"&&",
"(",
"$",
"bytes",
"=",
"@",
"mcrypt_create_iv",
"(",
"$",
"length",
",",
"MCRYPT_DEV_URANDOM",
")",
")",
"!==",
"false",
"&&",
"$",
"this",
"->",
"strlen",
"(",
"$",
"bytes",
")",
">=",
"$",
"length",
")",
"{",
"return",
"$",
"this",
"->",
"substr",
"(",
"$",
"bytes",
",",
"0",
",",
"$",
"length",
")",
";",
"}",
"if",
"(",
"(",
"$",
"file",
"=",
"@",
"fopen",
"(",
"'/dev/urandom'",
",",
"'rb'",
")",
")",
"!==",
"false",
"&&",
"(",
"$",
"bytes",
"=",
"@",
"fread",
"(",
"$",
"file",
",",
"$",
"length",
")",
")",
"!==",
"false",
"&&",
"(",
"fclose",
"(",
"$",
"file",
")",
"||",
"true",
")",
"&&",
"$",
"this",
"->",
"strlen",
"(",
"$",
"bytes",
")",
">=",
"$",
"length",
")",
"{",
"return",
"$",
"this",
"->",
"substr",
"(",
"$",
"bytes",
",",
"0",
",",
"$",
"length",
")",
";",
"}",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"$",
"this",
"->",
"strlen",
"(",
"$",
"bytes",
")",
"<",
"$",
"length",
"&&",
"(",
"$",
"byte",
"=",
"$",
"this",
"->",
"generateSessionRandomBlock",
"(",
")",
")",
"!==",
"false",
"&&",
"++",
"$",
"i",
"<",
"3",
")",
"{",
"$",
"bytes",
".=",
"$",
"byte",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"strlen",
"(",
"$",
"bytes",
")",
">=",
"$",
"length",
")",
"return",
"$",
"this",
"->",
"substr",
"(",
"$",
"bytes",
",",
"0",
",",
"$",
"length",
")",
";",
"if",
"(",
"$",
"cryptographicallyStrong",
")",
"return",
"false",
";",
"while",
"(",
"$",
"this",
"->",
"strlen",
"(",
"$",
"bytes",
")",
"<",
"$",
"length",
")",
"$",
"bytes",
".=",
"$",
"this",
"->",
"generatePseudoRandomBlock",
"(",
")",
";",
"return",
"$",
"this",
"->",
"substr",
"(",
"$",
"bytes",
",",
"0",
",",
"$",
"length",
")",
";",
"}"
] |
Generates a string of random bytes.
@param integer $length number of random bytes to be generated.
@param boolean $cryptographicallyStrong whether to fail if a cryptographically strong
result cannot be generated. The method attempts to read from a cryptographically strong
pseudorandom number generator (CS-PRNG), see
{@link https://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator#Requirements Wikipedia}.
However, in some runtime environments, PHP has no access to a CS-PRNG, in which case
the method returns false if $cryptographicallyStrong is true. When $cryptographicallyStrong is false,
the method always returns a pseudorandom result but may fall back to using {@link generatePseudoRandomBlock}.
This method does not guarantee that entropy, from sources external to the CS-PRNG, was mixed into
the CS-PRNG state between each successive call. The caller can therefore expect non-blocking
behavior, unlike, for example, reading from /dev/random on Linux, see
{@link http://eprint.iacr.org/2006/086.pdf Gutterman et al 2006}.
@return boolean|string generated random binary string or false on failure.
@since 1.1.14
|
[
"Generates",
"a",
"string",
"of",
"random",
"bytes",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/base/CSecurityManager.php#L391-L432
|
train
|
yiisoft/yii
|
framework/base/CSecurityManager.php
|
CSecurityManager.generateSessionRandomBlock
|
public function generateSessionRandomBlock()
{
ini_set('session.entropy_length',20);
if(ini_get('session.entropy_length')!=20)
return false;
// These calls are (supposed to be, according to PHP manual) safe even if
// there is already an active session for the calling script.
@session_start();
@session_regenerate_id();
$bytes=session_id();
if(!$bytes)
return false;
// $bytes has 20 bytes of entropy but the session manager converts the binary
// random bytes into something readable. We have to convert that back.
// SHA-1 should do it without losing entropy.
return sha1($bytes,true);
}
|
php
|
public function generateSessionRandomBlock()
{
ini_set('session.entropy_length',20);
if(ini_get('session.entropy_length')!=20)
return false;
// These calls are (supposed to be, according to PHP manual) safe even if
// there is already an active session for the calling script.
@session_start();
@session_regenerate_id();
$bytes=session_id();
if(!$bytes)
return false;
// $bytes has 20 bytes of entropy but the session manager converts the binary
// random bytes into something readable. We have to convert that back.
// SHA-1 should do it without losing entropy.
return sha1($bytes,true);
}
|
[
"public",
"function",
"generateSessionRandomBlock",
"(",
")",
"{",
"ini_set",
"(",
"'session.entropy_length'",
",",
"20",
")",
";",
"if",
"(",
"ini_get",
"(",
"'session.entropy_length'",
")",
"!=",
"20",
")",
"return",
"false",
";",
"// These calls are (supposed to be, according to PHP manual) safe even if",
"// there is already an active session for the calling script.",
"@",
"session_start",
"(",
")",
";",
"@",
"session_regenerate_id",
"(",
")",
";",
"$",
"bytes",
"=",
"session_id",
"(",
")",
";",
"if",
"(",
"!",
"$",
"bytes",
")",
"return",
"false",
";",
"// $bytes has 20 bytes of entropy but the session manager converts the binary",
"// random bytes into something readable. We have to convert that back.",
"// SHA-1 should do it without losing entropy.",
"return",
"sha1",
"(",
"$",
"bytes",
",",
"true",
")",
";",
"}"
] |
Get random bytes from the system entropy source via PHP session manager.
@return boolean|string 20-byte random binary string or false on error.
@since 1.1.14
|
[
"Get",
"random",
"bytes",
"from",
"the",
"system",
"entropy",
"source",
"via",
"PHP",
"session",
"manager",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/base/CSecurityManager.php#L477-L496
|
train
|
yiisoft/yii
|
framework/base/CSecurityManager.php
|
CSecurityManager.substr
|
private function substr($string,$start,$length)
{
return $this->_mbstring ? mb_substr($string,$start,$length,'8bit') : substr($string,$start,$length);
}
|
php
|
private function substr($string,$start,$length)
{
return $this->_mbstring ? mb_substr($string,$start,$length,'8bit') : substr($string,$start,$length);
}
|
[
"private",
"function",
"substr",
"(",
"$",
"string",
",",
"$",
"start",
",",
"$",
"length",
")",
"{",
"return",
"$",
"this",
"->",
"_mbstring",
"?",
"mb_substr",
"(",
"$",
"string",
",",
"$",
"start",
",",
"$",
"length",
",",
"'8bit'",
")",
":",
"substr",
"(",
"$",
"string",
",",
"$",
"start",
",",
"$",
"length",
")",
";",
"}"
] |
Returns the portion of string specified by the start and length parameters.
If available uses the multibyte string function mb_substr
@param string $string the input string. Must be one character or longer.
@param integer $start the starting position
@param integer $length the desired portion length
@return string the extracted part of string, or FALSE on failure or an empty string.
|
[
"Returns",
"the",
"portion",
"of",
"string",
"specified",
"by",
"the",
"start",
"and",
"length",
"parameters",
".",
"If",
"available",
"uses",
"the",
"multibyte",
"string",
"function",
"mb_substr"
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/base/CSecurityManager.php#L517-L520
|
train
|
yiisoft/yii
|
framework/base/CSecurityManager.php
|
CSecurityManager.unmaskToken
|
public function unmaskToken($maskedToken)
{
$decoded=base64_decode(strtr($maskedToken,'-_','+/'));
$length=$this->strlen($decoded)/2;
// Check if the masked token has an even length.
if(!is_int($length))
return '';
return $this->substr($decoded,$length,$length)^$this->substr($decoded,0,$length);
}
|
php
|
public function unmaskToken($maskedToken)
{
$decoded=base64_decode(strtr($maskedToken,'-_','+/'));
$length=$this->strlen($decoded)/2;
// Check if the masked token has an even length.
if(!is_int($length))
return '';
return $this->substr($decoded,$length,$length)^$this->substr($decoded,0,$length);
}
|
[
"public",
"function",
"unmaskToken",
"(",
"$",
"maskedToken",
")",
"{",
"$",
"decoded",
"=",
"base64_decode",
"(",
"strtr",
"(",
"$",
"maskedToken",
",",
"'-_'",
",",
"'+/'",
")",
")",
";",
"$",
"length",
"=",
"$",
"this",
"->",
"strlen",
"(",
"$",
"decoded",
")",
"/",
"2",
";",
"// Check if the masked token has an even length.",
"if",
"(",
"!",
"is_int",
"(",
"$",
"length",
")",
")",
"return",
"''",
";",
"return",
"$",
"this",
"->",
"substr",
"(",
"$",
"decoded",
",",
"$",
"length",
",",
"$",
"length",
")",
"^",
"$",
"this",
"->",
"substr",
"(",
"$",
"decoded",
",",
"0",
",",
"$",
"length",
")",
";",
"}"
] |
Unmasks a token previously masked by `maskToken`.
@param string $maskedToken A masked token.
@return string An unmasked token, or an empty string in case of token format is invalid.
@since 1.1.18
|
[
"Unmasks",
"a",
"token",
"previously",
"masked",
"by",
"maskToken",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/base/CSecurityManager.php#L639-L647
|
train
|
yiisoft/yii
|
framework/i18n/gettext/CGettextPoFile.php
|
CGettextPoFile.load
|
public function load($file,$context)
{
$pattern='/(msgctxt\s+"(.*?(?<!\\\\))")?\s+'
.'msgid\s+((?:".*(?<!\\\\)"\s*)+)\s+'
.'msgstr\s+((?:".*(?<!\\\\)"\s*)+)/';
$matches=array();
$n=preg_match_all($pattern,file_get_contents($file),$matches);
$messages=array();
for($i=0; $i<$n; $i++)
{
if($matches[2][$i]===$context)
{
$id=$this->decode($matches[3][$i]);
$message=$this->decode($matches[4][$i]);
$messages[$id]=$message;
}
}
return $messages;
}
|
php
|
public function load($file,$context)
{
$pattern='/(msgctxt\s+"(.*?(?<!\\\\))")?\s+'
.'msgid\s+((?:".*(?<!\\\\)"\s*)+)\s+'
.'msgstr\s+((?:".*(?<!\\\\)"\s*)+)/';
$matches=array();
$n=preg_match_all($pattern,file_get_contents($file),$matches);
$messages=array();
for($i=0; $i<$n; $i++)
{
if($matches[2][$i]===$context)
{
$id=$this->decode($matches[3][$i]);
$message=$this->decode($matches[4][$i]);
$messages[$id]=$message;
}
}
return $messages;
}
|
[
"public",
"function",
"load",
"(",
"$",
"file",
",",
"$",
"context",
")",
"{",
"$",
"pattern",
"=",
"'/(msgctxt\\s+\"(.*?(?<!\\\\\\\\))\")?\\s+'",
".",
"'msgid\\s+((?:\".*(?<!\\\\\\\\)\"\\s*)+)\\s+'",
".",
"'msgstr\\s+((?:\".*(?<!\\\\\\\\)\"\\s*)+)/'",
";",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"$",
"n",
"=",
"preg_match_all",
"(",
"$",
"pattern",
",",
"file_get_contents",
"(",
"$",
"file",
")",
",",
"$",
"matches",
")",
";",
"$",
"messages",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"n",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"matches",
"[",
"2",
"]",
"[",
"$",
"i",
"]",
"===",
"$",
"context",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"decode",
"(",
"$",
"matches",
"[",
"3",
"]",
"[",
"$",
"i",
"]",
")",
";",
"$",
"message",
"=",
"$",
"this",
"->",
"decode",
"(",
"$",
"matches",
"[",
"4",
"]",
"[",
"$",
"i",
"]",
")",
";",
"$",
"messages",
"[",
"$",
"id",
"]",
"=",
"$",
"message",
";",
"}",
"}",
"return",
"$",
"messages",
";",
"}"
] |
Loads messages from a PO file.
@param string $file file path
@param string $context message context
@return array message translations (source message => translated message)
|
[
"Loads",
"messages",
"from",
"a",
"PO",
"file",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/gettext/CGettextPoFile.php#L26-L45
|
train
|
yiisoft/yii
|
framework/cli/commands/shell/ModelCommand.php
|
ModelCommand.generateClassNames
|
protected function generateClassNames($schema,$pattern=null)
{
$this->_tables=array();
foreach($schema->getTableNames() as $name)
{
if($pattern===null)
$this->_tables[$name]=$this->generateClassName($this->removePrefix($name));
elseif(preg_match($pattern,$name,$matches))
{
if(count($matches)>1 && !empty($matches[1]))
$className=$this->generateClassName($matches[1]);
else
$className=$this->generateClassName($matches[0]);
$this->_tables[$name]=empty($className) ? $name : $className;
}
}
}
|
php
|
protected function generateClassNames($schema,$pattern=null)
{
$this->_tables=array();
foreach($schema->getTableNames() as $name)
{
if($pattern===null)
$this->_tables[$name]=$this->generateClassName($this->removePrefix($name));
elseif(preg_match($pattern,$name,$matches))
{
if(count($matches)>1 && !empty($matches[1]))
$className=$this->generateClassName($matches[1]);
else
$className=$this->generateClassName($matches[0]);
$this->_tables[$name]=empty($className) ? $name : $className;
}
}
}
|
[
"protected",
"function",
"generateClassNames",
"(",
"$",
"schema",
",",
"$",
"pattern",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_tables",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"schema",
"->",
"getTableNames",
"(",
")",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"pattern",
"===",
"null",
")",
"$",
"this",
"->",
"_tables",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"generateClassName",
"(",
"$",
"this",
"->",
"removePrefix",
"(",
"$",
"name",
")",
")",
";",
"elseif",
"(",
"preg_match",
"(",
"$",
"pattern",
",",
"$",
"name",
",",
"$",
"matches",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"matches",
")",
">",
"1",
"&&",
"!",
"empty",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
")",
"$",
"className",
"=",
"$",
"this",
"->",
"generateClassName",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"else",
"$",
"className",
"=",
"$",
"this",
"->",
"generateClassName",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"_tables",
"[",
"$",
"name",
"]",
"=",
"empty",
"(",
"$",
"className",
")",
"?",
"$",
"name",
":",
"$",
"className",
";",
"}",
"}",
"}"
] |
Generates the mapping table between table names and class names.
@param CDbSchema $schema the database schema
@param string $pattern a regular expression that may be used to filter table names
|
[
"Generates",
"the",
"mapping",
"table",
"between",
"table",
"names",
"and",
"class",
"names",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/cli/commands/shell/ModelCommand.php#L201-L217
|
train
|
yiisoft/yii
|
framework/zii/widgets/grid/CDataColumn.php
|
CDataColumn.init
|
public function init()
{
parent::init();
if($this->name===null)
$this->sortable=false;
if($this->name===null && $this->value===null)
throw new CException(Yii::t('zii','Either "name" or "value" must be specified for CDataColumn.'));
}
|
php
|
public function init()
{
parent::init();
if($this->name===null)
$this->sortable=false;
if($this->name===null && $this->value===null)
throw new CException(Yii::t('zii','Either "name" or "value" must be specified for CDataColumn.'));
}
|
[
"public",
"function",
"init",
"(",
")",
"{",
"parent",
"::",
"init",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"name",
"===",
"null",
")",
"$",
"this",
"->",
"sortable",
"=",
"false",
";",
"if",
"(",
"$",
"this",
"->",
"name",
"===",
"null",
"&&",
"$",
"this",
"->",
"value",
"===",
"null",
")",
"throw",
"new",
"CException",
"(",
"Yii",
"::",
"t",
"(",
"'zii'",
",",
"'Either \"name\" or \"value\" must be specified for CDataColumn.'",
")",
")",
";",
"}"
] |
Initializes the column.
|
[
"Initializes",
"the",
"column",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/zii/widgets/grid/CDataColumn.php#L78-L85
|
train
|
yiisoft/yii
|
framework/zii/widgets/grid/CDataColumn.php
|
CDataColumn.getHeaderCellContent
|
public function getHeaderCellContent()
{
if($this->grid->enableSorting && $this->sortable && $this->name!==null)
return $this->grid->dataProvider->getSort()->link($this->name,$this->header,array('class'=>'sort-link'));
elseif($this->name!==null && $this->header===null)
{
if($this->grid->dataProvider instanceof CActiveDataProvider)
return CHtml::encode($this->grid->dataProvider->model->getAttributeLabel($this->name));
else
return CHtml::encode($this->name);
}
else
return parent::getHeaderCellContent();
}
|
php
|
public function getHeaderCellContent()
{
if($this->grid->enableSorting && $this->sortable && $this->name!==null)
return $this->grid->dataProvider->getSort()->link($this->name,$this->header,array('class'=>'sort-link'));
elseif($this->name!==null && $this->header===null)
{
if($this->grid->dataProvider instanceof CActiveDataProvider)
return CHtml::encode($this->grid->dataProvider->model->getAttributeLabel($this->name));
else
return CHtml::encode($this->name);
}
else
return parent::getHeaderCellContent();
}
|
[
"public",
"function",
"getHeaderCellContent",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"grid",
"->",
"enableSorting",
"&&",
"$",
"this",
"->",
"sortable",
"&&",
"$",
"this",
"->",
"name",
"!==",
"null",
")",
"return",
"$",
"this",
"->",
"grid",
"->",
"dataProvider",
"->",
"getSort",
"(",
")",
"->",
"link",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"this",
"->",
"header",
",",
"array",
"(",
"'class'",
"=>",
"'sort-link'",
")",
")",
";",
"elseif",
"(",
"$",
"this",
"->",
"name",
"!==",
"null",
"&&",
"$",
"this",
"->",
"header",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"grid",
"->",
"dataProvider",
"instanceof",
"CActiveDataProvider",
")",
"return",
"CHtml",
"::",
"encode",
"(",
"$",
"this",
"->",
"grid",
"->",
"dataProvider",
"->",
"model",
"->",
"getAttributeLabel",
"(",
"$",
"this",
"->",
"name",
")",
")",
";",
"else",
"return",
"CHtml",
"::",
"encode",
"(",
"$",
"this",
"->",
"name",
")",
";",
"}",
"else",
"return",
"parent",
"::",
"getHeaderCellContent",
"(",
")",
";",
"}"
] |
Returns the header cell content.
This method will render a link that can trigger the sorting if the column is sortable.
@return string the header cell content.
@since 1.1.16
|
[
"Returns",
"the",
"header",
"cell",
"content",
".",
"This",
"method",
"will",
"render",
"a",
"link",
"that",
"can",
"trigger",
"the",
"sorting",
"if",
"the",
"column",
"is",
"sortable",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/zii/widgets/grid/CDataColumn.php#L116-L129
|
train
|
yiisoft/yii
|
framework/caching/dependencies/CDirectoryCacheDependency.php
|
CDirectoryCacheDependency.generateDependentData
|
protected function generateDependentData()
{
if($this->directory!==null)
return $this->generateTimestamps($this->directory);
else
throw new CException(Yii::t('yii','CDirectoryCacheDependency.directory cannot be empty.'));
}
|
php
|
protected function generateDependentData()
{
if($this->directory!==null)
return $this->generateTimestamps($this->directory);
else
throw new CException(Yii::t('yii','CDirectoryCacheDependency.directory cannot be empty.'));
}
|
[
"protected",
"function",
"generateDependentData",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"directory",
"!==",
"null",
")",
"return",
"$",
"this",
"->",
"generateTimestamps",
"(",
"$",
"this",
"->",
"directory",
")",
";",
"else",
"throw",
"new",
"CException",
"(",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'CDirectoryCacheDependency.directory cannot be empty.'",
")",
")",
";",
"}"
] |
Generates the data needed to determine if dependency has been changed.
This method returns the modification timestamps for files under the directory.
@throws CException if {@link directory} is empty
@return mixed the data needed to determine if dependency has been changed.
|
[
"Generates",
"the",
"data",
"needed",
"to",
"determine",
"if",
"dependency",
"has",
"been",
"changed",
".",
"This",
"method",
"returns",
"the",
"modification",
"timestamps",
"for",
"files",
"under",
"the",
"directory",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/caching/dependencies/CDirectoryCacheDependency.php#L66-L72
|
train
|
yiisoft/yii
|
framework/i18n/CLocale.php
|
CLocale.getInstance
|
public static function getInstance($id)
{
static $locales=array();
if(isset($locales[$id]))
return $locales[$id];
else
return $locales[$id]=new CLocale($id);
}
|
php
|
public static function getInstance($id)
{
static $locales=array();
if(isset($locales[$id]))
return $locales[$id];
else
return $locales[$id]=new CLocale($id);
}
|
[
"public",
"static",
"function",
"getInstance",
"(",
"$",
"id",
")",
"{",
"static",
"$",
"locales",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"locales",
"[",
"$",
"id",
"]",
")",
")",
"return",
"$",
"locales",
"[",
"$",
"id",
"]",
";",
"else",
"return",
"$",
"locales",
"[",
"$",
"id",
"]",
"=",
"new",
"CLocale",
"(",
"$",
"id",
")",
";",
"}"
] |
Returns the instance of the specified locale.
Since the constructor of CLocale is protected, you can only use
this method to obtain an instance of the specified locale.
@param string $id the locale ID (e.g. en_US)
@return CLocale the locale instance
|
[
"Returns",
"the",
"instance",
"of",
"the",
"specified",
"locale",
".",
"Since",
"the",
"constructor",
"of",
"CLocale",
"is",
"protected",
"you",
"can",
"only",
"use",
"this",
"method",
"to",
"obtain",
"an",
"instance",
"of",
"the",
"specified",
"locale",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CLocale.php#L58-L65
|
train
|
yiisoft/yii
|
framework/i18n/CLocale.php
|
CLocale.getMonthNames
|
public function getMonthNames($width='wide',$standAlone=false)
{
if($standAlone)
return isset($this->_data['monthNamesSA'][$width]) ? $this->_data['monthNamesSA'][$width] : $this->_data['monthNames'][$width];
else
return isset($this->_data['monthNames'][$width]) ? $this->_data['monthNames'][$width] : $this->_data['monthNamesSA'][$width];
}
|
php
|
public function getMonthNames($width='wide',$standAlone=false)
{
if($standAlone)
return isset($this->_data['monthNamesSA'][$width]) ? $this->_data['monthNamesSA'][$width] : $this->_data['monthNames'][$width];
else
return isset($this->_data['monthNames'][$width]) ? $this->_data['monthNames'][$width] : $this->_data['monthNamesSA'][$width];
}
|
[
"public",
"function",
"getMonthNames",
"(",
"$",
"width",
"=",
"'wide'",
",",
"$",
"standAlone",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"standAlone",
")",
"return",
"isset",
"(",
"$",
"this",
"->",
"_data",
"[",
"'monthNamesSA'",
"]",
"[",
"$",
"width",
"]",
")",
"?",
"$",
"this",
"->",
"_data",
"[",
"'monthNamesSA'",
"]",
"[",
"$",
"width",
"]",
":",
"$",
"this",
"->",
"_data",
"[",
"'monthNames'",
"]",
"[",
"$",
"width",
"]",
";",
"else",
"return",
"isset",
"(",
"$",
"this",
"->",
"_data",
"[",
"'monthNames'",
"]",
"[",
"$",
"width",
"]",
")",
"?",
"$",
"this",
"->",
"_data",
"[",
"'monthNames'",
"]",
"[",
"$",
"width",
"]",
":",
"$",
"this",
"->",
"_data",
"[",
"'monthNamesSA'",
"]",
"[",
"$",
"width",
"]",
";",
"}"
] |
Returns the month names in the specified width.
@param string $width month name width. It can be 'wide', 'abbreviated' or 'narrow'.
@param boolean $standAlone whether the month names should be returned in stand-alone format
@return array month names indexed by month values (1-12)
|
[
"Returns",
"the",
"month",
"names",
"in",
"the",
"specified",
"width",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CLocale.php#L217-L223
|
train
|
yiisoft/yii
|
framework/i18n/CLocale.php
|
CLocale.getWeekDayNames
|
public function getWeekDayNames($width='wide',$standAlone=false)
{
if($standAlone)
return isset($this->_data['weekDayNamesSA'][$width]) ? $this->_data['weekDayNamesSA'][$width] : $this->_data['weekDayNames'][$width];
else
return isset($this->_data['weekDayNames'][$width]) ? $this->_data['weekDayNames'][$width] : $this->_data['weekDayNamesSA'][$width];
}
|
php
|
public function getWeekDayNames($width='wide',$standAlone=false)
{
if($standAlone)
return isset($this->_data['weekDayNamesSA'][$width]) ? $this->_data['weekDayNamesSA'][$width] : $this->_data['weekDayNames'][$width];
else
return isset($this->_data['weekDayNames'][$width]) ? $this->_data['weekDayNames'][$width] : $this->_data['weekDayNamesSA'][$width];
}
|
[
"public",
"function",
"getWeekDayNames",
"(",
"$",
"width",
"=",
"'wide'",
",",
"$",
"standAlone",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"standAlone",
")",
"return",
"isset",
"(",
"$",
"this",
"->",
"_data",
"[",
"'weekDayNamesSA'",
"]",
"[",
"$",
"width",
"]",
")",
"?",
"$",
"this",
"->",
"_data",
"[",
"'weekDayNamesSA'",
"]",
"[",
"$",
"width",
"]",
":",
"$",
"this",
"->",
"_data",
"[",
"'weekDayNames'",
"]",
"[",
"$",
"width",
"]",
";",
"else",
"return",
"isset",
"(",
"$",
"this",
"->",
"_data",
"[",
"'weekDayNames'",
"]",
"[",
"$",
"width",
"]",
")",
"?",
"$",
"this",
"->",
"_data",
"[",
"'weekDayNames'",
"]",
"[",
"$",
"width",
"]",
":",
"$",
"this",
"->",
"_data",
"[",
"'weekDayNamesSA'",
"]",
"[",
"$",
"width",
"]",
";",
"}"
] |
Returns the week day names in the specified width.
@param string $width weekday name width. It can be 'wide', 'abbreviated' or 'narrow'.
@param boolean $standAlone whether the week day name should be returned in stand-alone format
@return array the weekday names indexed by weekday values (0-6, 0 means Sunday, 1 Monday, etc.)
|
[
"Returns",
"the",
"week",
"day",
"names",
"in",
"the",
"specified",
"width",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CLocale.php#L246-L252
|
train
|
yiisoft/yii
|
framework/i18n/CLocale.php
|
CLocale.getLanguageID
|
public function getLanguageID($id)
{
// normalize id
$id = $this->getCanonicalID($id);
// remove sub tags
if(($underscorePosition=strpos($id, '_'))!== false)
{
$id = substr($id, 0, $underscorePosition);
}
return $id;
}
|
php
|
public function getLanguageID($id)
{
// normalize id
$id = $this->getCanonicalID($id);
// remove sub tags
if(($underscorePosition=strpos($id, '_'))!== false)
{
$id = substr($id, 0, $underscorePosition);
}
return $id;
}
|
[
"public",
"function",
"getLanguageID",
"(",
"$",
"id",
")",
"{",
"// normalize id",
"$",
"id",
"=",
"$",
"this",
"->",
"getCanonicalID",
"(",
"$",
"id",
")",
";",
"// remove sub tags",
"if",
"(",
"(",
"$",
"underscorePosition",
"=",
"strpos",
"(",
"$",
"id",
",",
"'_'",
")",
")",
"!==",
"false",
")",
"{",
"$",
"id",
"=",
"substr",
"(",
"$",
"id",
",",
"0",
",",
"$",
"underscorePosition",
")",
";",
"}",
"return",
"$",
"id",
";",
"}"
] |
Converts a locale ID to a language ID.
A language ID consists of only the first group of letters before an underscore or dash.
@param string $id the locale ID to be converted
@return string the language ID
@since 1.1.9
|
[
"Converts",
"a",
"locale",
"ID",
"to",
"a",
"language",
"ID",
".",
"A",
"language",
"ID",
"consists",
"of",
"only",
"the",
"first",
"group",
"of",
"letters",
"before",
"an",
"underscore",
"or",
"dash",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CLocale.php#L330-L340
|
train
|
yiisoft/yii
|
framework/i18n/CLocale.php
|
CLocale.getScriptID
|
public function getScriptID($id)
{
// normalize id
$id = $this->getCanonicalID($id);
// find sub tags
if(($underscorePosition=strpos($id, '_'))!==false)
{
$subTag = explode('_', $id);
// script sub tags can be distinguished from territory sub tags by length
if (strlen($subTag[1])===4)
{
$id = $subTag[1];
}
else
{
$id = null;
}
}
else
{
$id = null;
}
return $id;
}
|
php
|
public function getScriptID($id)
{
// normalize id
$id = $this->getCanonicalID($id);
// find sub tags
if(($underscorePosition=strpos($id, '_'))!==false)
{
$subTag = explode('_', $id);
// script sub tags can be distinguished from territory sub tags by length
if (strlen($subTag[1])===4)
{
$id = $subTag[1];
}
else
{
$id = null;
}
}
else
{
$id = null;
}
return $id;
}
|
[
"public",
"function",
"getScriptID",
"(",
"$",
"id",
")",
"{",
"// normalize id",
"$",
"id",
"=",
"$",
"this",
"->",
"getCanonicalID",
"(",
"$",
"id",
")",
";",
"// find sub tags",
"if",
"(",
"(",
"$",
"underscorePosition",
"=",
"strpos",
"(",
"$",
"id",
",",
"'_'",
")",
")",
"!==",
"false",
")",
"{",
"$",
"subTag",
"=",
"explode",
"(",
"'_'",
",",
"$",
"id",
")",
";",
"// script sub tags can be distinguished from territory sub tags by length",
"if",
"(",
"strlen",
"(",
"$",
"subTag",
"[",
"1",
"]",
")",
"===",
"4",
")",
"{",
"$",
"id",
"=",
"$",
"subTag",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"id",
"=",
"null",
";",
"}",
"}",
"else",
"{",
"$",
"id",
"=",
"null",
";",
"}",
"return",
"$",
"id",
";",
"}"
] |
Converts a locale ID to a script ID.
A script ID consists of only the last four characters after an underscore or dash.
@param string $id the locale ID to be converted
@return string the script ID
@since 1.1.9
|
[
"Converts",
"a",
"locale",
"ID",
"to",
"a",
"script",
"ID",
".",
"A",
"script",
"ID",
"consists",
"of",
"only",
"the",
"last",
"four",
"characters",
"after",
"an",
"underscore",
"or",
"dash",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CLocale.php#L349-L372
|
train
|
yiisoft/yii
|
framework/i18n/CLocale.php
|
CLocale.getTerritoryID
|
public function getTerritoryID($id)
{
// normalize id
$id = $this->getCanonicalID($id);
// find sub tags
if (($underscorePosition=strpos($id, '_'))!== false)
{
$subTag = explode('_', $id);
// territory sub tags can be distinguished from script sub tags by length
if (isset($subTag[2]) && strlen($subTag[2])<4)
{
$id = $subTag[2];
}
elseif (strlen($subTag[1])<4)
{
$id = $subTag[1];
}
else
{
$id = null;
}
}
else
{
$id = null;
}
return $id;
}
|
php
|
public function getTerritoryID($id)
{
// normalize id
$id = $this->getCanonicalID($id);
// find sub tags
if (($underscorePosition=strpos($id, '_'))!== false)
{
$subTag = explode('_', $id);
// territory sub tags can be distinguished from script sub tags by length
if (isset($subTag[2]) && strlen($subTag[2])<4)
{
$id = $subTag[2];
}
elseif (strlen($subTag[1])<4)
{
$id = $subTag[1];
}
else
{
$id = null;
}
}
else
{
$id = null;
}
return $id;
}
|
[
"public",
"function",
"getTerritoryID",
"(",
"$",
"id",
")",
"{",
"// normalize id",
"$",
"id",
"=",
"$",
"this",
"->",
"getCanonicalID",
"(",
"$",
"id",
")",
";",
"// find sub tags",
"if",
"(",
"(",
"$",
"underscorePosition",
"=",
"strpos",
"(",
"$",
"id",
",",
"'_'",
")",
")",
"!==",
"false",
")",
"{",
"$",
"subTag",
"=",
"explode",
"(",
"'_'",
",",
"$",
"id",
")",
";",
"// territory sub tags can be distinguished from script sub tags by length",
"if",
"(",
"isset",
"(",
"$",
"subTag",
"[",
"2",
"]",
")",
"&&",
"strlen",
"(",
"$",
"subTag",
"[",
"2",
"]",
")",
"<",
"4",
")",
"{",
"$",
"id",
"=",
"$",
"subTag",
"[",
"2",
"]",
";",
"}",
"elseif",
"(",
"strlen",
"(",
"$",
"subTag",
"[",
"1",
"]",
")",
"<",
"4",
")",
"{",
"$",
"id",
"=",
"$",
"subTag",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"id",
"=",
"null",
";",
"}",
"}",
"else",
"{",
"$",
"id",
"=",
"null",
";",
"}",
"return",
"$",
"id",
";",
"}"
] |
Converts a locale ID to a territory ID.
A territory ID consists of only the last two to three letter or digits after an underscore or dash.
@param string $id the locale ID to be converted
@return string the territory ID
@since 1.1.9
|
[
"Converts",
"a",
"locale",
"ID",
"to",
"a",
"territory",
"ID",
".",
"A",
"territory",
"ID",
"consists",
"of",
"only",
"the",
"last",
"two",
"to",
"three",
"letter",
"or",
"digits",
"after",
"an",
"underscore",
"or",
"dash",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CLocale.php#L381-L408
|
train
|
yiisoft/yii
|
framework/collections/CAttributeCollection.php
|
CAttributeCollection.__isset
|
public function __isset($name)
{
if($this->contains($name))
return $this->itemAt($name)!==null;
else
return parent::__isset($name);
}
|
php
|
public function __isset($name)
{
if($this->contains($name))
return $this->itemAt($name)!==null;
else
return parent::__isset($name);
}
|
[
"public",
"function",
"__isset",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"contains",
"(",
"$",
"name",
")",
")",
"return",
"$",
"this",
"->",
"itemAt",
"(",
"$",
"name",
")",
"!==",
"null",
";",
"else",
"return",
"parent",
"::",
"__isset",
"(",
"$",
"name",
")",
";",
"}"
] |
Checks if a property value is null.
This method overrides the parent implementation by checking
if the key exists in the collection and contains a non-null value.
@param string $name the property name or the event name
@return boolean whether the property value is null
|
[
"Checks",
"if",
"a",
"property",
"value",
"is",
"null",
".",
"This",
"method",
"overrides",
"the",
"parent",
"implementation",
"by",
"checking",
"if",
"the",
"key",
"exists",
"in",
"the",
"collection",
"and",
"contains",
"a",
"non",
"-",
"null",
"value",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/collections/CAttributeCollection.php#L74-L80
|
train
|
yiisoft/yii
|
framework/collections/CAttributeCollection.php
|
CAttributeCollection.mergeWith
|
public function mergeWith($data,$recursive=true)
{
if(!$this->caseSensitive && (is_array($data) || $data instanceof Traversable))
{
$d=array();
foreach($data as $key=>$value)
$d[strtolower($key)]=$value;
return parent::mergeWith($d,$recursive);
}
parent::mergeWith($data,$recursive);
}
|
php
|
public function mergeWith($data,$recursive=true)
{
if(!$this->caseSensitive && (is_array($data) || $data instanceof Traversable))
{
$d=array();
foreach($data as $key=>$value)
$d[strtolower($key)]=$value;
return parent::mergeWith($d,$recursive);
}
parent::mergeWith($data,$recursive);
}
|
[
"public",
"function",
"mergeWith",
"(",
"$",
"data",
",",
"$",
"recursive",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"caseSensitive",
"&&",
"(",
"is_array",
"(",
"$",
"data",
")",
"||",
"$",
"data",
"instanceof",
"Traversable",
")",
")",
"{",
"$",
"d",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"$",
"d",
"[",
"strtolower",
"(",
"$",
"key",
")",
"]",
"=",
"$",
"value",
";",
"return",
"parent",
"::",
"mergeWith",
"(",
"$",
"d",
",",
"$",
"recursive",
")",
";",
"}",
"parent",
"::",
"mergeWith",
"(",
"$",
"data",
",",
"$",
"recursive",
")",
";",
"}"
] |
Merges iterable data into the map.
Existing elements in the map will be overwritten if their keys are the same as those in the source.
If the merge is recursive, the following algorithm is performed:
<ul>
<li>the map data is saved as $a, and the source data is saved as $b;</li>
<li>if $a and $b both have an array indexed at the same string key, the arrays will be merged using this algorithm;</li>
<li>any integer-indexed elements in $b will be appended to $a and reindexed accordingly;</li>
<li>any string-indexed elements in $b will overwrite elements in $a with the same index;</li>
</ul>
@param mixed $data the data to be merged with, must be an array or object implementing Traversable
@param boolean $recursive whether the merging should be recursive.
@throws CException If data is neither an array nor an iterator.
|
[
"Merges",
"iterable",
"data",
"into",
"the",
"map",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/collections/CAttributeCollection.php#L202-L212
|
train
|
yiisoft/yii
|
framework/web/CDataProvider.php
|
CDataProvider.getPagination
|
public function getPagination($className='CPagination')
{
if($this->_pagination===null)
{
$this->_pagination=new $className;
if(($id=$this->getId())!='')
$this->_pagination->pageVar=$id.'_page';
}
return $this->_pagination;
}
|
php
|
public function getPagination($className='CPagination')
{
if($this->_pagination===null)
{
$this->_pagination=new $className;
if(($id=$this->getId())!='')
$this->_pagination->pageVar=$id.'_page';
}
return $this->_pagination;
}
|
[
"public",
"function",
"getPagination",
"(",
"$",
"className",
"=",
"'CPagination'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_pagination",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_pagination",
"=",
"new",
"$",
"className",
";",
"if",
"(",
"(",
"$",
"id",
"=",
"$",
"this",
"->",
"getId",
"(",
")",
")",
"!=",
"''",
")",
"$",
"this",
"->",
"_pagination",
"->",
"pageVar",
"=",
"$",
"id",
".",
"'_page'",
";",
"}",
"return",
"$",
"this",
"->",
"_pagination",
";",
"}"
] |
Returns the pagination object.
@param string $className the pagination object class name. Parameter is available since version 1.1.13.
@return CPagination|false the pagination object. If this is false, it means the pagination is disabled.
|
[
"Returns",
"the",
"pagination",
"object",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CDataProvider.php#L69-L78
|
train
|
yiisoft/yii
|
framework/web/CDataProvider.php
|
CDataProvider.getSort
|
public function getSort($className='CSort')
{
if($this->_sort===null)
{
$this->_sort=new $className;
if(($id=$this->getId())!='')
$this->_sort->sortVar=$id.'_sort';
}
return $this->_sort;
}
|
php
|
public function getSort($className='CSort')
{
if($this->_sort===null)
{
$this->_sort=new $className;
if(($id=$this->getId())!='')
$this->_sort->sortVar=$id.'_sort';
}
return $this->_sort;
}
|
[
"public",
"function",
"getSort",
"(",
"$",
"className",
"=",
"'CSort'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_sort",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_sort",
"=",
"new",
"$",
"className",
";",
"if",
"(",
"(",
"$",
"id",
"=",
"$",
"this",
"->",
"getId",
"(",
")",
")",
"!=",
"''",
")",
"$",
"this",
"->",
"_sort",
"->",
"sortVar",
"=",
"$",
"id",
".",
"'_sort'",
";",
"}",
"return",
"$",
"this",
"->",
"_sort",
";",
"}"
] |
Returns the sort object.
@param string $className the sorting object class name. Parameter is available since version 1.1.13.
@return CSort|false the sorting object. If this is false, it means the sorting is disabled.
|
[
"Returns",
"the",
"sort",
"object",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CDataProvider.php#L117-L126
|
train
|
yiisoft/yii
|
framework/web/CDataProvider.php
|
CDataProvider.getData
|
public function getData($refresh=false)
{
if($this->_data===null || $refresh)
$this->_data=$this->fetchData();
return $this->_data;
}
|
php
|
public function getData($refresh=false)
{
if($this->_data===null || $refresh)
$this->_data=$this->fetchData();
return $this->_data;
}
|
[
"public",
"function",
"getData",
"(",
"$",
"refresh",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_data",
"===",
"null",
"||",
"$",
"refresh",
")",
"$",
"this",
"->",
"_data",
"=",
"$",
"this",
"->",
"fetchData",
"(",
")",
";",
"return",
"$",
"this",
"->",
"_data",
";",
"}"
] |
Returns the data items currently available.
@param boolean $refresh whether the data should be re-fetched from persistent storage.
@return array the list of data items currently available in this data provider.
|
[
"Returns",
"the",
"data",
"items",
"currently",
"available",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CDataProvider.php#L165-L170
|
train
|
yiisoft/yii
|
framework/web/CDataProvider.php
|
CDataProvider.getKeys
|
public function getKeys($refresh=false)
{
if($this->_keys===null || $refresh)
$this->_keys=$this->fetchKeys();
return $this->_keys;
}
|
php
|
public function getKeys($refresh=false)
{
if($this->_keys===null || $refresh)
$this->_keys=$this->fetchKeys();
return $this->_keys;
}
|
[
"public",
"function",
"getKeys",
"(",
"$",
"refresh",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_keys",
"===",
"null",
"||",
"$",
"refresh",
")",
"$",
"this",
"->",
"_keys",
"=",
"$",
"this",
"->",
"fetchKeys",
"(",
")",
";",
"return",
"$",
"this",
"->",
"_keys",
";",
"}"
] |
Returns the key values associated with the data items.
@param boolean $refresh whether the keys should be re-calculated.
@return array the list of key values corresponding to {@link data}. Each data item in {@link data}
is uniquely identified by the corresponding key value in this array.
|
[
"Returns",
"the",
"key",
"values",
"associated",
"with",
"the",
"data",
"items",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CDataProvider.php#L187-L192
|
train
|
yiisoft/yii
|
framework/web/auth/CAuthItem.php
|
CAuthItem.assign
|
public function assign($userId,$bizRule=null,$data=null)
{
return $this->_auth->assign($this->_name,$userId,$bizRule,$data);
}
|
php
|
public function assign($userId,$bizRule=null,$data=null)
{
return $this->_auth->assign($this->_name,$userId,$bizRule,$data);
}
|
[
"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
|
[
"Assigns",
"this",
"item",
"to",
"a",
"user",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/auth/CAuthItem.php#L239-L242
|
train
|
yiisoft/yii
|
build/commands/lite/protected/controllers/SiteController.php
|
SiteController.actionLogin
|
public function actionLogin()
{
$user=new LoginForm;
if(Yii::app()->request->isPostRequest)
{
// collect user input data
if(isset($_POST['LoginForm']))
$user->setAttributes($_POST['LoginForm']);
// validate user input and redirect to previous page if valid
if($user->validate())
$this->redirect(Yii::app()->user->returnUrl);
}
// display the login form
$this->render('login',array('user'=>$user));
}
|
php
|
public function actionLogin()
{
$user=new LoginForm;
if(Yii::app()->request->isPostRequest)
{
// collect user input data
if(isset($_POST['LoginForm']))
$user->setAttributes($_POST['LoginForm']);
// validate user input and redirect to previous page if valid
if($user->validate())
$this->redirect(Yii::app()->user->returnUrl);
}
// display the login form
$this->render('login',array('user'=>$user));
}
|
[
"public",
"function",
"actionLogin",
"(",
")",
"{",
"$",
"user",
"=",
"new",
"LoginForm",
";",
"if",
"(",
"Yii",
"::",
"app",
"(",
")",
"->",
"request",
"->",
"isPostRequest",
")",
"{",
"// collect user input data",
"if",
"(",
"isset",
"(",
"$",
"_POST",
"[",
"'LoginForm'",
"]",
")",
")",
"$",
"user",
"->",
"setAttributes",
"(",
"$",
"_POST",
"[",
"'LoginForm'",
"]",
")",
";",
"// validate user input and redirect to previous page if valid",
"if",
"(",
"$",
"user",
"->",
"validate",
"(",
")",
")",
"$",
"this",
"->",
"redirect",
"(",
"Yii",
"::",
"app",
"(",
")",
"->",
"user",
"->",
"returnUrl",
")",
";",
"}",
"// display the login form",
"$",
"this",
"->",
"render",
"(",
"'login'",
",",
"array",
"(",
"'user'",
"=>",
"$",
"user",
")",
")",
";",
"}"
] |
Displays a login form to login a user.
|
[
"Displays",
"a",
"login",
"form",
"to",
"login",
"a",
"user",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/build/commands/lite/protected/controllers/SiteController.php#L33-L47
|
train
|
yiisoft/yii
|
framework/web/auth/CDbAuthManager.php
|
CDbAuthManager.hasItemChild
|
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;
}
|
php
|
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;
}
|
[
"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
|
[
"Returns",
"a",
"value",
"indicating",
"whether",
"a",
"child",
"exists",
"within",
"a",
"parent",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/auth/CDbAuthManager.php#L195-L204
|
train
|
yiisoft/yii
|
framework/web/auth/CDbAuthManager.php
|
CDbAuthManager.isAssigned
|
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;
}
|
php
|
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;
}
|
[
"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.
|
[
"Returns",
"a",
"value",
"indicating",
"whether",
"the",
"item",
"has",
"been",
"assigned",
"to",
"the",
"user",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/auth/CDbAuthManager.php#L288-L297
|
train
|
yiisoft/yii
|
framework/web/auth/CDbAuthManager.php
|
CDbAuthManager.getAuthAssignments
|
public function getAuthAssignments($userId)
{
$rows=$this->db->createCommand()
->select()
->from($this->assignmentTable)
->where('userid=:userid', array(':userid'=>$userId))
->queryAll();
$assignments=array();
foreach($rows as $row)
{
if(($data=@unserialize($row['data']))===false)
$data=null;
$assignments[$row['itemname']]=new CAuthAssignment($this,$row['itemname'],$row['userid'],$row['bizrule'],$data);
}
return $assignments;
}
|
php
|
public function getAuthAssignments($userId)
{
$rows=$this->db->createCommand()
->select()
->from($this->assignmentTable)
->where('userid=:userid', array(':userid'=>$userId))
->queryAll();
$assignments=array();
foreach($rows as $row)
{
if(($data=@unserialize($row['data']))===false)
$data=null;
$assignments[$row['itemname']]=new CAuthAssignment($this,$row['itemname'],$row['userid'],$row['bizrule'],$data);
}
return $assignments;
}
|
[
"public",
"function",
"getAuthAssignments",
"(",
"$",
"userId",
")",
"{",
"$",
"rows",
"=",
"$",
"this",
"->",
"db",
"->",
"createCommand",
"(",
")",
"->",
"select",
"(",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"assignmentTable",
")",
"->",
"where",
"(",
"'userid=:userid'",
",",
"array",
"(",
"':userid'",
"=>",
"$",
"userId",
")",
")",
"->",
"queryAll",
"(",
")",
";",
"$",
"assignments",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"if",
"(",
"(",
"$",
"data",
"=",
"@",
"unserialize",
"(",
"$",
"row",
"[",
"'data'",
"]",
")",
")",
"===",
"false",
")",
"$",
"data",
"=",
"null",
";",
"$",
"assignments",
"[",
"$",
"row",
"[",
"'itemname'",
"]",
"]",
"=",
"new",
"CAuthAssignment",
"(",
"$",
"this",
",",
"$",
"row",
"[",
"'itemname'",
"]",
",",
"$",
"row",
"[",
"'userid'",
"]",
",",
"$",
"row",
"[",
"'bizrule'",
"]",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"assignments",
";",
"}"
] |
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.
|
[
"Returns",
"the",
"item",
"assignments",
"for",
"the",
"specified",
"user",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/auth/CDbAuthManager.php#L331-L346
|
train
|
yiisoft/yii
|
framework/web/auth/CDbAuthManager.php
|
CDbAuthManager.saveAuthAssignment
|
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()
));
}
|
php
|
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()
));
}
|
[
"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.
|
[
"Saves",
"the",
"changes",
"to",
"an",
"authorization",
"assignment",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/auth/CDbAuthManager.php#L352-L362
|
train
|
yiisoft/yii
|
framework/web/auth/CDbAuthManager.php
|
CDbAuthManager.clearAll
|
public function clearAll()
{
$this->clearAuthAssignments();
$this->db->createCommand()->delete($this->itemChildTable);
$this->db->createCommand()->delete($this->itemTable);
}
|
php
|
public function clearAll()
{
$this->clearAuthAssignments();
$this->db->createCommand()->delete($this->itemChildTable);
$this->db->createCommand()->delete($this->itemTable);
}
|
[
"public",
"function",
"clearAll",
"(",
")",
"{",
"$",
"this",
"->",
"clearAuthAssignments",
"(",
")",
";",
"$",
"this",
"->",
"db",
"->",
"createCommand",
"(",
")",
"->",
"delete",
"(",
"$",
"this",
"->",
"itemChildTable",
")",
";",
"$",
"this",
"->",
"db",
"->",
"createCommand",
"(",
")",
"->",
"delete",
"(",
"$",
"this",
"->",
"itemTable",
")",
";",
"}"
] |
Removes all authorization data.
|
[
"Removes",
"all",
"authorization",
"data",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/auth/CDbAuthManager.php#L548-L553
|
train
|
yiisoft/yii
|
framework/validators/CEmailValidator.php
|
CEmailValidator.validateValue
|
public function validateValue($value)
{
if(is_string($value) && $this->validateIDN)
$value=$this->encodeIDN($value);
// make sure string length is limited to avoid DOS attacks
$valid=is_string($value) && strlen($value)<=254 && (preg_match($this->pattern,$value) || $this->allowName && preg_match($this->fullPattern,$value));
if($valid)
$domain=rtrim(substr($value,strpos($value,'@')+1),'>');
if($valid && $this->checkMX && function_exists('checkdnsrr'))
$valid=checkdnsrr($domain,'MX');
if($valid && $this->checkPort && function_exists('fsockopen') && function_exists('dns_get_record'))
$valid=$this->checkMxPorts($domain);
return $valid;
}
|
php
|
public function validateValue($value)
{
if(is_string($value) && $this->validateIDN)
$value=$this->encodeIDN($value);
// make sure string length is limited to avoid DOS attacks
$valid=is_string($value) && strlen($value)<=254 && (preg_match($this->pattern,$value) || $this->allowName && preg_match($this->fullPattern,$value));
if($valid)
$domain=rtrim(substr($value,strpos($value,'@')+1),'>');
if($valid && $this->checkMX && function_exists('checkdnsrr'))
$valid=checkdnsrr($domain,'MX');
if($valid && $this->checkPort && function_exists('fsockopen') && function_exists('dns_get_record'))
$valid=$this->checkMxPorts($domain);
return $valid;
}
|
[
"public",
"function",
"validateValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"$",
"this",
"->",
"validateIDN",
")",
"$",
"value",
"=",
"$",
"this",
"->",
"encodeIDN",
"(",
"$",
"value",
")",
";",
"// make sure string length is limited to avoid DOS attacks",
"$",
"valid",
"=",
"is_string",
"(",
"$",
"value",
")",
"&&",
"strlen",
"(",
"$",
"value",
")",
"<=",
"254",
"&&",
"(",
"preg_match",
"(",
"$",
"this",
"->",
"pattern",
",",
"$",
"value",
")",
"||",
"$",
"this",
"->",
"allowName",
"&&",
"preg_match",
"(",
"$",
"this",
"->",
"fullPattern",
",",
"$",
"value",
")",
")",
";",
"if",
"(",
"$",
"valid",
")",
"$",
"domain",
"=",
"rtrim",
"(",
"substr",
"(",
"$",
"value",
",",
"strpos",
"(",
"$",
"value",
",",
"'@'",
")",
"+",
"1",
")",
",",
"'>'",
")",
";",
"if",
"(",
"$",
"valid",
"&&",
"$",
"this",
"->",
"checkMX",
"&&",
"function_exists",
"(",
"'checkdnsrr'",
")",
")",
"$",
"valid",
"=",
"checkdnsrr",
"(",
"$",
"domain",
",",
"'MX'",
")",
";",
"if",
"(",
"$",
"valid",
"&&",
"$",
"this",
"->",
"checkPort",
"&&",
"function_exists",
"(",
"'fsockopen'",
")",
"&&",
"function_exists",
"(",
"'dns_get_record'",
")",
")",
"$",
"valid",
"=",
"$",
"this",
"->",
"checkMxPorts",
"(",
"$",
"domain",
")",
";",
"return",
"$",
"valid",
";",
"}"
] |
Validates a static value to see if it is a valid email.
This method is provided so that you can call it directly without going through the model validation rule mechanism.
Note that this method does not respect the {@link allowEmpty} property.
@param mixed $value the value to be validated
@return boolean whether the value is a valid email
@since 1.1.1
@see https://github.com/yiisoft/yii/issues/3764#issuecomment-75457805
|
[
"Validates",
"a",
"static",
"value",
"to",
"see",
"if",
"it",
"is",
"a",
"valid",
"email",
".",
"This",
"method",
"is",
"provided",
"so",
"that",
"you",
"can",
"call",
"it",
"directly",
"without",
"going",
"through",
"the",
"model",
"validation",
"rule",
"mechanism",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/validators/CEmailValidator.php#L98-L111
|
train
|
yiisoft/yii
|
framework/validators/CBooleanValidator.php
|
CBooleanValidator.validateValue
|
public function validateValue($value)
{
if ($this->strict)
return $value===$this->trueValue || $value===$this->falseValue;
else
return $value==$this->trueValue || $value==$this->falseValue;
}
|
php
|
public function validateValue($value)
{
if ($this->strict)
return $value===$this->trueValue || $value===$this->falseValue;
else
return $value==$this->trueValue || $value==$this->falseValue;
}
|
[
"public",
"function",
"validateValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"strict",
")",
"return",
"$",
"value",
"===",
"$",
"this",
"->",
"trueValue",
"||",
"$",
"value",
"===",
"$",
"this",
"->",
"falseValue",
";",
"else",
"return",
"$",
"value",
"==",
"$",
"this",
"->",
"trueValue",
"||",
"$",
"value",
"==",
"$",
"this",
"->",
"falseValue",
";",
"}"
] |
Validates a static value to see if it is a valid boolean.
This method is provided so that you can call it directly without going
through the model validation rule mechanism.
Note that this method does not respect the {@link allowEmpty} property.
@param mixed $value the value to be validated
@return boolean whether the value is a valid boolean
@since 1.1.17
|
[
"Validates",
"a",
"static",
"value",
"to",
"see",
"if",
"it",
"is",
"a",
"valid",
"boolean",
".",
"This",
"method",
"is",
"provided",
"so",
"that",
"you",
"can",
"call",
"it",
"directly",
"without",
"going",
"through",
"the",
"model",
"validation",
"rule",
"mechanism",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/validators/CBooleanValidator.php#L81-L87
|
train
|
yiisoft/yii
|
framework/caching/CRedisCache.php
|
CRedisCache.parseResponse
|
private function parseResponse()
{
if(($line=fgets($this->_socket))===false)
throw new CException('Failed reading data from redis connection socket.');
$type=$line[0];
$line=substr($line,1,-2);
switch($type)
{
case '+': // Status reply
return true;
case '-': // Error reply
throw new CException('Redis error: '.$line);
case ':': // Integer reply
// no cast to int as it is in the range of a signed 64 bit integer
return $line;
case '$': // Bulk replies
if($line=='-1')
return null;
$length=$line+2;
$data='';
while($length>0)
{
if(($block=fread($this->_socket,$length))===false)
throw new CException('Failed reading data from redis connection socket.');
$data.=$block;
$length-=$this->byteLength($block);
}
return substr($data,0,-2);
case '*': // Multi-bulk replies
$count=(int)$line;
$data=array();
for($i=0;$i<$count;$i++)
$data[]=$this->parseResponse();
return $data;
default:
throw new CException('Unable to parse data received from redis.');
}
}
|
php
|
private function parseResponse()
{
if(($line=fgets($this->_socket))===false)
throw new CException('Failed reading data from redis connection socket.');
$type=$line[0];
$line=substr($line,1,-2);
switch($type)
{
case '+': // Status reply
return true;
case '-': // Error reply
throw new CException('Redis error: '.$line);
case ':': // Integer reply
// no cast to int as it is in the range of a signed 64 bit integer
return $line;
case '$': // Bulk replies
if($line=='-1')
return null;
$length=$line+2;
$data='';
while($length>0)
{
if(($block=fread($this->_socket,$length))===false)
throw new CException('Failed reading data from redis connection socket.');
$data.=$block;
$length-=$this->byteLength($block);
}
return substr($data,0,-2);
case '*': // Multi-bulk replies
$count=(int)$line;
$data=array();
for($i=0;$i<$count;$i++)
$data[]=$this->parseResponse();
return $data;
default:
throw new CException('Unable to parse data received from redis.');
}
}
|
[
"private",
"function",
"parseResponse",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"line",
"=",
"fgets",
"(",
"$",
"this",
"->",
"_socket",
")",
")",
"===",
"false",
")",
"throw",
"new",
"CException",
"(",
"'Failed reading data from redis connection socket.'",
")",
";",
"$",
"type",
"=",
"$",
"line",
"[",
"0",
"]",
";",
"$",
"line",
"=",
"substr",
"(",
"$",
"line",
",",
"1",
",",
"-",
"2",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'+'",
":",
"// Status reply",
"return",
"true",
";",
"case",
"'-'",
":",
"// Error reply",
"throw",
"new",
"CException",
"(",
"'Redis error: '",
".",
"$",
"line",
")",
";",
"case",
"':'",
":",
"// Integer reply",
"// no cast to int as it is in the range of a signed 64 bit integer",
"return",
"$",
"line",
";",
"case",
"'$'",
":",
"// Bulk replies",
"if",
"(",
"$",
"line",
"==",
"'-1'",
")",
"return",
"null",
";",
"$",
"length",
"=",
"$",
"line",
"+",
"2",
";",
"$",
"data",
"=",
"''",
";",
"while",
"(",
"$",
"length",
">",
"0",
")",
"{",
"if",
"(",
"(",
"$",
"block",
"=",
"fread",
"(",
"$",
"this",
"->",
"_socket",
",",
"$",
"length",
")",
")",
"===",
"false",
")",
"throw",
"new",
"CException",
"(",
"'Failed reading data from redis connection socket.'",
")",
";",
"$",
"data",
".=",
"$",
"block",
";",
"$",
"length",
"-=",
"$",
"this",
"->",
"byteLength",
"(",
"$",
"block",
")",
";",
"}",
"return",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"-",
"2",
")",
";",
"case",
"'*'",
":",
"// Multi-bulk replies",
"$",
"count",
"=",
"(",
"int",
")",
"$",
"line",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"$",
"data",
"[",
"]",
"=",
"$",
"this",
"->",
"parseResponse",
"(",
")",
";",
"return",
"$",
"data",
";",
"default",
":",
"throw",
"new",
"CException",
"(",
"'Unable to parse data received from redis.'",
")",
";",
"}",
"}"
] |
Reads the result from socket and parses it
@return array|bool|null|string
@throws CException socket or data problems
|
[
"Reads",
"the",
"result",
"from",
"socket",
"and",
"parses",
"it"
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/caching/CRedisCache.php#L143-L180
|
train
|
yiisoft/yii
|
demos/blog/protected/models/Lookup.php
|
Lookup.item
|
public static function item($type,$code)
{
if(!isset(self::$_items[$type]))
self::loadItems($type);
return isset(self::$_items[$type][$code]) ? self::$_items[$type][$code] : false;
}
|
php
|
public static function item($type,$code)
{
if(!isset(self::$_items[$type]))
self::loadItems($type);
return isset(self::$_items[$type][$code]) ? self::$_items[$type][$code] : false;
}
|
[
"public",
"static",
"function",
"item",
"(",
"$",
"type",
",",
"$",
"code",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_items",
"[",
"$",
"type",
"]",
")",
")",
"self",
"::",
"loadItems",
"(",
"$",
"type",
")",
";",
"return",
"isset",
"(",
"self",
"::",
"$",
"_items",
"[",
"$",
"type",
"]",
"[",
"$",
"code",
"]",
")",
"?",
"self",
"::",
"$",
"_items",
"[",
"$",
"type",
"]",
"[",
"$",
"code",
"]",
":",
"false",
";",
"}"
] |
Returns the item name for the specified type and code.
@param string the item type (e.g. 'PostStatus').
@param integer the item code (corresponding to the 'code' column value)
@return string the item name for the specified the code. False is returned if the item type or code does not exist.
|
[
"Returns",
"the",
"item",
"name",
"for",
"the",
"specified",
"type",
"and",
"code",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/demos/blog/protected/models/Lookup.php#L52-L57
|
train
|
yiisoft/yii
|
demos/blog/protected/models/Lookup.php
|
Lookup.loadItems
|
private static function loadItems($type)
{
self::$_items[$type]=array();
$models=self::model()->findAll(array(
'condition'=>'type=:type',
'params'=>array(':type'=>$type),
'order'=>'position',
));
foreach($models as $model)
self::$_items[$type][$model->code]=$model->name;
}
|
php
|
private static function loadItems($type)
{
self::$_items[$type]=array();
$models=self::model()->findAll(array(
'condition'=>'type=:type',
'params'=>array(':type'=>$type),
'order'=>'position',
));
foreach($models as $model)
self::$_items[$type][$model->code]=$model->name;
}
|
[
"private",
"static",
"function",
"loadItems",
"(",
"$",
"type",
")",
"{",
"self",
"::",
"$",
"_items",
"[",
"$",
"type",
"]",
"=",
"array",
"(",
")",
";",
"$",
"models",
"=",
"self",
"::",
"model",
"(",
")",
"->",
"findAll",
"(",
"array",
"(",
"'condition'",
"=>",
"'type=:type'",
",",
"'params'",
"=>",
"array",
"(",
"':type'",
"=>",
"$",
"type",
")",
",",
"'order'",
"=>",
"'position'",
",",
")",
")",
";",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"self",
"::",
"$",
"_items",
"[",
"$",
"type",
"]",
"[",
"$",
"model",
"->",
"code",
"]",
"=",
"$",
"model",
"->",
"name",
";",
"}"
] |
Loads the lookup items for the specified type from the database.
@param string the item type
|
[
"Loads",
"the",
"lookup",
"items",
"for",
"the",
"specified",
"type",
"from",
"the",
"database",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/demos/blog/protected/models/Lookup.php#L63-L73
|
train
|
yiisoft/yii
|
framework/caching/dependencies/CCacheDependency.php
|
CCacheDependency.getHash
|
private function getHash()
{
if($this->_hash===null)
$this->_hash=sha1(serialize($this));
return $this->_hash;
}
|
php
|
private function getHash()
{
if($this->_hash===null)
$this->_hash=sha1(serialize($this));
return $this->_hash;
}
|
[
"private",
"function",
"getHash",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_hash",
"===",
"null",
")",
"$",
"this",
"->",
"_hash",
"=",
"sha1",
"(",
"serialize",
"(",
"$",
"this",
")",
")",
";",
"return",
"$",
"this",
"->",
"_hash",
";",
"}"
] |
Generates a unique hash that identifies this cache dependency.
@return string the hash for this cache dependency
|
[
"Generates",
"a",
"unique",
"hash",
"that",
"identifies",
"this",
"cache",
"dependency",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/caching/dependencies/CCacheDependency.php#L111-L116
|
train
|
yiisoft/yii
|
framework/web/form/CForm.php
|
CForm.submitted
|
public function submitted($buttonName='submit',$loadData=true)
{
$ret=$this->clicked($this->getUniqueId()) && $this->clicked($buttonName);
if($ret && $loadData)
$this->loadData();
return $ret;
}
|
php
|
public function submitted($buttonName='submit',$loadData=true)
{
$ret=$this->clicked($this->getUniqueId()) && $this->clicked($buttonName);
if($ret && $loadData)
$this->loadData();
return $ret;
}
|
[
"public",
"function",
"submitted",
"(",
"$",
"buttonName",
"=",
"'submit'",
",",
"$",
"loadData",
"=",
"true",
")",
"{",
"$",
"ret",
"=",
"$",
"this",
"->",
"clicked",
"(",
"$",
"this",
"->",
"getUniqueId",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"clicked",
"(",
"$",
"buttonName",
")",
";",
"if",
"(",
"$",
"ret",
"&&",
"$",
"loadData",
")",
"$",
"this",
"->",
"loadData",
"(",
")",
";",
"return",
"$",
"ret",
";",
"}"
] |
Returns a value indicating whether this form is submitted.
@param string $buttonName the name of the submit button
@param boolean $loadData whether to call {@link loadData} if the form is submitted so that
the submitted data can be populated to the associated models.
@return boolean whether this form is submitted.
@see loadData
|
[
"Returns",
"a",
"value",
"indicating",
"whether",
"this",
"form",
"is",
"submitted",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/form/CForm.php#L202-L208
|
train
|
yiisoft/yii
|
framework/web/form/CForm.php
|
CForm.clicked
|
public function clicked($name)
{
if(strcasecmp($this->getRoot()->method,'get'))
return isset($_POST[$name]);
else
return isset($_GET[$name]);
}
|
php
|
public function clicked($name)
{
if(strcasecmp($this->getRoot()->method,'get'))
return isset($_POST[$name]);
else
return isset($_GET[$name]);
}
|
[
"public",
"function",
"clicked",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"strcasecmp",
"(",
"$",
"this",
"->",
"getRoot",
"(",
")",
"->",
"method",
",",
"'get'",
")",
")",
"return",
"isset",
"(",
"$",
"_POST",
"[",
"$",
"name",
"]",
")",
";",
"else",
"return",
"isset",
"(",
"$",
"_GET",
"[",
"$",
"name",
"]",
")",
";",
"}"
] |
Returns a value indicating whether the specified button is clicked.
@param string $name the button name
@return boolean whether the button is clicked.
|
[
"Returns",
"a",
"value",
"indicating",
"whether",
"the",
"specified",
"button",
"is",
"clicked",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/form/CForm.php#L215-L221
|
train
|
yiisoft/yii
|
framework/web/form/CForm.php
|
CForm.getModel
|
public function getModel($checkParent=true)
{
if(!$checkParent)
return $this->_model;
$form=$this;
while($form->_model===null && $form->getParent() instanceof self)
$form=$form->getParent();
return $form->_model;
}
|
php
|
public function getModel($checkParent=true)
{
if(!$checkParent)
return $this->_model;
$form=$this;
while($form->_model===null && $form->getParent() instanceof self)
$form=$form->getParent();
return $form->_model;
}
|
[
"public",
"function",
"getModel",
"(",
"$",
"checkParent",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"checkParent",
")",
"return",
"$",
"this",
"->",
"_model",
";",
"$",
"form",
"=",
"$",
"this",
";",
"while",
"(",
"$",
"form",
"->",
"_model",
"===",
"null",
"&&",
"$",
"form",
"->",
"getParent",
"(",
")",
"instanceof",
"self",
")",
"$",
"form",
"=",
"$",
"form",
"->",
"getParent",
"(",
")",
";",
"return",
"$",
"form",
"->",
"_model",
";",
"}"
] |
Returns the model that this form is associated with.
@param boolean $checkParent whether to return parent's model if this form doesn't have model by itself.
@return CModel the model associated with this form. If this form does not have a model,
it will look for a model in its ancestors.
|
[
"Returns",
"the",
"model",
"that",
"this",
"form",
"is",
"associated",
"with",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/form/CForm.php#L306-L314
|
train
|
yiisoft/yii
|
framework/web/form/CForm.php
|
CForm.getModels
|
public function getModels()
{
$models=array();
if($this->_model!==null)
$models[]=$this->_model;
foreach($this->getElements() as $element)
{
if($element instanceof self)
$models=array_merge($models,$element->getModels());
}
return $models;
}
|
php
|
public function getModels()
{
$models=array();
if($this->_model!==null)
$models[]=$this->_model;
foreach($this->getElements() as $element)
{
if($element instanceof self)
$models=array_merge($models,$element->getModels());
}
return $models;
}
|
[
"public",
"function",
"getModels",
"(",
")",
"{",
"$",
"models",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_model",
"!==",
"null",
")",
"$",
"models",
"[",
"]",
"=",
"$",
"this",
"->",
"_model",
";",
"foreach",
"(",
"$",
"this",
"->",
"getElements",
"(",
")",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"instanceof",
"self",
")",
"$",
"models",
"=",
"array_merge",
"(",
"$",
"models",
",",
"$",
"element",
"->",
"getModels",
"(",
")",
")",
";",
"}",
"return",
"$",
"models",
";",
"}"
] |
Returns all models that are associated with this form or its sub-forms.
@return array the models that are associated with this form or its sub-forms.
|
[
"Returns",
"all",
"models",
"that",
"are",
"associated",
"with",
"this",
"form",
"or",
"its",
"sub",
"-",
"forms",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/form/CForm.php#L328-L339
|
train
|
yiisoft/yii
|
framework/web/form/CForm.php
|
CForm.getUniqueId
|
protected function getUniqueId()
{
if(isset($this->attributes['id']))
return 'yform_'.$this->attributes['id'];
else
return 'yform_'.sprintf('%x',crc32(serialize(array_keys($this->getElements()->toArray()))));
}
|
php
|
protected function getUniqueId()
{
if(isset($this->attributes['id']))
return 'yform_'.$this->attributes['id'];
else
return 'yform_'.sprintf('%x',crc32(serialize(array_keys($this->getElements()->toArray()))));
}
|
[
"protected",
"function",
"getUniqueId",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'id'",
"]",
")",
")",
"return",
"'yform_'",
".",
"$",
"this",
"->",
"attributes",
"[",
"'id'",
"]",
";",
"else",
"return",
"'yform_'",
".",
"sprintf",
"(",
"'%x'",
",",
"crc32",
"(",
"serialize",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getElements",
"(",
")",
"->",
"toArray",
"(",
")",
")",
")",
")",
")",
";",
"}"
] |
Returns a unique ID that identifies this form in the current page.
@return string the unique ID identifying this form
|
[
"Returns",
"a",
"unique",
"ID",
"that",
"identifies",
"this",
"form",
"in",
"the",
"current",
"page",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/form/CForm.php#L593-L599
|
train
|
yiisoft/yii
|
framework/validators/CUrlValidator.php
|
CUrlValidator.encodeIDN
|
private function encodeIDN($value)
{
if(preg_match_all('/^(.*):\/\/([^\/]+)(.*)$/',$value,$matches))
{
if(function_exists('idn_to_ascii'))
$value=$matches[1][0].'://'.idn_to_ascii($matches[2][0]).$matches[3][0];
else
{
require_once(Yii::getPathOfAlias('system.vendors.Net_IDNA2.Net').DIRECTORY_SEPARATOR.'IDNA2.php');
$idna=new Net_IDNA2();
$value=$matches[1][0].'://'.@$idna->encode($matches[2][0]).$matches[3][0];
}
}
return $value;
}
|
php
|
private function encodeIDN($value)
{
if(preg_match_all('/^(.*):\/\/([^\/]+)(.*)$/',$value,$matches))
{
if(function_exists('idn_to_ascii'))
$value=$matches[1][0].'://'.idn_to_ascii($matches[2][0]).$matches[3][0];
else
{
require_once(Yii::getPathOfAlias('system.vendors.Net_IDNA2.Net').DIRECTORY_SEPARATOR.'IDNA2.php');
$idna=new Net_IDNA2();
$value=$matches[1][0].'://'.@$idna->encode($matches[2][0]).$matches[3][0];
}
}
return $value;
}
|
[
"private",
"function",
"encodeIDN",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"preg_match_all",
"(",
"'/^(.*):\\/\\/([^\\/]+)(.*)$/'",
",",
"$",
"value",
",",
"$",
"matches",
")",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'idn_to_ascii'",
")",
")",
"$",
"value",
"=",
"$",
"matches",
"[",
"1",
"]",
"[",
"0",
"]",
".",
"'://'",
".",
"idn_to_ascii",
"(",
"$",
"matches",
"[",
"2",
"]",
"[",
"0",
"]",
")",
".",
"$",
"matches",
"[",
"3",
"]",
"[",
"0",
"]",
";",
"else",
"{",
"require_once",
"(",
"Yii",
"::",
"getPathOfAlias",
"(",
"'system.vendors.Net_IDNA2.Net'",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'IDNA2.php'",
")",
";",
"$",
"idna",
"=",
"new",
"Net_IDNA2",
"(",
")",
";",
"$",
"value",
"=",
"$",
"matches",
"[",
"1",
"]",
"[",
"0",
"]",
".",
"'://'",
".",
"@",
"$",
"idna",
"->",
"encode",
"(",
"$",
"matches",
"[",
"2",
"]",
"[",
"0",
"]",
")",
".",
"$",
"matches",
"[",
"3",
"]",
"[",
"0",
"]",
";",
"}",
"}",
"return",
"$",
"value",
";",
"}"
] |
Converts given IDN to the punycode.
@param string $value IDN to be converted.
@return string resulting punycode.
@since 1.1.13
|
[
"Converts",
"given",
"IDN",
"to",
"the",
"punycode",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/validators/CUrlValidator.php#L167-L181
|
train
|
yiisoft/yii
|
framework/validators/CUrlValidator.php
|
CUrlValidator.decodeIDN
|
private function decodeIDN($value)
{
if(preg_match_all('/^(.*):\/\/([^\/]+)(.*)$/',$value,$matches))
{
if(function_exists('idn_to_utf8'))
$value=$matches[1][0].'://'.idn_to_utf8($matches[2][0]).$matches[3][0];
else
{
require_once(Yii::getPathOfAlias('system.vendors.Net_IDNA2.Net').DIRECTORY_SEPARATOR.'IDNA2.php');
$idna=new Net_IDNA2();
$value=$matches[1][0].'://'.@$idna->decode($matches[2][0]).$matches[3][0];
}
}
return $value;
}
|
php
|
private function decodeIDN($value)
{
if(preg_match_all('/^(.*):\/\/([^\/]+)(.*)$/',$value,$matches))
{
if(function_exists('idn_to_utf8'))
$value=$matches[1][0].'://'.idn_to_utf8($matches[2][0]).$matches[3][0];
else
{
require_once(Yii::getPathOfAlias('system.vendors.Net_IDNA2.Net').DIRECTORY_SEPARATOR.'IDNA2.php');
$idna=new Net_IDNA2();
$value=$matches[1][0].'://'.@$idna->decode($matches[2][0]).$matches[3][0];
}
}
return $value;
}
|
[
"private",
"function",
"decodeIDN",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"preg_match_all",
"(",
"'/^(.*):\\/\\/([^\\/]+)(.*)$/'",
",",
"$",
"value",
",",
"$",
"matches",
")",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'idn_to_utf8'",
")",
")",
"$",
"value",
"=",
"$",
"matches",
"[",
"1",
"]",
"[",
"0",
"]",
".",
"'://'",
".",
"idn_to_utf8",
"(",
"$",
"matches",
"[",
"2",
"]",
"[",
"0",
"]",
")",
".",
"$",
"matches",
"[",
"3",
"]",
"[",
"0",
"]",
";",
"else",
"{",
"require_once",
"(",
"Yii",
"::",
"getPathOfAlias",
"(",
"'system.vendors.Net_IDNA2.Net'",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'IDNA2.php'",
")",
";",
"$",
"idna",
"=",
"new",
"Net_IDNA2",
"(",
")",
";",
"$",
"value",
"=",
"$",
"matches",
"[",
"1",
"]",
"[",
"0",
"]",
".",
"'://'",
".",
"@",
"$",
"idna",
"->",
"decode",
"(",
"$",
"matches",
"[",
"2",
"]",
"[",
"0",
"]",
")",
".",
"$",
"matches",
"[",
"3",
"]",
"[",
"0",
"]",
";",
"}",
"}",
"return",
"$",
"value",
";",
"}"
] |
Converts given punycode to the IDN.
@param string $value punycode to be converted.
@return string resulting IDN.
@since 1.1.13
|
[
"Converts",
"given",
"punycode",
"to",
"the",
"IDN",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/validators/CUrlValidator.php#L189-L203
|
train
|
yiisoft/yii
|
framework/zii/widgets/CMenu.php
|
CMenu.renderMenu
|
protected function renderMenu($items)
{
if(count($items))
{
echo CHtml::openTag('ul',$this->htmlOptions)."\n";
$this->renderMenuRecursive($items);
echo CHtml::closeTag('ul');
}
}
|
php
|
protected function renderMenu($items)
{
if(count($items))
{
echo CHtml::openTag('ul',$this->htmlOptions)."\n";
$this->renderMenuRecursive($items);
echo CHtml::closeTag('ul');
}
}
|
[
"protected",
"function",
"renderMenu",
"(",
"$",
"items",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"items",
")",
")",
"{",
"echo",
"CHtml",
"::",
"openTag",
"(",
"'ul'",
",",
"$",
"this",
"->",
"htmlOptions",
")",
".",
"\"\\n\"",
";",
"$",
"this",
"->",
"renderMenuRecursive",
"(",
"$",
"items",
")",
";",
"echo",
"CHtml",
"::",
"closeTag",
"(",
"'ul'",
")",
";",
"}",
"}"
] |
Renders the menu items.
@param array $items menu items. Each menu item will be an array with at least two elements: 'label' and 'active'.
It may have three other optional elements: 'items', 'linkOptions' and 'itemOptions'.
|
[
"Renders",
"the",
"menu",
"items",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/zii/widgets/CMenu.php#L177-L185
|
train
|
yiisoft/yii
|
framework/zii/widgets/CMenu.php
|
CMenu.renderMenuRecursive
|
protected function renderMenuRecursive($items)
{
$count=0;
$n=count($items);
foreach($items as $item)
{
$count++;
$options=isset($item['itemOptions']) ? $item['itemOptions'] : array();
$class=array();
if($item['active'] && $this->activeCssClass!='')
$class[]=$this->activeCssClass;
if($count===1 && $this->firstItemCssClass!==null)
$class[]=$this->firstItemCssClass;
if($count===$n && $this->lastItemCssClass!==null)
$class[]=$this->lastItemCssClass;
if($this->itemCssClass!==null)
$class[]=$this->itemCssClass;
if($class!==array())
{
if(empty($options['class']))
$options['class']=implode(' ',$class);
else
$options['class'].=' '.implode(' ',$class);
}
echo CHtml::openTag('li', $options);
$menu=$this->renderMenuItem($item);
if(isset($this->itemTemplate) || isset($item['template']))
{
$template=isset($item['template']) ? $item['template'] : $this->itemTemplate;
echo strtr($template,array('{menu}'=>$menu));
}
else
echo $menu;
if(isset($item['items']) && count($item['items']))
{
echo "\n".CHtml::openTag('ul',isset($item['submenuOptions']) ? $item['submenuOptions'] : $this->submenuHtmlOptions)."\n";
$this->renderMenuRecursive($item['items']);
echo CHtml::closeTag('ul')."\n";
}
echo CHtml::closeTag('li')."\n";
}
}
|
php
|
protected function renderMenuRecursive($items)
{
$count=0;
$n=count($items);
foreach($items as $item)
{
$count++;
$options=isset($item['itemOptions']) ? $item['itemOptions'] : array();
$class=array();
if($item['active'] && $this->activeCssClass!='')
$class[]=$this->activeCssClass;
if($count===1 && $this->firstItemCssClass!==null)
$class[]=$this->firstItemCssClass;
if($count===$n && $this->lastItemCssClass!==null)
$class[]=$this->lastItemCssClass;
if($this->itemCssClass!==null)
$class[]=$this->itemCssClass;
if($class!==array())
{
if(empty($options['class']))
$options['class']=implode(' ',$class);
else
$options['class'].=' '.implode(' ',$class);
}
echo CHtml::openTag('li', $options);
$menu=$this->renderMenuItem($item);
if(isset($this->itemTemplate) || isset($item['template']))
{
$template=isset($item['template']) ? $item['template'] : $this->itemTemplate;
echo strtr($template,array('{menu}'=>$menu));
}
else
echo $menu;
if(isset($item['items']) && count($item['items']))
{
echo "\n".CHtml::openTag('ul',isset($item['submenuOptions']) ? $item['submenuOptions'] : $this->submenuHtmlOptions)."\n";
$this->renderMenuRecursive($item['items']);
echo CHtml::closeTag('ul')."\n";
}
echo CHtml::closeTag('li')."\n";
}
}
|
[
"protected",
"function",
"renderMenuRecursive",
"(",
"$",
"items",
")",
"{",
"$",
"count",
"=",
"0",
";",
"$",
"n",
"=",
"count",
"(",
"$",
"items",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"count",
"++",
";",
"$",
"options",
"=",
"isset",
"(",
"$",
"item",
"[",
"'itemOptions'",
"]",
")",
"?",
"$",
"item",
"[",
"'itemOptions'",
"]",
":",
"array",
"(",
")",
";",
"$",
"class",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"item",
"[",
"'active'",
"]",
"&&",
"$",
"this",
"->",
"activeCssClass",
"!=",
"''",
")",
"$",
"class",
"[",
"]",
"=",
"$",
"this",
"->",
"activeCssClass",
";",
"if",
"(",
"$",
"count",
"===",
"1",
"&&",
"$",
"this",
"->",
"firstItemCssClass",
"!==",
"null",
")",
"$",
"class",
"[",
"]",
"=",
"$",
"this",
"->",
"firstItemCssClass",
";",
"if",
"(",
"$",
"count",
"===",
"$",
"n",
"&&",
"$",
"this",
"->",
"lastItemCssClass",
"!==",
"null",
")",
"$",
"class",
"[",
"]",
"=",
"$",
"this",
"->",
"lastItemCssClass",
";",
"if",
"(",
"$",
"this",
"->",
"itemCssClass",
"!==",
"null",
")",
"$",
"class",
"[",
"]",
"=",
"$",
"this",
"->",
"itemCssClass",
";",
"if",
"(",
"$",
"class",
"!==",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'class'",
"]",
")",
")",
"$",
"options",
"[",
"'class'",
"]",
"=",
"implode",
"(",
"' '",
",",
"$",
"class",
")",
";",
"else",
"$",
"options",
"[",
"'class'",
"]",
".=",
"' '",
".",
"implode",
"(",
"' '",
",",
"$",
"class",
")",
";",
"}",
"echo",
"CHtml",
"::",
"openTag",
"(",
"'li'",
",",
"$",
"options",
")",
";",
"$",
"menu",
"=",
"$",
"this",
"->",
"renderMenuItem",
"(",
"$",
"item",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"itemTemplate",
")",
"||",
"isset",
"(",
"$",
"item",
"[",
"'template'",
"]",
")",
")",
"{",
"$",
"template",
"=",
"isset",
"(",
"$",
"item",
"[",
"'template'",
"]",
")",
"?",
"$",
"item",
"[",
"'template'",
"]",
":",
"$",
"this",
"->",
"itemTemplate",
";",
"echo",
"strtr",
"(",
"$",
"template",
",",
"array",
"(",
"'{menu}'",
"=>",
"$",
"menu",
")",
")",
";",
"}",
"else",
"echo",
"$",
"menu",
";",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'items'",
"]",
")",
"&&",
"count",
"(",
"$",
"item",
"[",
"'items'",
"]",
")",
")",
"{",
"echo",
"\"\\n\"",
".",
"CHtml",
"::",
"openTag",
"(",
"'ul'",
",",
"isset",
"(",
"$",
"item",
"[",
"'submenuOptions'",
"]",
")",
"?",
"$",
"item",
"[",
"'submenuOptions'",
"]",
":",
"$",
"this",
"->",
"submenuHtmlOptions",
")",
".",
"\"\\n\"",
";",
"$",
"this",
"->",
"renderMenuRecursive",
"(",
"$",
"item",
"[",
"'items'",
"]",
")",
";",
"echo",
"CHtml",
"::",
"closeTag",
"(",
"'ul'",
")",
".",
"\"\\n\"",
";",
"}",
"echo",
"CHtml",
"::",
"closeTag",
"(",
"'li'",
")",
".",
"\"\\n\"",
";",
"}",
"}"
] |
Recursively renders the menu items.
@param array $items the menu items to be rendered recursively
|
[
"Recursively",
"renders",
"the",
"menu",
"items",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/zii/widgets/CMenu.php#L191-L236
|
train
|
yiisoft/yii
|
framework/db/schema/mysql/CMysqlCommandBuilder.php
|
CMysqlCommandBuilder.applyJoin
|
public function applyJoin($sql,$join)
{
if($join=='')
return $sql;
if(strpos($sql,'UPDATE')===0 && ($pos=strpos($sql,'SET'))!==false)
return substr($sql,0,$pos).$join.' '.substr($sql,$pos);
elseif(strpos($sql,'DELETE FROM ')===0)
{
$tableName=substr($sql,12);
return "DELETE {$tableName} FROM {$tableName} ".$join;
}
else
return $sql.' '.$join;
}
|
php
|
public function applyJoin($sql,$join)
{
if($join=='')
return $sql;
if(strpos($sql,'UPDATE')===0 && ($pos=strpos($sql,'SET'))!==false)
return substr($sql,0,$pos).$join.' '.substr($sql,$pos);
elseif(strpos($sql,'DELETE FROM ')===0)
{
$tableName=substr($sql,12);
return "DELETE {$tableName} FROM {$tableName} ".$join;
}
else
return $sql.' '.$join;
}
|
[
"public",
"function",
"applyJoin",
"(",
"$",
"sql",
",",
"$",
"join",
")",
"{",
"if",
"(",
"$",
"join",
"==",
"''",
")",
"return",
"$",
"sql",
";",
"if",
"(",
"strpos",
"(",
"$",
"sql",
",",
"'UPDATE'",
")",
"===",
"0",
"&&",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"sql",
",",
"'SET'",
")",
")",
"!==",
"false",
")",
"return",
"substr",
"(",
"$",
"sql",
",",
"0",
",",
"$",
"pos",
")",
".",
"$",
"join",
".",
"' '",
".",
"substr",
"(",
"$",
"sql",
",",
"$",
"pos",
")",
";",
"elseif",
"(",
"strpos",
"(",
"$",
"sql",
",",
"'DELETE FROM '",
")",
"===",
"0",
")",
"{",
"$",
"tableName",
"=",
"substr",
"(",
"$",
"sql",
",",
"12",
")",
";",
"return",
"\"DELETE {$tableName} FROM {$tableName} \"",
".",
"$",
"join",
";",
"}",
"else",
"return",
"$",
"sql",
".",
"' '",
".",
"$",
"join",
";",
"}"
] |
Alters the SQL to apply JOIN clause.
This method handles the mysql specific syntax where JOIN has to come before SET in UPDATE statement
and for DELETE where JOIN has to be after FROM part.
@param string $sql the SQL statement to be altered
@param string $join the JOIN clause (starting with join type, such as INNER JOIN)
@return string the altered SQL statement
|
[
"Alters",
"the",
"SQL",
"to",
"apply",
"JOIN",
"clause",
".",
"This",
"method",
"handles",
"the",
"mysql",
"specific",
"syntax",
"where",
"JOIN",
"has",
"to",
"come",
"before",
"SET",
"in",
"UPDATE",
"statement",
"and",
"for",
"DELETE",
"where",
"JOIN",
"has",
"to",
"be",
"after",
"FROM",
"part",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/mysql/CMysqlCommandBuilder.php#L28-L42
|
train
|
yiisoft/yii
|
framework/validators/CDefaultValueValidator.php
|
CDefaultValueValidator.validateAttribute
|
protected function validateAttribute($object,$attribute)
{
if(!$this->setOnEmpty)
$object->$attribute=$this->value;
else
{
$value=$object->$attribute;
if($value===null || $value==='')
$object->$attribute=$this->value;
}
}
|
php
|
protected function validateAttribute($object,$attribute)
{
if(!$this->setOnEmpty)
$object->$attribute=$this->value;
else
{
$value=$object->$attribute;
if($value===null || $value==='')
$object->$attribute=$this->value;
}
}
|
[
"protected",
"function",
"validateAttribute",
"(",
"$",
"object",
",",
"$",
"attribute",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"setOnEmpty",
")",
"$",
"object",
"->",
"$",
"attribute",
"=",
"$",
"this",
"->",
"value",
";",
"else",
"{",
"$",
"value",
"=",
"$",
"object",
"->",
"$",
"attribute",
";",
"if",
"(",
"$",
"value",
"===",
"null",
"||",
"$",
"value",
"===",
"''",
")",
"$",
"object",
"->",
"$",
"attribute",
"=",
"$",
"this",
"->",
"value",
";",
"}",
"}"
] |
Validates the attribute of the object.
@param CModel $object the object being validated
@param string $attribute the attribute being validated
|
[
"Validates",
"the",
"attribute",
"of",
"the",
"object",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/validators/CDefaultValueValidator.php#L38-L48
|
train
|
yiisoft/yii
|
framework/web/CActiveDataProvider.php
|
CActiveDataProvider.getSort
|
public function getSort($className='CSort')
{
if(($sort=parent::getSort($className))!==false)
$sort->modelClass=$this->modelClass;
return $sort;
}
|
php
|
public function getSort($className='CSort')
{
if(($sort=parent::getSort($className))!==false)
$sort->modelClass=$this->modelClass;
return $sort;
}
|
[
"public",
"function",
"getSort",
"(",
"$",
"className",
"=",
"'CSort'",
")",
"{",
"if",
"(",
"(",
"$",
"sort",
"=",
"parent",
"::",
"getSort",
"(",
"$",
"className",
")",
")",
"!==",
"false",
")",
"$",
"sort",
"->",
"modelClass",
"=",
"$",
"this",
"->",
"modelClass",
";",
"return",
"$",
"sort",
";",
"}"
] |
Returns the sorting object.
@param string $className the sorting object class name. Parameter is available since version 1.1.13.
@return CSort the sorting object. If this is false, it means the sorting is disabled.
|
[
"Returns",
"the",
"sorting",
"object",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CActiveDataProvider.php#L148-L153
|
train
|
yiisoft/yii
|
framework/web/CActiveDataProvider.php
|
CActiveDataProvider.calculateTotalItemCount
|
protected function calculateTotalItemCount()
{
$baseCriteria=$this->model->getDbCriteria(false);
if($baseCriteria!==null)
$baseCriteria=clone $baseCriteria;
$count=$this->model->count($this->getCountCriteria());
$this->model->setDbCriteria($baseCriteria);
return $count;
}
|
php
|
protected function calculateTotalItemCount()
{
$baseCriteria=$this->model->getDbCriteria(false);
if($baseCriteria!==null)
$baseCriteria=clone $baseCriteria;
$count=$this->model->count($this->getCountCriteria());
$this->model->setDbCriteria($baseCriteria);
return $count;
}
|
[
"protected",
"function",
"calculateTotalItemCount",
"(",
")",
"{",
"$",
"baseCriteria",
"=",
"$",
"this",
"->",
"model",
"->",
"getDbCriteria",
"(",
"false",
")",
";",
"if",
"(",
"$",
"baseCriteria",
"!==",
"null",
")",
"$",
"baseCriteria",
"=",
"clone",
"$",
"baseCriteria",
";",
"$",
"count",
"=",
"$",
"this",
"->",
"model",
"->",
"count",
"(",
"$",
"this",
"->",
"getCountCriteria",
"(",
")",
")",
";",
"$",
"this",
"->",
"model",
"->",
"setDbCriteria",
"(",
"$",
"baseCriteria",
")",
";",
"return",
"$",
"count",
";",
"}"
] |
Calculates the total number of data items.
@return integer the total number of data items.
|
[
"Calculates",
"the",
"total",
"number",
"of",
"data",
"items",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CActiveDataProvider.php#L223-L231
|
train
|
yiisoft/yii
|
framework/console/CConsoleCommandRunner.php
|
CConsoleCommandRunner.run
|
public function run($args)
{
$this->_scriptName=$args[0];
array_shift($args);
if(isset($args[0]))
{
$name=$args[0];
array_shift($args);
}
else
$name='help';
$oldCommand=$this->_command;
if(($command=$this->createCommand($name))===null)
$command=$this->createCommand('help');
$this->_command=$command;
$command->init();
$exitCode=$command->run($args);
$this->_command=$oldCommand;
return $exitCode;
}
|
php
|
public function run($args)
{
$this->_scriptName=$args[0];
array_shift($args);
if(isset($args[0]))
{
$name=$args[0];
array_shift($args);
}
else
$name='help';
$oldCommand=$this->_command;
if(($command=$this->createCommand($name))===null)
$command=$this->createCommand('help');
$this->_command=$command;
$command->init();
$exitCode=$command->run($args);
$this->_command=$oldCommand;
return $exitCode;
}
|
[
"public",
"function",
"run",
"(",
"$",
"args",
")",
"{",
"$",
"this",
"->",
"_scriptName",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"array_shift",
"(",
"$",
"args",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
"{",
"$",
"name",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"array_shift",
"(",
"$",
"args",
")",
";",
"}",
"else",
"$",
"name",
"=",
"'help'",
";",
"$",
"oldCommand",
"=",
"$",
"this",
"->",
"_command",
";",
"if",
"(",
"(",
"$",
"command",
"=",
"$",
"this",
"->",
"createCommand",
"(",
"$",
"name",
")",
")",
"===",
"null",
")",
"$",
"command",
"=",
"$",
"this",
"->",
"createCommand",
"(",
"'help'",
")",
";",
"$",
"this",
"->",
"_command",
"=",
"$",
"command",
";",
"$",
"command",
"->",
"init",
"(",
")",
";",
"$",
"exitCode",
"=",
"$",
"command",
"->",
"run",
"(",
"$",
"args",
")",
";",
"$",
"this",
"->",
"_command",
"=",
"$",
"oldCommand",
";",
"return",
"$",
"exitCode",
";",
"}"
] |
Executes the requested command.
@param array $args list of user supplied parameters (including the entry script name and the command name).
@return integer|null application exit code returned by the command.
if null is returned, application will not exit explicitly. See also {@link CConsoleApplication::processRequest()}.
(return value is available since version 1.1.11)
|
[
"Executes",
"the",
"requested",
"command",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/console/CConsoleCommandRunner.php#L54-L74
|
train
|
yiisoft/yii
|
framework/console/CConsoleCommandRunner.php
|
CConsoleCommandRunner.findCommands
|
public function findCommands($path)
{
if(($dir=@opendir($path))===false)
return array();
$commands=array();
while(($name=readdir($dir))!==false)
{
$file=$path.DIRECTORY_SEPARATOR.$name;
if(!strcasecmp(substr($name,-11),'Command.php') && is_file($file))
$commands[strtolower(substr($name,0,-11))]=$file;
}
closedir($dir);
return $commands;
}
|
php
|
public function findCommands($path)
{
if(($dir=@opendir($path))===false)
return array();
$commands=array();
while(($name=readdir($dir))!==false)
{
$file=$path.DIRECTORY_SEPARATOR.$name;
if(!strcasecmp(substr($name,-11),'Command.php') && is_file($file))
$commands[strtolower(substr($name,0,-11))]=$file;
}
closedir($dir);
return $commands;
}
|
[
"public",
"function",
"findCommands",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"(",
"$",
"dir",
"=",
"@",
"opendir",
"(",
"$",
"path",
")",
")",
"===",
"false",
")",
"return",
"array",
"(",
")",
";",
"$",
"commands",
"=",
"array",
"(",
")",
";",
"while",
"(",
"(",
"$",
"name",
"=",
"readdir",
"(",
"$",
"dir",
")",
")",
"!==",
"false",
")",
"{",
"$",
"file",
"=",
"$",
"path",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"name",
";",
"if",
"(",
"!",
"strcasecmp",
"(",
"substr",
"(",
"$",
"name",
",",
"-",
"11",
")",
",",
"'Command.php'",
")",
"&&",
"is_file",
"(",
"$",
"file",
")",
")",
"$",
"commands",
"[",
"strtolower",
"(",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"-",
"11",
")",
")",
"]",
"=",
"$",
"file",
";",
"}",
"closedir",
"(",
"$",
"dir",
")",
";",
"return",
"$",
"commands",
";",
"}"
] |
Searches for commands under the specified directory.
@param string $path the directory containing the command class files.
@return array list of commands (command name=>command class file)
|
[
"Searches",
"for",
"commands",
"under",
"the",
"specified",
"directory",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/console/CConsoleCommandRunner.php#L108-L121
|
train
|
yiisoft/yii
|
framework/console/CConsoleCommandRunner.php
|
CConsoleCommandRunner.addCommands
|
public function addCommands($path)
{
if(($commands=$this->findCommands($path))!==array())
{
foreach($commands as $name=>$file)
{
if(!isset($this->commands[$name]))
$this->commands[$name]=$file;
}
}
}
|
php
|
public function addCommands($path)
{
if(($commands=$this->findCommands($path))!==array())
{
foreach($commands as $name=>$file)
{
if(!isset($this->commands[$name]))
$this->commands[$name]=$file;
}
}
}
|
[
"public",
"function",
"addCommands",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"(",
"$",
"commands",
"=",
"$",
"this",
"->",
"findCommands",
"(",
"$",
"path",
")",
")",
"!==",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"commands",
"as",
"$",
"name",
"=>",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"commands",
"[",
"$",
"name",
"]",
")",
")",
"$",
"this",
"->",
"commands",
"[",
"$",
"name",
"]",
"=",
"$",
"file",
";",
"}",
"}",
"}"
] |
Adds commands from the specified command path.
If a command already exists, the new one will be ignored.
@param string $path the alias of the directory containing the command class files.
|
[
"Adds",
"commands",
"from",
"the",
"specified",
"command",
"path",
".",
"If",
"a",
"command",
"already",
"exists",
"the",
"new",
"one",
"will",
"be",
"ignored",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/console/CConsoleCommandRunner.php#L128-L138
|
train
|
yiisoft/yii
|
framework/zii/widgets/jui/CJuiDialog.php
|
CJuiDialog.init
|
public function init()
{
parent::init();
$id=$this->getId();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
$options=CJavaScript::encode($this->options);
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').dialog($options);");
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
}
|
php
|
public function init()
{
parent::init();
$id=$this->getId();
if(isset($this->htmlOptions['id']))
$id=$this->htmlOptions['id'];
else
$this->htmlOptions['id']=$id;
$options=CJavaScript::encode($this->options);
Yii::app()->getClientScript()->registerScript(__CLASS__.'#'.$id,"jQuery('#{$id}').dialog($options);");
echo CHtml::openTag($this->tagName,$this->htmlOptions)."\n";
}
|
[
"public",
"function",
"init",
"(",
")",
"{",
"parent",
"::",
"init",
"(",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"getId",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"htmlOptions",
"[",
"'id'",
"]",
")",
")",
"$",
"id",
"=",
"$",
"this",
"->",
"htmlOptions",
"[",
"'id'",
"]",
";",
"else",
"$",
"this",
"->",
"htmlOptions",
"[",
"'id'",
"]",
"=",
"$",
"id",
";",
"$",
"options",
"=",
"CJavaScript",
"::",
"encode",
"(",
"$",
"this",
"->",
"options",
")",
";",
"Yii",
"::",
"app",
"(",
")",
"->",
"getClientScript",
"(",
")",
"->",
"registerScript",
"(",
"__CLASS__",
".",
"'#'",
".",
"$",
"id",
",",
"\"jQuery('#{$id}').dialog($options);\"",
")",
";",
"echo",
"CHtml",
"::",
"openTag",
"(",
"$",
"this",
"->",
"tagName",
",",
"$",
"this",
"->",
"htmlOptions",
")",
".",
"\"\\n\"",
";",
"}"
] |
Renders the open tag of the dialog.
This method also registers the necessary javascript code.
|
[
"Renders",
"the",
"open",
"tag",
"of",
"the",
"dialog",
".",
"This",
"method",
"also",
"registers",
"the",
"necessary",
"javascript",
"code",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/zii/widgets/jui/CJuiDialog.php#L62-L76
|
train
|
yiisoft/yii
|
framework/db/schema/CDbCommandBuilder.php
|
CDbCommandBuilder.getLastInsertID
|
public function getLastInsertID($table)
{
$this->ensureTable($table);
if($table->sequenceName!==null)
return $this->_connection->getLastInsertID($table->sequenceName);
else
return null;
}
|
php
|
public function getLastInsertID($table)
{
$this->ensureTable($table);
if($table->sequenceName!==null)
return $this->_connection->getLastInsertID($table->sequenceName);
else
return null;
}
|
[
"public",
"function",
"getLastInsertID",
"(",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"ensureTable",
"(",
"$",
"table",
")",
";",
"if",
"(",
"$",
"table",
"->",
"sequenceName",
"!==",
"null",
")",
"return",
"$",
"this",
"->",
"_connection",
"->",
"getLastInsertID",
"(",
"$",
"table",
"->",
"sequenceName",
")",
";",
"else",
"return",
"null",
";",
"}"
] |
Returns the last insertion ID for the specified table.
@param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
@return mixed last insertion id. Null is returned if no sequence name.
|
[
"Returns",
"the",
"last",
"insertion",
"ID",
"for",
"the",
"specified",
"table",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/CDbCommandBuilder.php#L58-L65
|
train
|
yiisoft/yii
|
framework/db/schema/CDbCommandBuilder.php
|
CDbCommandBuilder.createFindCommand
|
public function createFindCommand($table,$criteria,$alias='t')
{
$this->ensureTable($table);
$select=is_array($criteria->select) ? implode(', ',$criteria->select) : $criteria->select;
if($criteria->alias!='')
$alias=$criteria->alias;
$alias=$this->_schema->quoteTableName($alias);
// issue 1432: need to expand * when SQL has JOIN
if($select==='*' && !empty($criteria->join))
{
$prefix=$alias.'.';
$select=array();
foreach($table->getColumnNames() as $name)
$select[]=$prefix.$this->_schema->quoteColumnName($name);
$select=implode(', ',$select);
}
$sql=($criteria->distinct ? 'SELECT DISTINCT':'SELECT')." {$select} FROM {$table->rawName} $alias";
$sql=$this->applyJoin($sql,$criteria->join);
$sql=$this->applyCondition($sql,$criteria->condition);
$sql=$this->applyGroup($sql,$criteria->group);
$sql=$this->applyHaving($sql,$criteria->having);
$sql=$this->applyOrder($sql,$criteria->order);
$sql=$this->applyLimit($sql,$criteria->limit,$criteria->offset);
$command=$this->_connection->createCommand($sql);
$this->bindValues($command,$criteria->params);
return $command;
}
|
php
|
public function createFindCommand($table,$criteria,$alias='t')
{
$this->ensureTable($table);
$select=is_array($criteria->select) ? implode(', ',$criteria->select) : $criteria->select;
if($criteria->alias!='')
$alias=$criteria->alias;
$alias=$this->_schema->quoteTableName($alias);
// issue 1432: need to expand * when SQL has JOIN
if($select==='*' && !empty($criteria->join))
{
$prefix=$alias.'.';
$select=array();
foreach($table->getColumnNames() as $name)
$select[]=$prefix.$this->_schema->quoteColumnName($name);
$select=implode(', ',$select);
}
$sql=($criteria->distinct ? 'SELECT DISTINCT':'SELECT')." {$select} FROM {$table->rawName} $alias";
$sql=$this->applyJoin($sql,$criteria->join);
$sql=$this->applyCondition($sql,$criteria->condition);
$sql=$this->applyGroup($sql,$criteria->group);
$sql=$this->applyHaving($sql,$criteria->having);
$sql=$this->applyOrder($sql,$criteria->order);
$sql=$this->applyLimit($sql,$criteria->limit,$criteria->offset);
$command=$this->_connection->createCommand($sql);
$this->bindValues($command,$criteria->params);
return $command;
}
|
[
"public",
"function",
"createFindCommand",
"(",
"$",
"table",
",",
"$",
"criteria",
",",
"$",
"alias",
"=",
"'t'",
")",
"{",
"$",
"this",
"->",
"ensureTable",
"(",
"$",
"table",
")",
";",
"$",
"select",
"=",
"is_array",
"(",
"$",
"criteria",
"->",
"select",
")",
"?",
"implode",
"(",
"', '",
",",
"$",
"criteria",
"->",
"select",
")",
":",
"$",
"criteria",
"->",
"select",
";",
"if",
"(",
"$",
"criteria",
"->",
"alias",
"!=",
"''",
")",
"$",
"alias",
"=",
"$",
"criteria",
"->",
"alias",
";",
"$",
"alias",
"=",
"$",
"this",
"->",
"_schema",
"->",
"quoteTableName",
"(",
"$",
"alias",
")",
";",
"// issue 1432: need to expand * when SQL has JOIN",
"if",
"(",
"$",
"select",
"===",
"'*'",
"&&",
"!",
"empty",
"(",
"$",
"criteria",
"->",
"join",
")",
")",
"{",
"$",
"prefix",
"=",
"$",
"alias",
".",
"'.'",
";",
"$",
"select",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"table",
"->",
"getColumnNames",
"(",
")",
"as",
"$",
"name",
")",
"$",
"select",
"[",
"]",
"=",
"$",
"prefix",
".",
"$",
"this",
"->",
"_schema",
"->",
"quoteColumnName",
"(",
"$",
"name",
")",
";",
"$",
"select",
"=",
"implode",
"(",
"', '",
",",
"$",
"select",
")",
";",
"}",
"$",
"sql",
"=",
"(",
"$",
"criteria",
"->",
"distinct",
"?",
"'SELECT DISTINCT'",
":",
"'SELECT'",
")",
".",
"\" {$select} FROM {$table->rawName} $alias\"",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"applyJoin",
"(",
"$",
"sql",
",",
"$",
"criteria",
"->",
"join",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"applyCondition",
"(",
"$",
"sql",
",",
"$",
"criteria",
"->",
"condition",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"applyGroup",
"(",
"$",
"sql",
",",
"$",
"criteria",
"->",
"group",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"applyHaving",
"(",
"$",
"sql",
",",
"$",
"criteria",
"->",
"having",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"applyOrder",
"(",
"$",
"sql",
",",
"$",
"criteria",
"->",
"order",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"applyLimit",
"(",
"$",
"sql",
",",
"$",
"criteria",
"->",
"limit",
",",
"$",
"criteria",
"->",
"offset",
")",
";",
"$",
"command",
"=",
"$",
"this",
"->",
"_connection",
"->",
"createCommand",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"bindValues",
"(",
"$",
"command",
",",
"$",
"criteria",
"->",
"params",
")",
";",
"return",
"$",
"command",
";",
"}"
] |
Creates a SELECT command for a single table.
@param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
@param CDbCriteria $criteria the query criteria
@param string $alias the alias name of the primary table. Defaults to 't'.
@return CDbCommand query command.
|
[
"Creates",
"a",
"SELECT",
"command",
"for",
"a",
"single",
"table",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/CDbCommandBuilder.php#L74-L102
|
train
|
yiisoft/yii
|
framework/db/schema/CDbCommandBuilder.php
|
CDbCommandBuilder.createDeleteCommand
|
public function createDeleteCommand($table,$criteria)
{
$this->ensureTable($table);
$sql="DELETE FROM {$table->rawName}";
$sql=$this->applyJoin($sql,$criteria->join);
$sql=$this->applyCondition($sql,$criteria->condition);
$sql=$this->applyGroup($sql,$criteria->group);
$sql=$this->applyHaving($sql,$criteria->having);
$sql=$this->applyOrder($sql,$criteria->order);
$sql=$this->applyLimit($sql,$criteria->limit,$criteria->offset);
$command=$this->_connection->createCommand($sql);
$this->bindValues($command,$criteria->params);
return $command;
}
|
php
|
public function createDeleteCommand($table,$criteria)
{
$this->ensureTable($table);
$sql="DELETE FROM {$table->rawName}";
$sql=$this->applyJoin($sql,$criteria->join);
$sql=$this->applyCondition($sql,$criteria->condition);
$sql=$this->applyGroup($sql,$criteria->group);
$sql=$this->applyHaving($sql,$criteria->having);
$sql=$this->applyOrder($sql,$criteria->order);
$sql=$this->applyLimit($sql,$criteria->limit,$criteria->offset);
$command=$this->_connection->createCommand($sql);
$this->bindValues($command,$criteria->params);
return $command;
}
|
[
"public",
"function",
"createDeleteCommand",
"(",
"$",
"table",
",",
"$",
"criteria",
")",
"{",
"$",
"this",
"->",
"ensureTable",
"(",
"$",
"table",
")",
";",
"$",
"sql",
"=",
"\"DELETE FROM {$table->rawName}\"",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"applyJoin",
"(",
"$",
"sql",
",",
"$",
"criteria",
"->",
"join",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"applyCondition",
"(",
"$",
"sql",
",",
"$",
"criteria",
"->",
"condition",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"applyGroup",
"(",
"$",
"sql",
",",
"$",
"criteria",
"->",
"group",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"applyHaving",
"(",
"$",
"sql",
",",
"$",
"criteria",
"->",
"having",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"applyOrder",
"(",
"$",
"sql",
",",
"$",
"criteria",
"->",
"order",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"applyLimit",
"(",
"$",
"sql",
",",
"$",
"criteria",
"->",
"limit",
",",
"$",
"criteria",
"->",
"offset",
")",
";",
"$",
"command",
"=",
"$",
"this",
"->",
"_connection",
"->",
"createCommand",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"bindValues",
"(",
"$",
"command",
",",
"$",
"criteria",
"->",
"params",
")",
";",
"return",
"$",
"command",
";",
"}"
] |
Creates a DELETE command.
@param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
@param CDbCriteria $criteria the query criteria
@return CDbCommand delete command.
|
[
"Creates",
"a",
"DELETE",
"command",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/CDbCommandBuilder.php#L187-L200
|
train
|
yiisoft/yii
|
framework/db/schema/CDbCommandBuilder.php
|
CDbCommandBuilder.createSqlCommand
|
public function createSqlCommand($sql,$params=array())
{
$command=$this->_connection->createCommand($sql);
$this->bindValues($command,$params);
return $command;
}
|
php
|
public function createSqlCommand($sql,$params=array())
{
$command=$this->_connection->createCommand($sql);
$this->bindValues($command,$params);
return $command;
}
|
[
"public",
"function",
"createSqlCommand",
"(",
"$",
"sql",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"command",
"=",
"$",
"this",
"->",
"_connection",
"->",
"createCommand",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"bindValues",
"(",
"$",
"command",
",",
"$",
"params",
")",
";",
"return",
"$",
"command",
";",
"}"
] |
Creates a command based on a given SQL statement.
@param string $sql the explicitly specified SQL statement
@param array $params parameters that will be bound to the SQL statement
@return CDbCommand the created command
|
[
"Creates",
"a",
"command",
"based",
"on",
"a",
"given",
"SQL",
"statement",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/CDbCommandBuilder.php#L454-L459
|
train
|
yiisoft/yii
|
framework/db/schema/CDbCommandBuilder.php
|
CDbCommandBuilder.bindValues
|
public function bindValues($command, $values)
{
if(($n=count($values))===0)
return;
if(isset($values[0])) // question mark placeholders
{
for($i=0;$i<$n;++$i)
$command->bindValue($i+1,$values[$i]);
}
else // named placeholders
{
foreach($values as $name=>$value)
{
if($name[0]!==':')
$name=':'.$name;
$command->bindValue($name,$value);
}
}
}
|
php
|
public function bindValues($command, $values)
{
if(($n=count($values))===0)
return;
if(isset($values[0])) // question mark placeholders
{
for($i=0;$i<$n;++$i)
$command->bindValue($i+1,$values[$i]);
}
else // named placeholders
{
foreach($values as $name=>$value)
{
if($name[0]!==':')
$name=':'.$name;
$command->bindValue($name,$value);
}
}
}
|
[
"public",
"function",
"bindValues",
"(",
"$",
"command",
",",
"$",
"values",
")",
"{",
"if",
"(",
"(",
"$",
"n",
"=",
"count",
"(",
"$",
"values",
")",
")",
"===",
"0",
")",
"return",
";",
"if",
"(",
"isset",
"(",
"$",
"values",
"[",
"0",
"]",
")",
")",
"// question mark placeholders",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"n",
";",
"++",
"$",
"i",
")",
"$",
"command",
"->",
"bindValue",
"(",
"$",
"i",
"+",
"1",
",",
"$",
"values",
"[",
"$",
"i",
"]",
")",
";",
"}",
"else",
"// named placeholders",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"name",
"[",
"0",
"]",
"!==",
"':'",
")",
"$",
"name",
"=",
"':'",
".",
"$",
"name",
";",
"$",
"command",
"->",
"bindValue",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}",
"}"
] |
Binds parameter values for an SQL command.
@param CDbCommand $command database command
@param array $values values for binding (integer-indexed array for question mark placeholders, string-indexed array for named placeholders)
|
[
"Binds",
"parameter",
"values",
"for",
"an",
"SQL",
"command",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/CDbCommandBuilder.php#L553-L571
|
train
|
yiisoft/yii
|
framework/db/schema/CDbCommandBuilder.php
|
CDbCommandBuilder.createCriteria
|
public function createCriteria($condition='',$params=array())
{
if(is_array($condition))
$criteria=new CDbCriteria($condition);
elseif($condition instanceof CDbCriteria)
$criteria=clone $condition;
else
{
$criteria=new CDbCriteria;
$criteria->condition=$condition;
$criteria->params=$params;
}
return $criteria;
}
|
php
|
public function createCriteria($condition='',$params=array())
{
if(is_array($condition))
$criteria=new CDbCriteria($condition);
elseif($condition instanceof CDbCriteria)
$criteria=clone $condition;
else
{
$criteria=new CDbCriteria;
$criteria->condition=$condition;
$criteria->params=$params;
}
return $criteria;
}
|
[
"public",
"function",
"createCriteria",
"(",
"$",
"condition",
"=",
"''",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"condition",
")",
")",
"$",
"criteria",
"=",
"new",
"CDbCriteria",
"(",
"$",
"condition",
")",
";",
"elseif",
"(",
"$",
"condition",
"instanceof",
"CDbCriteria",
")",
"$",
"criteria",
"=",
"clone",
"$",
"condition",
";",
"else",
"{",
"$",
"criteria",
"=",
"new",
"CDbCriteria",
";",
"$",
"criteria",
"->",
"condition",
"=",
"$",
"condition",
";",
"$",
"criteria",
"->",
"params",
"=",
"$",
"params",
";",
"}",
"return",
"$",
"criteria",
";",
"}"
] |
Creates a query criteria.
@param mixed $condition query condition or criteria.
If a string, it is treated as query condition (the WHERE clause);
If an array, it is treated as the initial values for constructing a {@link CDbCriteria} object;
Otherwise, it should be an instance of {@link CDbCriteria}.
@param array $params parameters to be bound to an SQL statement.
This is only used when the first parameter is a string (query condition).
In other cases, please use {@link CDbCriteria::params} to set parameters.
@return CDbCriteria the created query criteria
@throws CException if the condition is not string, array and CDbCriteria
|
[
"Creates",
"a",
"query",
"criteria",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/CDbCommandBuilder.php#L585-L598
|
train
|
yiisoft/yii
|
framework/db/schema/CDbCommandBuilder.php
|
CDbCommandBuilder.createPkCriteria
|
public function createPkCriteria($table,$pk,$condition='',$params=array(),$prefix=null)
{
$this->ensureTable($table);
$criteria=$this->createCriteria($condition,$params);
if($criteria->alias!='')
$prefix=$this->_schema->quoteTableName($criteria->alias).'.';
if(!is_array($pk)) // single key
$pk=array($pk);
if(is_array($table->primaryKey) && !isset($pk[0]) && $pk!==array()) // single composite key
$pk=array($pk);
$condition=$this->createInCondition($table,$table->primaryKey,$pk,$prefix);
if($criteria->condition!='')
$criteria->condition=$condition.' AND ('.$criteria->condition.')';
else
$criteria->condition=$condition;
return $criteria;
}
|
php
|
public function createPkCriteria($table,$pk,$condition='',$params=array(),$prefix=null)
{
$this->ensureTable($table);
$criteria=$this->createCriteria($condition,$params);
if($criteria->alias!='')
$prefix=$this->_schema->quoteTableName($criteria->alias).'.';
if(!is_array($pk)) // single key
$pk=array($pk);
if(is_array($table->primaryKey) && !isset($pk[0]) && $pk!==array()) // single composite key
$pk=array($pk);
$condition=$this->createInCondition($table,$table->primaryKey,$pk,$prefix);
if($criteria->condition!='')
$criteria->condition=$condition.' AND ('.$criteria->condition.')';
else
$criteria->condition=$condition;
return $criteria;
}
|
[
"public",
"function",
"createPkCriteria",
"(",
"$",
"table",
",",
"$",
"pk",
",",
"$",
"condition",
"=",
"''",
",",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"prefix",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"ensureTable",
"(",
"$",
"table",
")",
";",
"$",
"criteria",
"=",
"$",
"this",
"->",
"createCriteria",
"(",
"$",
"condition",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"criteria",
"->",
"alias",
"!=",
"''",
")",
"$",
"prefix",
"=",
"$",
"this",
"->",
"_schema",
"->",
"quoteTableName",
"(",
"$",
"criteria",
"->",
"alias",
")",
".",
"'.'",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"pk",
")",
")",
"// single key",
"$",
"pk",
"=",
"array",
"(",
"$",
"pk",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"table",
"->",
"primaryKey",
")",
"&&",
"!",
"isset",
"(",
"$",
"pk",
"[",
"0",
"]",
")",
"&&",
"$",
"pk",
"!==",
"array",
"(",
")",
")",
"// single composite key",
"$",
"pk",
"=",
"array",
"(",
"$",
"pk",
")",
";",
"$",
"condition",
"=",
"$",
"this",
"->",
"createInCondition",
"(",
"$",
"table",
",",
"$",
"table",
"->",
"primaryKey",
",",
"$",
"pk",
",",
"$",
"prefix",
")",
";",
"if",
"(",
"$",
"criteria",
"->",
"condition",
"!=",
"''",
")",
"$",
"criteria",
"->",
"condition",
"=",
"$",
"condition",
".",
"' AND ('",
".",
"$",
"criteria",
"->",
"condition",
".",
"')'",
";",
"else",
"$",
"criteria",
"->",
"condition",
"=",
"$",
"condition",
";",
"return",
"$",
"criteria",
";",
"}"
] |
Creates a query criteria with the specified primary key.
@param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
@param mixed $pk primary key value(s). Use array for multiple primary keys. For composite key, each key value must be an array (column name=>column value).
@param mixed $condition query condition or criteria.
If a string, it is treated as query condition;
If an array, it is treated as the initial values for constructing a {@link CDbCriteria};
Otherwise, it should be an instance of {@link CDbCriteria}.
@param array $params parameters to be bound to an SQL statement.
This is only used when the second parameter is a string (query condition).
In other cases, please use {@link CDbCriteria::params} to set parameters.
@param string $prefix column prefix (ended with dot). If null, it will be the table name
@return CDbCriteria the created query criteria
|
[
"Creates",
"a",
"query",
"criteria",
"with",
"the",
"specified",
"primary",
"key",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/CDbCommandBuilder.php#L614-L631
|
train
|
yiisoft/yii
|
framework/db/schema/CDbCommandBuilder.php
|
CDbCommandBuilder.createColumnCriteria
|
public function createColumnCriteria($table,$columns,$condition='',$params=array(),$prefix=null)
{
$this->ensureTable($table);
$criteria=$this->createCriteria($condition,$params);
if($criteria->alias!='')
$prefix=$this->_schema->quoteTableName($criteria->alias).'.';
$bindByPosition=isset($criteria->params[0]);
$conditions=array();
$values=array();
$i=0;
if($prefix===null)
$prefix=$table->rawName.'.';
foreach($columns as $name=>$value)
{
if(($column=$table->getColumn($name))!==null)
{
if(is_array($value))
$conditions[]=$this->createInCondition($table,$name,$value,$prefix);
elseif($value!==null)
{
if($bindByPosition)
{
$conditions[]=$prefix.$column->rawName.'=?';
$values[]=$value;
}
else
{
$conditions[]=$prefix.$column->rawName.'='.self::PARAM_PREFIX.$i;
$values[self::PARAM_PREFIX.$i]=$value;
$i++;
}
}
else
$conditions[]=$prefix.$column->rawName.' IS NULL';
}
else
throw new CDbException(Yii::t('yii','Table "{table}" does not have a column named "{column}".',
array('{table}'=>$table->name,'{column}'=>$name)));
}
$criteria->params=array_merge($values,$criteria->params);
if(isset($conditions[0]))
{
if($criteria->condition!='')
$criteria->condition=implode(' AND ',$conditions).' AND ('.$criteria->condition.')';
else
$criteria->condition=implode(' AND ',$conditions);
}
return $criteria;
}
|
php
|
public function createColumnCriteria($table,$columns,$condition='',$params=array(),$prefix=null)
{
$this->ensureTable($table);
$criteria=$this->createCriteria($condition,$params);
if($criteria->alias!='')
$prefix=$this->_schema->quoteTableName($criteria->alias).'.';
$bindByPosition=isset($criteria->params[0]);
$conditions=array();
$values=array();
$i=0;
if($prefix===null)
$prefix=$table->rawName.'.';
foreach($columns as $name=>$value)
{
if(($column=$table->getColumn($name))!==null)
{
if(is_array($value))
$conditions[]=$this->createInCondition($table,$name,$value,$prefix);
elseif($value!==null)
{
if($bindByPosition)
{
$conditions[]=$prefix.$column->rawName.'=?';
$values[]=$value;
}
else
{
$conditions[]=$prefix.$column->rawName.'='.self::PARAM_PREFIX.$i;
$values[self::PARAM_PREFIX.$i]=$value;
$i++;
}
}
else
$conditions[]=$prefix.$column->rawName.' IS NULL';
}
else
throw new CDbException(Yii::t('yii','Table "{table}" does not have a column named "{column}".',
array('{table}'=>$table->name,'{column}'=>$name)));
}
$criteria->params=array_merge($values,$criteria->params);
if(isset($conditions[0]))
{
if($criteria->condition!='')
$criteria->condition=implode(' AND ',$conditions).' AND ('.$criteria->condition.')';
else
$criteria->condition=implode(' AND ',$conditions);
}
return $criteria;
}
|
[
"public",
"function",
"createColumnCriteria",
"(",
"$",
"table",
",",
"$",
"columns",
",",
"$",
"condition",
"=",
"''",
",",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"prefix",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"ensureTable",
"(",
"$",
"table",
")",
";",
"$",
"criteria",
"=",
"$",
"this",
"->",
"createCriteria",
"(",
"$",
"condition",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"criteria",
"->",
"alias",
"!=",
"''",
")",
"$",
"prefix",
"=",
"$",
"this",
"->",
"_schema",
"->",
"quoteTableName",
"(",
"$",
"criteria",
"->",
"alias",
")",
".",
"'.'",
";",
"$",
"bindByPosition",
"=",
"isset",
"(",
"$",
"criteria",
"->",
"params",
"[",
"0",
"]",
")",
";",
"$",
"conditions",
"=",
"array",
"(",
")",
";",
"$",
"values",
"=",
"array",
"(",
")",
";",
"$",
"i",
"=",
"0",
";",
"if",
"(",
"$",
"prefix",
"===",
"null",
")",
"$",
"prefix",
"=",
"$",
"table",
"->",
"rawName",
".",
"'.'",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"(",
"$",
"column",
"=",
"$",
"table",
"->",
"getColumn",
"(",
"$",
"name",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"$",
"conditions",
"[",
"]",
"=",
"$",
"this",
"->",
"createInCondition",
"(",
"$",
"table",
",",
"$",
"name",
",",
"$",
"value",
",",
"$",
"prefix",
")",
";",
"elseif",
"(",
"$",
"value",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"bindByPosition",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"$",
"prefix",
".",
"$",
"column",
"->",
"rawName",
".",
"'=?'",
";",
"$",
"values",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"conditions",
"[",
"]",
"=",
"$",
"prefix",
".",
"$",
"column",
"->",
"rawName",
".",
"'='",
".",
"self",
"::",
"PARAM_PREFIX",
".",
"$",
"i",
";",
"$",
"values",
"[",
"self",
"::",
"PARAM_PREFIX",
".",
"$",
"i",
"]",
"=",
"$",
"value",
";",
"$",
"i",
"++",
";",
"}",
"}",
"else",
"$",
"conditions",
"[",
"]",
"=",
"$",
"prefix",
".",
"$",
"column",
"->",
"rawName",
".",
"' IS NULL'",
";",
"}",
"else",
"throw",
"new",
"CDbException",
"(",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'Table \"{table}\" does not have a column named \"{column}\".'",
",",
"array",
"(",
"'{table}'",
"=>",
"$",
"table",
"->",
"name",
",",
"'{column}'",
"=>",
"$",
"name",
")",
")",
")",
";",
"}",
"$",
"criteria",
"->",
"params",
"=",
"array_merge",
"(",
"$",
"values",
",",
"$",
"criteria",
"->",
"params",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"conditions",
"[",
"0",
"]",
")",
")",
"{",
"if",
"(",
"$",
"criteria",
"->",
"condition",
"!=",
"''",
")",
"$",
"criteria",
"->",
"condition",
"=",
"implode",
"(",
"' AND '",
",",
"$",
"conditions",
")",
".",
"' AND ('",
".",
"$",
"criteria",
"->",
"condition",
".",
"')'",
";",
"else",
"$",
"criteria",
"->",
"condition",
"=",
"implode",
"(",
"' AND '",
",",
"$",
"conditions",
")",
";",
"}",
"return",
"$",
"criteria",
";",
"}"
] |
Creates a query criteria with the specified column values.
@param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
@param array $columns column values that should be matched in the query (name=>value)
@param mixed $condition query condition or criteria.
If a string, it is treated as query condition;
If an array, it is treated as the initial values for constructing a {@link CDbCriteria};
Otherwise, it should be an instance of {@link CDbCriteria}.
@param array $params parameters to be bound to an SQL statement.
This is only used when the third parameter is a string (query condition).
In other cases, please use {@link CDbCriteria::params} to set parameters.
@param string $prefix column prefix (ended with dot). If null, it will be the table name
@throws CDbException if specified column is not found in given table
@return CDbCriteria the created query criteria
|
[
"Creates",
"a",
"query",
"criteria",
"with",
"the",
"specified",
"column",
"values",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/CDbCommandBuilder.php#L661-L709
|
train
|
yiisoft/yii
|
framework/db/schema/CDbCommandBuilder.php
|
CDbCommandBuilder.createSearchCondition
|
public function createSearchCondition($table,$columns,$keywords,$prefix=null,$caseSensitive=true)
{
$this->ensureTable($table);
if(!is_array($keywords))
$keywords=preg_split('/\s+/u',$keywords,-1,PREG_SPLIT_NO_EMPTY);
if(empty($keywords))
return '';
if($prefix===null)
$prefix=$table->rawName.'.';
$conditions=array();
foreach($columns as $name)
{
if(($column=$table->getColumn($name))===null)
throw new CDbException(Yii::t('yii','Table "{table}" does not have a column named "{column}".',
array('{table}'=>$table->name,'{column}'=>$name)));
$condition=array();
foreach($keywords as $keyword)
{
$keyword='%'.strtr($keyword,array('%'=>'\%', '_'=>'\_', '\\'=>'\\\\')).'%';
if($caseSensitive)
$condition[]=$prefix.$column->rawName.' LIKE '.$this->_connection->quoteValue($keyword);
else
$condition[]='LOWER('.$prefix.$column->rawName.') LIKE LOWER('.$this->_connection->quoteValue($keyword).')';
}
$conditions[]=implode(' AND ',$condition);
}
return '('.implode(' OR ',$conditions).')';
}
|
php
|
public function createSearchCondition($table,$columns,$keywords,$prefix=null,$caseSensitive=true)
{
$this->ensureTable($table);
if(!is_array($keywords))
$keywords=preg_split('/\s+/u',$keywords,-1,PREG_SPLIT_NO_EMPTY);
if(empty($keywords))
return '';
if($prefix===null)
$prefix=$table->rawName.'.';
$conditions=array();
foreach($columns as $name)
{
if(($column=$table->getColumn($name))===null)
throw new CDbException(Yii::t('yii','Table "{table}" does not have a column named "{column}".',
array('{table}'=>$table->name,'{column}'=>$name)));
$condition=array();
foreach($keywords as $keyword)
{
$keyword='%'.strtr($keyword,array('%'=>'\%', '_'=>'\_', '\\'=>'\\\\')).'%';
if($caseSensitive)
$condition[]=$prefix.$column->rawName.' LIKE '.$this->_connection->quoteValue($keyword);
else
$condition[]='LOWER('.$prefix.$column->rawName.') LIKE LOWER('.$this->_connection->quoteValue($keyword).')';
}
$conditions[]=implode(' AND ',$condition);
}
return '('.implode(' OR ',$conditions).')';
}
|
[
"public",
"function",
"createSearchCondition",
"(",
"$",
"table",
",",
"$",
"columns",
",",
"$",
"keywords",
",",
"$",
"prefix",
"=",
"null",
",",
"$",
"caseSensitive",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"ensureTable",
"(",
"$",
"table",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"keywords",
")",
")",
"$",
"keywords",
"=",
"preg_split",
"(",
"'/\\s+/u'",
",",
"$",
"keywords",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"keywords",
")",
")",
"return",
"''",
";",
"if",
"(",
"$",
"prefix",
"===",
"null",
")",
"$",
"prefix",
"=",
"$",
"table",
"->",
"rawName",
".",
"'.'",
";",
"$",
"conditions",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"name",
")",
"{",
"if",
"(",
"(",
"$",
"column",
"=",
"$",
"table",
"->",
"getColumn",
"(",
"$",
"name",
")",
")",
"===",
"null",
")",
"throw",
"new",
"CDbException",
"(",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'Table \"{table}\" does not have a column named \"{column}\".'",
",",
"array",
"(",
"'{table}'",
"=>",
"$",
"table",
"->",
"name",
",",
"'{column}'",
"=>",
"$",
"name",
")",
")",
")",
";",
"$",
"condition",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"keywords",
"as",
"$",
"keyword",
")",
"{",
"$",
"keyword",
"=",
"'%'",
".",
"strtr",
"(",
"$",
"keyword",
",",
"array",
"(",
"'%'",
"=>",
"'\\%'",
",",
"'_'",
"=>",
"'\\_'",
",",
"'\\\\'",
"=>",
"'\\\\\\\\'",
")",
")",
".",
"'%'",
";",
"if",
"(",
"$",
"caseSensitive",
")",
"$",
"condition",
"[",
"]",
"=",
"$",
"prefix",
".",
"$",
"column",
"->",
"rawName",
".",
"' LIKE '",
".",
"$",
"this",
"->",
"_connection",
"->",
"quoteValue",
"(",
"$",
"keyword",
")",
";",
"else",
"$",
"condition",
"[",
"]",
"=",
"'LOWER('",
".",
"$",
"prefix",
".",
"$",
"column",
"->",
"rawName",
".",
"') LIKE LOWER('",
".",
"$",
"this",
"->",
"_connection",
"->",
"quoteValue",
"(",
"$",
"keyword",
")",
".",
"')'",
";",
"}",
"$",
"conditions",
"[",
"]",
"=",
"implode",
"(",
"' AND '",
",",
"$",
"condition",
")",
";",
"}",
"return",
"'('",
".",
"implode",
"(",
"' OR '",
",",
"$",
"conditions",
")",
".",
"')'",
";",
"}"
] |
Generates the expression for searching the specified keywords within a list of columns.
The search expression is generated using the 'LIKE' SQL syntax.
Every word in the keywords must be present and appear in at least one of the columns.
@param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
@param array $columns list of column names for potential search condition.
@param mixed $keywords search keywords. This can be either a string with space-separated keywords or an array of keywords.
@param string $prefix optional column prefix (with dot at the end). If null, the table name will be used as the prefix.
@param boolean $caseSensitive whether the search is case-sensitive. Defaults to true.
@throws CDbException if specified column is not found in given table
@return string SQL search condition matching on a set of columns. An empty string is returned
if either the column array or the keywords are empty.
|
[
"Generates",
"the",
"expression",
"for",
"searching",
"the",
"specified",
"keywords",
"within",
"a",
"list",
"of",
"columns",
".",
"The",
"search",
"expression",
"is",
"generated",
"using",
"the",
"LIKE",
"SQL",
"syntax",
".",
"Every",
"word",
"in",
"the",
"keywords",
"must",
"be",
"present",
"and",
"appear",
"in",
"at",
"least",
"one",
"of",
"the",
"columns",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/CDbCommandBuilder.php#L724-L751
|
train
|
yiisoft/yii
|
framework/db/schema/CDbCommandBuilder.php
|
CDbCommandBuilder.ensureTable
|
protected function ensureTable(&$table)
{
if(is_string($table) && ($table=$this->_schema->getTable($tableName=$table))===null)
throw new CDbException(Yii::t('yii','Table "{table}" does not exist.',
array('{table}'=>$tableName)));
}
|
php
|
protected function ensureTable(&$table)
{
if(is_string($table) && ($table=$this->_schema->getTable($tableName=$table))===null)
throw new CDbException(Yii::t('yii','Table "{table}" does not exist.',
array('{table}'=>$tableName)));
}
|
[
"protected",
"function",
"ensureTable",
"(",
"&",
"$",
"table",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"table",
")",
"&&",
"(",
"$",
"table",
"=",
"$",
"this",
"->",
"_schema",
"->",
"getTable",
"(",
"$",
"tableName",
"=",
"$",
"table",
")",
")",
"===",
"null",
")",
"throw",
"new",
"CDbException",
"(",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'Table \"{table}\" does not exist.'",
",",
"array",
"(",
"'{table}'",
"=>",
"$",
"tableName",
")",
")",
")",
";",
"}"
] |
Checks if the parameter is a valid table schema.
If it is a string, the corresponding table schema will be retrieved.
@param mixed $table table schema ({@link CDbTableSchema}) or table name (string).
If this refers to a valid table name, this parameter will be returned with the corresponding table schema.
@throws CDbException if the table name is not valid
|
[
"Checks",
"if",
"the",
"parameter",
"is",
"a",
"valid",
"table",
"schema",
".",
"If",
"it",
"is",
"a",
"string",
"the",
"corresponding",
"table",
"schema",
"will",
"be",
"retrieved",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/db/schema/CDbCommandBuilder.php#L859-L864
|
train
|
yiisoft/yii
|
framework/base/CDbStatePersister.php
|
CDbStatePersister.save
|
public function save($state)
{
$command=$this->db->createCommand();
if(false===$this->exists())
return $command->insert($this->stateTableName,array(
$this->keyField=>Yii::app()->name,
$this->valueField=>serialize($state)
));
else
return $command->update($this->stateTableName,array($this->valueField=>serialize($state)),
$this->db->quoteColumnName($this->keyField).'=:key',
array(':key'=>Yii::app()->name)
);
}
|
php
|
public function save($state)
{
$command=$this->db->createCommand();
if(false===$this->exists())
return $command->insert($this->stateTableName,array(
$this->keyField=>Yii::app()->name,
$this->valueField=>serialize($state)
));
else
return $command->update($this->stateTableName,array($this->valueField=>serialize($state)),
$this->db->quoteColumnName($this->keyField).'=:key',
array(':key'=>Yii::app()->name)
);
}
|
[
"public",
"function",
"save",
"(",
"$",
"state",
")",
"{",
"$",
"command",
"=",
"$",
"this",
"->",
"db",
"->",
"createCommand",
"(",
")",
";",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"exists",
"(",
")",
")",
"return",
"$",
"command",
"->",
"insert",
"(",
"$",
"this",
"->",
"stateTableName",
",",
"array",
"(",
"$",
"this",
"->",
"keyField",
"=>",
"Yii",
"::",
"app",
"(",
")",
"->",
"name",
",",
"$",
"this",
"->",
"valueField",
"=>",
"serialize",
"(",
"$",
"state",
")",
")",
")",
";",
"else",
"return",
"$",
"command",
"->",
"update",
"(",
"$",
"this",
"->",
"stateTableName",
",",
"array",
"(",
"$",
"this",
"->",
"valueField",
"=>",
"serialize",
"(",
"$",
"state",
")",
")",
",",
"$",
"this",
"->",
"db",
"->",
"quoteColumnName",
"(",
"$",
"this",
"->",
"keyField",
")",
".",
"'=:key'",
",",
"array",
"(",
"':key'",
"=>",
"Yii",
"::",
"app",
"(",
")",
"->",
"name",
")",
")",
";",
"}"
] |
Saves application state in persistent storage.
@param mixed $state state data (must be serializable).
@return int
|
[
"Saves",
"application",
"state",
"in",
"persistent",
"storage",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/base/CDbStatePersister.php#L105-L118
|
train
|
yiisoft/yii
|
framework/base/CDbStatePersister.php
|
CDbStatePersister.createTable
|
protected function createTable()
{
try
{
$command=$this->db->createCommand();
$command->createTable($this->stateTableName,array(
$this->keyField=>'string NOT NULL',
$this->valueField=>'text NOT NULL',
'PRIMARY KEY ('.$this->db->quoteColumnName($this->keyField).')'
));
}
catch (CDbException $e)
{
throw new CException(Yii::t('yii','Can\'t create state persister table. Check CREATE privilege for \'{db}\' connection user or create table manually with SQL: {sql}.',array('{db}'=>$this->dbComponent,'{sql}'=>$command->text ) ) );
}
}
|
php
|
protected function createTable()
{
try
{
$command=$this->db->createCommand();
$command->createTable($this->stateTableName,array(
$this->keyField=>'string NOT NULL',
$this->valueField=>'text NOT NULL',
'PRIMARY KEY ('.$this->db->quoteColumnName($this->keyField).')'
));
}
catch (CDbException $e)
{
throw new CException(Yii::t('yii','Can\'t create state persister table. Check CREATE privilege for \'{db}\' connection user or create table manually with SQL: {sql}.',array('{db}'=>$this->dbComponent,'{sql}'=>$command->text ) ) );
}
}
|
[
"protected",
"function",
"createTable",
"(",
")",
"{",
"try",
"{",
"$",
"command",
"=",
"$",
"this",
"->",
"db",
"->",
"createCommand",
"(",
")",
";",
"$",
"command",
"->",
"createTable",
"(",
"$",
"this",
"->",
"stateTableName",
",",
"array",
"(",
"$",
"this",
"->",
"keyField",
"=>",
"'string NOT NULL'",
",",
"$",
"this",
"->",
"valueField",
"=>",
"'text NOT NULL'",
",",
"'PRIMARY KEY ('",
".",
"$",
"this",
"->",
"db",
"->",
"quoteColumnName",
"(",
"$",
"this",
"->",
"keyField",
")",
".",
"')'",
")",
")",
";",
"}",
"catch",
"(",
"CDbException",
"$",
"e",
")",
"{",
"throw",
"new",
"CException",
"(",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'Can\\'t create state persister table. Check CREATE privilege for \\'{db}\\' connection user or create table manually with SQL: {sql}.'",
",",
"array",
"(",
"'{db}'",
"=>",
"$",
"this",
"->",
"dbComponent",
",",
"'{sql}'",
"=>",
"$",
"command",
"->",
"text",
")",
")",
")",
";",
"}",
"}"
] |
Creates state persister table
@throws CException
|
[
"Creates",
"state",
"persister",
"table"
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/base/CDbStatePersister.php#L137-L152
|
train
|
yiisoft/yii
|
framework/i18n/CDateFormatter.php
|
CDateFormatter.format
|
public function format($pattern,$time)
{
if($time===null)
return null;
if(is_string($time))
{
if(ctype_digit($time) || ($time{0}=='-' && ctype_digit(substr($time, 1))))
$time=(int)$time;
else
$time=strtotime($time);
}
$date=CTimestamp::getDate($time,false,false);
$tokens=$this->parseFormat($pattern);
foreach($tokens as &$token)
{
if(is_array($token)) // a callback: method name, sub-pattern
$token=$this->{$token[0]}($token[1],$date);
}
return implode('',$tokens);
}
|
php
|
public function format($pattern,$time)
{
if($time===null)
return null;
if(is_string($time))
{
if(ctype_digit($time) || ($time{0}=='-' && ctype_digit(substr($time, 1))))
$time=(int)$time;
else
$time=strtotime($time);
}
$date=CTimestamp::getDate($time,false,false);
$tokens=$this->parseFormat($pattern);
foreach($tokens as &$token)
{
if(is_array($token)) // a callback: method name, sub-pattern
$token=$this->{$token[0]}($token[1],$date);
}
return implode('',$tokens);
}
|
[
"public",
"function",
"format",
"(",
"$",
"pattern",
",",
"$",
"time",
")",
"{",
"if",
"(",
"$",
"time",
"===",
"null",
")",
"return",
"null",
";",
"if",
"(",
"is_string",
"(",
"$",
"time",
")",
")",
"{",
"if",
"(",
"ctype_digit",
"(",
"$",
"time",
")",
"||",
"(",
"$",
"time",
"{",
"0",
"}",
"==",
"'-'",
"&&",
"ctype_digit",
"(",
"substr",
"(",
"$",
"time",
",",
"1",
")",
")",
")",
")",
"$",
"time",
"=",
"(",
"int",
")",
"$",
"time",
";",
"else",
"$",
"time",
"=",
"strtotime",
"(",
"$",
"time",
")",
";",
"}",
"$",
"date",
"=",
"CTimestamp",
"::",
"getDate",
"(",
"$",
"time",
",",
"false",
",",
"false",
")",
";",
"$",
"tokens",
"=",
"$",
"this",
"->",
"parseFormat",
"(",
"$",
"pattern",
")",
";",
"foreach",
"(",
"$",
"tokens",
"as",
"&",
"$",
"token",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"token",
")",
")",
"// a callback: method name, sub-pattern",
"$",
"token",
"=",
"$",
"this",
"->",
"{",
"$",
"token",
"[",
"0",
"]",
"}",
"(",
"$",
"token",
"[",
"1",
"]",
",",
"$",
"date",
")",
";",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"tokens",
")",
";",
"}"
] |
Formats a date according to a customized pattern.
@param string $pattern the pattern (See {@link http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns})
@param mixed $time UNIX timestamp or a string in strtotime format
@return string formatted date time. Null if $time is null. (the null value check is available since Yii 1.1.11)
|
[
"Formats",
"a",
"date",
"according",
"to",
"a",
"customized",
"pattern",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CDateFormatter.php#L86-L106
|
train
|
yiisoft/yii
|
framework/i18n/CDateFormatter.php
|
CDateFormatter.formatDateTime
|
public function formatDateTime($timestamp,$dateWidth='medium',$timeWidth='medium')
{
if(!empty($dateWidth))
$date=$this->format($this->_locale->getDateFormat($dateWidth),$timestamp);
if(!empty($timeWidth))
$time=$this->format($this->_locale->getTimeFormat($timeWidth),$timestamp);
if(isset($date) && isset($time))
{
$dateTimePattern=$this->_locale->getDateTimeFormat();
return strtr($dateTimePattern,array('{0}'=>$time,'{1}'=>$date));
}
elseif(isset($date))
return $date;
elseif(isset($time))
return $time;
}
|
php
|
public function formatDateTime($timestamp,$dateWidth='medium',$timeWidth='medium')
{
if(!empty($dateWidth))
$date=$this->format($this->_locale->getDateFormat($dateWidth),$timestamp);
if(!empty($timeWidth))
$time=$this->format($this->_locale->getTimeFormat($timeWidth),$timestamp);
if(isset($date) && isset($time))
{
$dateTimePattern=$this->_locale->getDateTimeFormat();
return strtr($dateTimePattern,array('{0}'=>$time,'{1}'=>$date));
}
elseif(isset($date))
return $date;
elseif(isset($time))
return $time;
}
|
[
"public",
"function",
"formatDateTime",
"(",
"$",
"timestamp",
",",
"$",
"dateWidth",
"=",
"'medium'",
",",
"$",
"timeWidth",
"=",
"'medium'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"dateWidth",
")",
")",
"$",
"date",
"=",
"$",
"this",
"->",
"format",
"(",
"$",
"this",
"->",
"_locale",
"->",
"getDateFormat",
"(",
"$",
"dateWidth",
")",
",",
"$",
"timestamp",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"timeWidth",
")",
")",
"$",
"time",
"=",
"$",
"this",
"->",
"format",
"(",
"$",
"this",
"->",
"_locale",
"->",
"getTimeFormat",
"(",
"$",
"timeWidth",
")",
",",
"$",
"timestamp",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"date",
")",
"&&",
"isset",
"(",
"$",
"time",
")",
")",
"{",
"$",
"dateTimePattern",
"=",
"$",
"this",
"->",
"_locale",
"->",
"getDateTimeFormat",
"(",
")",
";",
"return",
"strtr",
"(",
"$",
"dateTimePattern",
",",
"array",
"(",
"'{0}'",
"=>",
"$",
"time",
",",
"'{1}'",
"=>",
"$",
"date",
")",
")",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"date",
")",
")",
"return",
"$",
"date",
";",
"elseif",
"(",
"isset",
"(",
"$",
"time",
")",
")",
"return",
"$",
"time",
";",
"}"
] |
Formats a date according to a predefined pattern.
The predefined pattern is determined based on the date pattern width and time pattern width.
@param mixed $timestamp UNIX timestamp or a string in strtotime format
@param string $dateWidth width of the date pattern. It can be 'full', 'long', 'medium' and 'short'.
If null, it means the date portion will NOT appear in the formatting result
@param string $timeWidth width of the time pattern. It can be 'full', 'long', 'medium' and 'short'.
If null, it means the time portion will NOT appear in the formatting result
@return string formatted date time.
|
[
"Formats",
"a",
"date",
"according",
"to",
"a",
"predefined",
"pattern",
".",
"The",
"predefined",
"pattern",
"is",
"determined",
"based",
"on",
"the",
"date",
"pattern",
"width",
"and",
"time",
"pattern",
"width",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CDateFormatter.php#L118-L135
|
train
|
yiisoft/yii
|
framework/i18n/CDateFormatter.php
|
CDateFormatter.parseFormat
|
protected function parseFormat($pattern)
{
static $formats=array(); // cache
if(isset($formats[$pattern]))
return $formats[$pattern];
$tokens=array();
$n=strlen($pattern);
$isLiteral=false;
$literal='';
for($i=0;$i<$n;++$i)
{
$c=$pattern[$i];
if($c==="'")
{
if($i<$n-1 && $pattern[$i+1]==="'")
{
$tokens[]="'";
$i++;
}
elseif($isLiteral)
{
$tokens[]=$literal;
$literal='';
$isLiteral=false;
}
else
{
$isLiteral=true;
$literal='';
}
}
elseif($isLiteral)
$literal.=$c;
else
{
for($j=$i+1;$j<$n;++$j)
{
if($pattern[$j]!==$c)
break;
}
$p=str_repeat($c,$j-$i);
if(isset(self::$_formatters[$c]))
$tokens[]=array(self::$_formatters[$c],$p);
else
$tokens[]=$p;
$i=$j-1;
}
}
if($literal!=='')
$tokens[]=$literal;
return $formats[$pattern]=$tokens;
}
|
php
|
protected function parseFormat($pattern)
{
static $formats=array(); // cache
if(isset($formats[$pattern]))
return $formats[$pattern];
$tokens=array();
$n=strlen($pattern);
$isLiteral=false;
$literal='';
for($i=0;$i<$n;++$i)
{
$c=$pattern[$i];
if($c==="'")
{
if($i<$n-1 && $pattern[$i+1]==="'")
{
$tokens[]="'";
$i++;
}
elseif($isLiteral)
{
$tokens[]=$literal;
$literal='';
$isLiteral=false;
}
else
{
$isLiteral=true;
$literal='';
}
}
elseif($isLiteral)
$literal.=$c;
else
{
for($j=$i+1;$j<$n;++$j)
{
if($pattern[$j]!==$c)
break;
}
$p=str_repeat($c,$j-$i);
if(isset(self::$_formatters[$c]))
$tokens[]=array(self::$_formatters[$c],$p);
else
$tokens[]=$p;
$i=$j-1;
}
}
if($literal!=='')
$tokens[]=$literal;
return $formats[$pattern]=$tokens;
}
|
[
"protected",
"function",
"parseFormat",
"(",
"$",
"pattern",
")",
"{",
"static",
"$",
"formats",
"=",
"array",
"(",
")",
";",
"// cache",
"if",
"(",
"isset",
"(",
"$",
"formats",
"[",
"$",
"pattern",
"]",
")",
")",
"return",
"$",
"formats",
"[",
"$",
"pattern",
"]",
";",
"$",
"tokens",
"=",
"array",
"(",
")",
";",
"$",
"n",
"=",
"strlen",
"(",
"$",
"pattern",
")",
";",
"$",
"isLiteral",
"=",
"false",
";",
"$",
"literal",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"n",
";",
"++",
"$",
"i",
")",
"{",
"$",
"c",
"=",
"$",
"pattern",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"$",
"c",
"===",
"\"'\"",
")",
"{",
"if",
"(",
"$",
"i",
"<",
"$",
"n",
"-",
"1",
"&&",
"$",
"pattern",
"[",
"$",
"i",
"+",
"1",
"]",
"===",
"\"'\"",
")",
"{",
"$",
"tokens",
"[",
"]",
"=",
"\"'\"",
";",
"$",
"i",
"++",
";",
"}",
"elseif",
"(",
"$",
"isLiteral",
")",
"{",
"$",
"tokens",
"[",
"]",
"=",
"$",
"literal",
";",
"$",
"literal",
"=",
"''",
";",
"$",
"isLiteral",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"isLiteral",
"=",
"true",
";",
"$",
"literal",
"=",
"''",
";",
"}",
"}",
"elseif",
"(",
"$",
"isLiteral",
")",
"$",
"literal",
".=",
"$",
"c",
";",
"else",
"{",
"for",
"(",
"$",
"j",
"=",
"$",
"i",
"+",
"1",
";",
"$",
"j",
"<",
"$",
"n",
";",
"++",
"$",
"j",
")",
"{",
"if",
"(",
"$",
"pattern",
"[",
"$",
"j",
"]",
"!==",
"$",
"c",
")",
"break",
";",
"}",
"$",
"p",
"=",
"str_repeat",
"(",
"$",
"c",
",",
"$",
"j",
"-",
"$",
"i",
")",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"_formatters",
"[",
"$",
"c",
"]",
")",
")",
"$",
"tokens",
"[",
"]",
"=",
"array",
"(",
"self",
"::",
"$",
"_formatters",
"[",
"$",
"c",
"]",
",",
"$",
"p",
")",
";",
"else",
"$",
"tokens",
"[",
"]",
"=",
"$",
"p",
";",
"$",
"i",
"=",
"$",
"j",
"-",
"1",
";",
"}",
"}",
"if",
"(",
"$",
"literal",
"!==",
"''",
")",
"$",
"tokens",
"[",
"]",
"=",
"$",
"literal",
";",
"return",
"$",
"formats",
"[",
"$",
"pattern",
"]",
"=",
"$",
"tokens",
";",
"}"
] |
Parses the datetime format pattern.
@param string $pattern the pattern to be parsed
@return array tokenized parsing result
|
[
"Parses",
"the",
"datetime",
"format",
"pattern",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CDateFormatter.php#L142-L194
|
train
|
yiisoft/yii
|
framework/i18n/CDateFormatter.php
|
CDateFormatter.formatMinutes
|
protected function formatMinutes($pattern,$date)
{
$minutes=$date['minutes'];
if($pattern==='m')
return $minutes;
elseif($pattern==='mm')
return str_pad($minutes,2,'0',STR_PAD_LEFT);
else
throw new CException(Yii::t('yii','The pattern for minutes must be "m" or "mm".'));
}
|
php
|
protected function formatMinutes($pattern,$date)
{
$minutes=$date['minutes'];
if($pattern==='m')
return $minutes;
elseif($pattern==='mm')
return str_pad($minutes,2,'0',STR_PAD_LEFT);
else
throw new CException(Yii::t('yii','The pattern for minutes must be "m" or "mm".'));
}
|
[
"protected",
"function",
"formatMinutes",
"(",
"$",
"pattern",
",",
"$",
"date",
")",
"{",
"$",
"minutes",
"=",
"$",
"date",
"[",
"'minutes'",
"]",
";",
"if",
"(",
"$",
"pattern",
"===",
"'m'",
")",
"return",
"$",
"minutes",
";",
"elseif",
"(",
"$",
"pattern",
"===",
"'mm'",
")",
"return",
"str_pad",
"(",
"$",
"minutes",
",",
"2",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"else",
"throw",
"new",
"CException",
"(",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'The pattern for minutes must be \"m\" or \"mm\".'",
")",
")",
";",
"}"
] |
Get the minutes.
"m" for non-padding, "mm" will always return 2 characters.
@param string $pattern a pattern.
@param array $date result of {@link CTimestamp::getdate}.
@throws CException if "minutes" pattern is unknown
@return string minutes.
|
[
"Get",
"the",
"minutes",
".",
"m",
"for",
"non",
"-",
"padding",
"mm",
"will",
"always",
"return",
"2",
"characters",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CDateFormatter.php#L453-L462
|
train
|
yiisoft/yii
|
framework/i18n/CDateFormatter.php
|
CDateFormatter.formatSeconds
|
protected function formatSeconds($pattern,$date)
{
$seconds=$date['seconds'];
if($pattern==='s')
return $seconds;
elseif($pattern==='ss')
return str_pad($seconds,2,'0',STR_PAD_LEFT);
else
throw new CException(Yii::t('yii','The pattern for seconds must be "s" or "ss".'));
}
|
php
|
protected function formatSeconds($pattern,$date)
{
$seconds=$date['seconds'];
if($pattern==='s')
return $seconds;
elseif($pattern==='ss')
return str_pad($seconds,2,'0',STR_PAD_LEFT);
else
throw new CException(Yii::t('yii','The pattern for seconds must be "s" or "ss".'));
}
|
[
"protected",
"function",
"formatSeconds",
"(",
"$",
"pattern",
",",
"$",
"date",
")",
"{",
"$",
"seconds",
"=",
"$",
"date",
"[",
"'seconds'",
"]",
";",
"if",
"(",
"$",
"pattern",
"===",
"'s'",
")",
"return",
"$",
"seconds",
";",
"elseif",
"(",
"$",
"pattern",
"===",
"'ss'",
")",
"return",
"str_pad",
"(",
"$",
"seconds",
",",
"2",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
";",
"else",
"throw",
"new",
"CException",
"(",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'The pattern for seconds must be \"s\" or \"ss\".'",
")",
")",
";",
"}"
] |
Get the seconds.
"s" for non-padding, "ss" will always return 2 characters.
@param string $pattern a pattern.
@param array $date result of {@link CTimestamp::getdate}.
@throws CException if "seconds" pattern is unknown
@return string seconds
|
[
"Get",
"the",
"seconds",
".",
"s",
"for",
"non",
"-",
"padding",
"ss",
"will",
"always",
"return",
"2",
"characters",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CDateFormatter.php#L472-L481
|
train
|
yiisoft/yii
|
framework/i18n/CDateFormatter.php
|
CDateFormatter.formatWeekInYear
|
protected function formatWeekInYear($pattern,$date)
{
if($pattern==='w')
return @date('W',@mktime(0,0,0,$date['mon'],$date['mday'],$date['year']));
else
throw new CException(Yii::t('yii','The pattern for week in year must be "w".'));
}
|
php
|
protected function formatWeekInYear($pattern,$date)
{
if($pattern==='w')
return @date('W',@mktime(0,0,0,$date['mon'],$date['mday'],$date['year']));
else
throw new CException(Yii::t('yii','The pattern for week in year must be "w".'));
}
|
[
"protected",
"function",
"formatWeekInYear",
"(",
"$",
"pattern",
",",
"$",
"date",
")",
"{",
"if",
"(",
"$",
"pattern",
"===",
"'w'",
")",
"return",
"@",
"date",
"(",
"'W'",
",",
"@",
"mktime",
"(",
"0",
",",
"0",
",",
"0",
",",
"$",
"date",
"[",
"'mon'",
"]",
",",
"$",
"date",
"[",
"'mday'",
"]",
",",
"$",
"date",
"[",
"'year'",
"]",
")",
")",
";",
"else",
"throw",
"new",
"CException",
"(",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'The pattern for week in year must be \"w\".'",
")",
")",
";",
"}"
] |
Get the week in the year.
@param string $pattern a pattern.
@param array $date result of {@link CTimestamp::getdate}.
@throws CException if "weekInYear" pattern is unknown
@return integer week in year
|
[
"Get",
"the",
"week",
"in",
"the",
"year",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CDateFormatter.php#L490-L496
|
train
|
yiisoft/yii
|
framework/i18n/CDateFormatter.php
|
CDateFormatter.formatWeekInMonth
|
protected function formatWeekInMonth($pattern,$date)
{
if($pattern==='W')
{
$weekDay=date('N',mktime(0,0,0,$date['mon'],1,$date['year']));
return floor(($weekDay+$date['mday']-2)/7)+1;
}
else
throw new CException(Yii::t('yii','The pattern for week in month must be "W".'));
}
|
php
|
protected function formatWeekInMonth($pattern,$date)
{
if($pattern==='W')
{
$weekDay=date('N',mktime(0,0,0,$date['mon'],1,$date['year']));
return floor(($weekDay+$date['mday']-2)/7)+1;
}
else
throw new CException(Yii::t('yii','The pattern for week in month must be "W".'));
}
|
[
"protected",
"function",
"formatWeekInMonth",
"(",
"$",
"pattern",
",",
"$",
"date",
")",
"{",
"if",
"(",
"$",
"pattern",
"===",
"'W'",
")",
"{",
"$",
"weekDay",
"=",
"date",
"(",
"'N'",
",",
"mktime",
"(",
"0",
",",
"0",
",",
"0",
",",
"$",
"date",
"[",
"'mon'",
"]",
",",
"1",
",",
"$",
"date",
"[",
"'year'",
"]",
")",
")",
";",
"return",
"floor",
"(",
"(",
"$",
"weekDay",
"+",
"$",
"date",
"[",
"'mday'",
"]",
"-",
"2",
")",
"/",
"7",
")",
"+",
"1",
";",
"}",
"else",
"throw",
"new",
"CException",
"(",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'The pattern for week in month must be \"W\".'",
")",
")",
";",
"}"
] |
Get week in the month.
@param array $pattern result of {@link CTimestamp::getdate}.
@param string $date a pattern.
@throws CException if "weekInMonth" pattern is unknown
@return integer week in month
|
[
"Get",
"week",
"in",
"the",
"month",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CDateFormatter.php#L505-L514
|
train
|
yiisoft/yii
|
framework/i18n/CDateFormatter.php
|
CDateFormatter.formatTimeZone
|
protected function formatTimeZone($pattern,$date)
{
if($pattern[0]==='z' || $pattern[0]==='v')
return @date('T', @mktime($date['hours'], $date['minutes'], $date['seconds'], $date['mon'], $date['mday'], $date['year']));
elseif($pattern[0]==='Z')
return @date('P', @mktime($date['hours'], $date['minutes'], $date['seconds'], $date['mon'], $date['mday'], $date['year']));
else
throw new CException(Yii::t('yii','The pattern for time zone must be "z" or "v".'));
}
|
php
|
protected function formatTimeZone($pattern,$date)
{
if($pattern[0]==='z' || $pattern[0]==='v')
return @date('T', @mktime($date['hours'], $date['minutes'], $date['seconds'], $date['mon'], $date['mday'], $date['year']));
elseif($pattern[0]==='Z')
return @date('P', @mktime($date['hours'], $date['minutes'], $date['seconds'], $date['mon'], $date['mday'], $date['year']));
else
throw new CException(Yii::t('yii','The pattern for time zone must be "z" or "v".'));
}
|
[
"protected",
"function",
"formatTimeZone",
"(",
"$",
"pattern",
",",
"$",
"date",
")",
"{",
"if",
"(",
"$",
"pattern",
"[",
"0",
"]",
"===",
"'z'",
"||",
"$",
"pattern",
"[",
"0",
"]",
"===",
"'v'",
")",
"return",
"@",
"date",
"(",
"'T'",
",",
"@",
"mktime",
"(",
"$",
"date",
"[",
"'hours'",
"]",
",",
"$",
"date",
"[",
"'minutes'",
"]",
",",
"$",
"date",
"[",
"'seconds'",
"]",
",",
"$",
"date",
"[",
"'mon'",
"]",
",",
"$",
"date",
"[",
"'mday'",
"]",
",",
"$",
"date",
"[",
"'year'",
"]",
")",
")",
";",
"elseif",
"(",
"$",
"pattern",
"[",
"0",
"]",
"===",
"'Z'",
")",
"return",
"@",
"date",
"(",
"'P'",
",",
"@",
"mktime",
"(",
"$",
"date",
"[",
"'hours'",
"]",
",",
"$",
"date",
"[",
"'minutes'",
"]",
",",
"$",
"date",
"[",
"'seconds'",
"]",
",",
"$",
"date",
"[",
"'mon'",
"]",
",",
"$",
"date",
"[",
"'mday'",
"]",
",",
"$",
"date",
"[",
"'year'",
"]",
")",
")",
";",
"else",
"throw",
"new",
"CException",
"(",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'The pattern for time zone must be \"z\" or \"v\".'",
")",
")",
";",
"}"
] |
Get the timezone of the server machine.
@param string $pattern a pattern.
@param array $date result of {@link CTimestamp::getdate}.
@throws CException if "timeZone" pattern is unknown
@return string time zone
@todo How to get the timezone for a different region?
|
[
"Get",
"the",
"timezone",
"of",
"the",
"server",
"machine",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CDateFormatter.php#L524-L532
|
train
|
yiisoft/yii
|
framework/i18n/CDateFormatter.php
|
CDateFormatter.formatEra
|
protected function formatEra($pattern,$date)
{
$era=$date['year']>0 ? 1 : 0;
switch($pattern)
{
case 'G':
case 'GG':
case 'GGG':
return $this->_locale->getEraName($era,'abbreviated');
case 'GGGG':
return $this->_locale->getEraName($era,'wide');
case 'GGGGG':
return $this->_locale->getEraName($era,'narrow');
default:
throw new CException(Yii::t('yii','The pattern for era must be "G", "GG", "GGG", "GGGG" or "GGGGG".'));
}
}
|
php
|
protected function formatEra($pattern,$date)
{
$era=$date['year']>0 ? 1 : 0;
switch($pattern)
{
case 'G':
case 'GG':
case 'GGG':
return $this->_locale->getEraName($era,'abbreviated');
case 'GGGG':
return $this->_locale->getEraName($era,'wide');
case 'GGGGG':
return $this->_locale->getEraName($era,'narrow');
default:
throw new CException(Yii::t('yii','The pattern for era must be "G", "GG", "GGG", "GGGG" or "GGGGG".'));
}
}
|
[
"protected",
"function",
"formatEra",
"(",
"$",
"pattern",
",",
"$",
"date",
")",
"{",
"$",
"era",
"=",
"$",
"date",
"[",
"'year'",
"]",
">",
"0",
"?",
"1",
":",
"0",
";",
"switch",
"(",
"$",
"pattern",
")",
"{",
"case",
"'G'",
":",
"case",
"'GG'",
":",
"case",
"'GGG'",
":",
"return",
"$",
"this",
"->",
"_locale",
"->",
"getEraName",
"(",
"$",
"era",
",",
"'abbreviated'",
")",
";",
"case",
"'GGGG'",
":",
"return",
"$",
"this",
"->",
"_locale",
"->",
"getEraName",
"(",
"$",
"era",
",",
"'wide'",
")",
";",
"case",
"'GGGGG'",
":",
"return",
"$",
"this",
"->",
"_locale",
"->",
"getEraName",
"(",
"$",
"era",
",",
"'narrow'",
")",
";",
"default",
":",
"throw",
"new",
"CException",
"(",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'The pattern for era must be \"G\", \"GG\", \"GGG\", \"GGGG\" or \"GGGGG\".'",
")",
")",
";",
"}",
"}"
] |
Get the era. i.e. in gregorian, year > 0 is AD, else BC.
@param string $pattern a pattern.
@param array $date result of {@link CTimestamp::getdate}.
@throws CException if "era" pattern is unknown
@return string era
@todo How to support multiple Eras?, e.g. Japanese.
|
[
"Get",
"the",
"era",
".",
"i",
".",
"e",
".",
"in",
"gregorian",
"year",
">",
"0",
"is",
"AD",
"else",
"BC",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/i18n/CDateFormatter.php#L542-L558
|
train
|
yiisoft/yii
|
framework/logging/CFileLogRoute.php
|
CFileLogRoute.processLogs
|
protected function processLogs($logs)
{
$text='';
foreach($logs as $log)
$text.=$this->formatLogMessage($log[0],$log[1],$log[2],$log[3]);
$logFile=$this->getLogPath().DIRECTORY_SEPARATOR.$this->getLogFile();
$fp=@fopen($logFile,'a');
@flock($fp,LOCK_EX);
if(@filesize($logFile)>$this->getMaxFileSize()*1024)
{
$this->rotateFiles();
@flock($fp,LOCK_UN);
@fclose($fp);
@file_put_contents($logFile,$text,FILE_APPEND|LOCK_EX);
}
else
{
@fwrite($fp,$text);
@flock($fp,LOCK_UN);
@fclose($fp);
}
}
|
php
|
protected function processLogs($logs)
{
$text='';
foreach($logs as $log)
$text.=$this->formatLogMessage($log[0],$log[1],$log[2],$log[3]);
$logFile=$this->getLogPath().DIRECTORY_SEPARATOR.$this->getLogFile();
$fp=@fopen($logFile,'a');
@flock($fp,LOCK_EX);
if(@filesize($logFile)>$this->getMaxFileSize()*1024)
{
$this->rotateFiles();
@flock($fp,LOCK_UN);
@fclose($fp);
@file_put_contents($logFile,$text,FILE_APPEND|LOCK_EX);
}
else
{
@fwrite($fp,$text);
@flock($fp,LOCK_UN);
@fclose($fp);
}
}
|
[
"protected",
"function",
"processLogs",
"(",
"$",
"logs",
")",
"{",
"$",
"text",
"=",
"''",
";",
"foreach",
"(",
"$",
"logs",
"as",
"$",
"log",
")",
"$",
"text",
".=",
"$",
"this",
"->",
"formatLogMessage",
"(",
"$",
"log",
"[",
"0",
"]",
",",
"$",
"log",
"[",
"1",
"]",
",",
"$",
"log",
"[",
"2",
"]",
",",
"$",
"log",
"[",
"3",
"]",
")",
";",
"$",
"logFile",
"=",
"$",
"this",
"->",
"getLogPath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"getLogFile",
"(",
")",
";",
"$",
"fp",
"=",
"@",
"fopen",
"(",
"$",
"logFile",
",",
"'a'",
")",
";",
"@",
"flock",
"(",
"$",
"fp",
",",
"LOCK_EX",
")",
";",
"if",
"(",
"@",
"filesize",
"(",
"$",
"logFile",
")",
">",
"$",
"this",
"->",
"getMaxFileSize",
"(",
")",
"*",
"1024",
")",
"{",
"$",
"this",
"->",
"rotateFiles",
"(",
")",
";",
"@",
"flock",
"(",
"$",
"fp",
",",
"LOCK_UN",
")",
";",
"@",
"fclose",
"(",
"$",
"fp",
")",
";",
"@",
"file_put_contents",
"(",
"$",
"logFile",
",",
"$",
"text",
",",
"FILE_APPEND",
"|",
"LOCK_EX",
")",
";",
"}",
"else",
"{",
"@",
"fwrite",
"(",
"$",
"fp",
",",
"$",
"text",
")",
";",
"@",
"flock",
"(",
"$",
"fp",
",",
"LOCK_UN",
")",
";",
"@",
"fclose",
"(",
"$",
"fp",
")",
";",
"}",
"}"
] |
Saves log messages in files.
@param array $logs list of log messages
|
[
"Saves",
"log",
"messages",
"in",
"files",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/logging/CFileLogRoute.php#L144-L166
|
train
|
yiisoft/yii
|
framework/web/helpers/CGoogleApi.php
|
CGoogleApi.init
|
public static function init($apiKey=null)
{
if($apiKey===null)
return CHtml::scriptFile(self::$bootstrapUrl);
else
return CHtml::scriptFile(self::$bootstrapUrl.'?key='.$apiKey);
}
|
php
|
public static function init($apiKey=null)
{
if($apiKey===null)
return CHtml::scriptFile(self::$bootstrapUrl);
else
return CHtml::scriptFile(self::$bootstrapUrl.'?key='.$apiKey);
}
|
[
"public",
"static",
"function",
"init",
"(",
"$",
"apiKey",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"apiKey",
"===",
"null",
")",
"return",
"CHtml",
"::",
"scriptFile",
"(",
"self",
"::",
"$",
"bootstrapUrl",
")",
";",
"else",
"return",
"CHtml",
"::",
"scriptFile",
"(",
"self",
"::",
"$",
"bootstrapUrl",
".",
"'?key='",
".",
"$",
"apiKey",
")",
";",
"}"
] |
Renders the jsapi script file.
@param string $apiKey the API key. Null if you do not have a key.
@return string the script tag that loads Google jsapi.
|
[
"Renders",
"the",
"jsapi",
"script",
"file",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/helpers/CGoogleApi.php#L30-L36
|
train
|
yiisoft/yii
|
demos/blog/protected/models/Tag.php
|
Tag.findTagWeights
|
public function findTagWeights($limit=20)
{
$models=$this->findAll(array(
'order'=>'frequency DESC',
'limit'=>$limit,
));
$total=0;
foreach($models as $model)
$total+=$model->frequency;
$tags=array();
if($total>0)
{
foreach($models as $model)
$tags[$model->name]=8+(int)(16*$model->frequency/($total+10));
ksort($tags);
}
return $tags;
}
|
php
|
public function findTagWeights($limit=20)
{
$models=$this->findAll(array(
'order'=>'frequency DESC',
'limit'=>$limit,
));
$total=0;
foreach($models as $model)
$total+=$model->frequency;
$tags=array();
if($total>0)
{
foreach($models as $model)
$tags[$model->name]=8+(int)(16*$model->frequency/($total+10));
ksort($tags);
}
return $tags;
}
|
[
"public",
"function",
"findTagWeights",
"(",
"$",
"limit",
"=",
"20",
")",
"{",
"$",
"models",
"=",
"$",
"this",
"->",
"findAll",
"(",
"array",
"(",
"'order'",
"=>",
"'frequency DESC'",
",",
"'limit'",
"=>",
"$",
"limit",
",",
")",
")",
";",
"$",
"total",
"=",
"0",
";",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"$",
"total",
"+=",
"$",
"model",
"->",
"frequency",
";",
"$",
"tags",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"total",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"$",
"tags",
"[",
"$",
"model",
"->",
"name",
"]",
"=",
"8",
"+",
"(",
"int",
")",
"(",
"16",
"*",
"$",
"model",
"->",
"frequency",
"/",
"(",
"$",
"total",
"+",
"10",
")",
")",
";",
"ksort",
"(",
"$",
"tags",
")",
";",
"}",
"return",
"$",
"tags",
";",
"}"
] |
Returns tag names and their corresponding weights.
Only the tags with the top weights will be returned.
@param integer the maximum number of tags that should be returned
@return array weights indexed by tag names.
|
[
"Returns",
"tag",
"names",
"and",
"their",
"corresponding",
"weights",
".",
"Only",
"the",
"tags",
"with",
"the",
"top",
"weights",
"will",
"be",
"returned",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/demos/blog/protected/models/Tag.php#L70-L89
|
train
|
yiisoft/yii
|
framework/web/CAssetManager.php
|
CAssetManager.setBasePath
|
public function setBasePath($value)
{
if(($basePath=realpath($value))!==false && is_dir($basePath) && is_writable($basePath))
$this->_basePath=$basePath;
else
throw new CException(Yii::t('yii','CAssetManager.basePath "{path}" is invalid. Please make sure the directory exists and is writable by the Web server process.',
array('{path}'=>$value)));
}
|
php
|
public function setBasePath($value)
{
if(($basePath=realpath($value))!==false && is_dir($basePath) && is_writable($basePath))
$this->_basePath=$basePath;
else
throw new CException(Yii::t('yii','CAssetManager.basePath "{path}" is invalid. Please make sure the directory exists and is writable by the Web server process.',
array('{path}'=>$value)));
}
|
[
"public",
"function",
"setBasePath",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"(",
"$",
"basePath",
"=",
"realpath",
"(",
"$",
"value",
")",
")",
"!==",
"false",
"&&",
"is_dir",
"(",
"$",
"basePath",
")",
"&&",
"is_writable",
"(",
"$",
"basePath",
")",
")",
"$",
"this",
"->",
"_basePath",
"=",
"$",
"basePath",
";",
"else",
"throw",
"new",
"CException",
"(",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'CAssetManager.basePath \"{path}\" is invalid. Please make sure the directory exists and is writable by the Web server process.'",
",",
"array",
"(",
"'{path}'",
"=>",
"$",
"value",
")",
")",
")",
";",
"}"
] |
Sets the root directory storing published asset files.
@param string $value the root directory storing published asset files
@throws CException if the base path is invalid
|
[
"Sets",
"the",
"root",
"directory",
"storing",
"published",
"asset",
"files",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CAssetManager.php#L133-L140
|
train
|
yiisoft/yii
|
framework/web/CAssetManager.php
|
CAssetManager.getPublishedUrl
|
public function getPublishedUrl($path,$hashByName=false)
{
if(isset($this->_published[$path]))
return $this->_published[$path];
if(is_string($path) && ($path=realpath($path))!==false)
{
$base=$this->getBaseUrl().'/'.$this->generatePath($path,$hashByName);
return is_file($path) ? $base.'/'.basename($path) : $base;
}
else
return false;
}
|
php
|
public function getPublishedUrl($path,$hashByName=false)
{
if(isset($this->_published[$path]))
return $this->_published[$path];
if(is_string($path) && ($path=realpath($path))!==false)
{
$base=$this->getBaseUrl().'/'.$this->generatePath($path,$hashByName);
return is_file($path) ? $base.'/'.basename($path) : $base;
}
else
return false;
}
|
[
"public",
"function",
"getPublishedUrl",
"(",
"$",
"path",
",",
"$",
"hashByName",
"=",
"false",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_published",
"[",
"$",
"path",
"]",
")",
")",
"return",
"$",
"this",
"->",
"_published",
"[",
"$",
"path",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"path",
")",
"&&",
"(",
"$",
"path",
"=",
"realpath",
"(",
"$",
"path",
")",
")",
"!==",
"false",
")",
"{",
"$",
"base",
"=",
"$",
"this",
"->",
"getBaseUrl",
"(",
")",
".",
"'/'",
".",
"$",
"this",
"->",
"generatePath",
"(",
"$",
"path",
",",
"$",
"hashByName",
")",
";",
"return",
"is_file",
"(",
"$",
"path",
")",
"?",
"$",
"base",
".",
"'/'",
".",
"basename",
"(",
"$",
"path",
")",
":",
"$",
"base",
";",
"}",
"else",
"return",
"false",
";",
"}"
] |
Returns the URL of a published file path.
This method does not perform any publishing. It merely tells you
if the file path is published, what the URL will be to access it.
@param string $path directory or file path being published
@param boolean $hashByName whether the published directory should be named as the hashed basename.
If false, the name will be the hash taken from dirname of the path being published and path mtime.
Defaults to false. Set true if the path being published is shared among
different extensions.
@return string the published URL for the file or directory. False if the file or directory does not exist.
|
[
"Returns",
"the",
"URL",
"of",
"a",
"published",
"file",
"path",
".",
"This",
"method",
"does",
"not",
"perform",
"any",
"publishing",
".",
"It",
"merely",
"tells",
"you",
"if",
"the",
"file",
"path",
"is",
"published",
"what",
"the",
"URL",
"will",
"be",
"to",
"access",
"it",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CAssetManager.php#L294-L305
|
train
|
yiisoft/yii
|
framework/web/CAssetManager.php
|
CAssetManager.generatePath
|
protected function generatePath($file,$hashByName=false)
{
if (is_file($file))
$pathForHashing=$hashByName ? dirname($file) : dirname($file).filemtime($file);
else
$pathForHashing=$hashByName ? $file : $file.filemtime($file);
return $this->hash($pathForHashing);
}
|
php
|
protected function generatePath($file,$hashByName=false)
{
if (is_file($file))
$pathForHashing=$hashByName ? dirname($file) : dirname($file).filemtime($file);
else
$pathForHashing=$hashByName ? $file : $file.filemtime($file);
return $this->hash($pathForHashing);
}
|
[
"protected",
"function",
"generatePath",
"(",
"$",
"file",
",",
"$",
"hashByName",
"=",
"false",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"file",
")",
")",
"$",
"pathForHashing",
"=",
"$",
"hashByName",
"?",
"dirname",
"(",
"$",
"file",
")",
":",
"dirname",
"(",
"$",
"file",
")",
".",
"filemtime",
"(",
"$",
"file",
")",
";",
"else",
"$",
"pathForHashing",
"=",
"$",
"hashByName",
"?",
"$",
"file",
":",
"$",
"file",
".",
"filemtime",
"(",
"$",
"file",
")",
";",
"return",
"$",
"this",
"->",
"hash",
"(",
"$",
"pathForHashing",
")",
";",
"}"
] |
Generates path segments relative to basePath.
@param string $file for which public path will be created.
@param bool $hashByName whether the published directory should be named as the hashed basename.
@return string path segments without basePath.
@since 1.1.13
|
[
"Generates",
"path",
"segments",
"relative",
"to",
"basePath",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/CAssetManager.php#L325-L333
|
train
|
yiisoft/yii
|
framework/gii/CCodeModel.php
|
CCodeModel.sticky
|
public function sticky($attribute,$params)
{
if(!$this->hasErrors())
$this->_stickyAttributes[$attribute]=$this->$attribute;
}
|
php
|
public function sticky($attribute,$params)
{
if(!$this->hasErrors())
$this->_stickyAttributes[$attribute]=$this->$attribute;
}
|
[
"public",
"function",
"sticky",
"(",
"$",
"attribute",
",",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasErrors",
"(",
")",
")",
"$",
"this",
"->",
"_stickyAttributes",
"[",
"$",
"attribute",
"]",
"=",
"$",
"this",
"->",
"$",
"attribute",
";",
"}"
] |
The "sticky" validator.
This validator does not really validate the attributes.
It actually saves the attribute value in a file to make it sticky.
@param string $attribute the attribute to be validated
@param array $params the validation parameters
|
[
"The",
"sticky",
"validator",
".",
"This",
"validator",
"does",
"not",
"really",
"validate",
"the",
"attributes",
".",
"It",
"actually",
"saves",
"the",
"attribute",
"value",
"in",
"a",
"file",
"to",
"make",
"it",
"sticky",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/gii/CCodeModel.php#L353-L357
|
train
|
yiisoft/yii
|
framework/gii/CCodeModel.php
|
CCodeModel.loadStickyAttributes
|
public function loadStickyAttributes()
{
$this->_stickyAttributes=array();
$path=$this->getStickyFile();
if(is_file($path))
{
$result=@include($path);
if(is_array($result))
{
$this->_stickyAttributes=$result;
foreach($this->_stickyAttributes as $name=>$value)
{
if(property_exists($this,$name) || $this->canSetProperty($name))
$this->$name=$value;
}
}
}
}
|
php
|
public function loadStickyAttributes()
{
$this->_stickyAttributes=array();
$path=$this->getStickyFile();
if(is_file($path))
{
$result=@include($path);
if(is_array($result))
{
$this->_stickyAttributes=$result;
foreach($this->_stickyAttributes as $name=>$value)
{
if(property_exists($this,$name) || $this->canSetProperty($name))
$this->$name=$value;
}
}
}
}
|
[
"public",
"function",
"loadStickyAttributes",
"(",
")",
"{",
"$",
"this",
"->",
"_stickyAttributes",
"=",
"array",
"(",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"getStickyFile",
"(",
")",
";",
"if",
"(",
"is_file",
"(",
"$",
"path",
")",
")",
"{",
"$",
"result",
"=",
"@",
"include",
"(",
"$",
"path",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"result",
")",
")",
"{",
"$",
"this",
"->",
"_stickyAttributes",
"=",
"$",
"result",
";",
"foreach",
"(",
"$",
"this",
"->",
"_stickyAttributes",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"$",
"name",
")",
"||",
"$",
"this",
"->",
"canSetProperty",
"(",
"$",
"name",
")",
")",
"$",
"this",
"->",
"$",
"name",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"}"
] |
Loads sticky attributes from a file and populates them into the model.
|
[
"Loads",
"sticky",
"attributes",
"from",
"a",
"file",
"and",
"populates",
"them",
"into",
"the",
"model",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/gii/CCodeModel.php#L362-L379
|
train
|
yiisoft/yii
|
framework/gii/CCodeModel.php
|
CCodeModel.saveStickyAttributes
|
public function saveStickyAttributes()
{
$path=$this->getStickyFile();
@mkdir(dirname($path),0755,true);
file_put_contents($path,"<?php\nreturn ".var_export($this->_stickyAttributes,true).";\n");
}
|
php
|
public function saveStickyAttributes()
{
$path=$this->getStickyFile();
@mkdir(dirname($path),0755,true);
file_put_contents($path,"<?php\nreturn ".var_export($this->_stickyAttributes,true).";\n");
}
|
[
"public",
"function",
"saveStickyAttributes",
"(",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getStickyFile",
"(",
")",
";",
"@",
"mkdir",
"(",
"dirname",
"(",
"$",
"path",
")",
",",
"0755",
",",
"true",
")",
";",
"file_put_contents",
"(",
"$",
"path",
",",
"\"<?php\\nreturn \"",
".",
"var_export",
"(",
"$",
"this",
"->",
"_stickyAttributes",
",",
"true",
")",
".",
"\";\\n\"",
")",
";",
"}"
] |
Saves sticky attributes into a file.
|
[
"Saves",
"sticky",
"attributes",
"into",
"a",
"file",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/gii/CCodeModel.php#L384-L389
|
train
|
yiisoft/yii
|
framework/gii/CCodeModel.php
|
CCodeModel.class2name
|
public function class2name($name,$ucwords=true)
{
$result=trim(strtolower(str_replace('_',' ',preg_replace('/(?<![A-Z])[A-Z]/', ' \0', $name))));
return $ucwords ? ucwords($result) : $result;
}
|
php
|
public function class2name($name,$ucwords=true)
{
$result=trim(strtolower(str_replace('_',' ',preg_replace('/(?<![A-Z])[A-Z]/', ' \0', $name))));
return $ucwords ? ucwords($result) : $result;
}
|
[
"public",
"function",
"class2name",
"(",
"$",
"name",
",",
"$",
"ucwords",
"=",
"true",
")",
"{",
"$",
"result",
"=",
"trim",
"(",
"strtolower",
"(",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"preg_replace",
"(",
"'/(?<![A-Z])[A-Z]/'",
",",
"' \\0'",
",",
"$",
"name",
")",
")",
")",
")",
";",
"return",
"$",
"ucwords",
"?",
"ucwords",
"(",
"$",
"result",
")",
":",
"$",
"result",
";",
"}"
] |
Converts a class name into space-separated words.
For example, 'PostTag' will be converted as 'Post Tag'.
@param string $name the string to be converted
@param boolean $ucwords whether to capitalize the first letter in each word
@return string the resulting words
|
[
"Converts",
"a",
"class",
"name",
"into",
"space",
"-",
"separated",
"words",
".",
"For",
"example",
"PostTag",
"will",
"be",
"converted",
"as",
"Post",
"Tag",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/gii/CCodeModel.php#L454-L458
|
train
|
yiisoft/yii
|
framework/gii/CCodeModel.php
|
CCodeModel.validateReservedWord
|
public function validateReservedWord($attribute,$params)
{
$value=$this->$attribute;
if(in_array(strtolower($value),self::$keywords))
$this->addError($attribute, $this->getAttributeLabel($attribute).' cannot take a reserved PHP keyword.');
}
|
php
|
public function validateReservedWord($attribute,$params)
{
$value=$this->$attribute;
if(in_array(strtolower($value),self::$keywords))
$this->addError($attribute, $this->getAttributeLabel($attribute).' cannot take a reserved PHP keyword.');
}
|
[
"public",
"function",
"validateReservedWord",
"(",
"$",
"attribute",
",",
"$",
"params",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"$",
"attribute",
";",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"value",
")",
",",
"self",
"::",
"$",
"keywords",
")",
")",
"$",
"this",
"->",
"addError",
"(",
"$",
"attribute",
",",
"$",
"this",
"->",
"getAttributeLabel",
"(",
"$",
"attribute",
")",
".",
"' cannot take a reserved PHP keyword.'",
")",
";",
"}"
] |
Validates an attribute to make sure it is not taking a PHP reserved keyword.
@param string $attribute the attribute to be validated
@param array $params validation parameters
|
[
"Validates",
"an",
"attribute",
"to",
"make",
"sure",
"it",
"is",
"not",
"taking",
"a",
"PHP",
"reserved",
"keyword",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/gii/CCodeModel.php#L478-L483
|
train
|
yiisoft/yii
|
framework/web/widgets/CActiveForm.php
|
CActiveForm.validate
|
public static function validate($models, $attributes=null, $loadInput=true)
{
$result=array();
if(!is_array($models))
$models=array($models);
foreach($models as $model)
{
$modelName=CHtml::modelName($model);
if($loadInput && isset($_POST[$modelName]))
$model->attributes=$_POST[$modelName];
$model->validate($attributes);
foreach($model->getErrors() as $attribute=>$errors)
$result[CHtml::activeId($model,$attribute)]=$errors;
}
return function_exists('json_encode') ? json_encode($result) : CJSON::encode($result);
}
|
php
|
public static function validate($models, $attributes=null, $loadInput=true)
{
$result=array();
if(!is_array($models))
$models=array($models);
foreach($models as $model)
{
$modelName=CHtml::modelName($model);
if($loadInput && isset($_POST[$modelName]))
$model->attributes=$_POST[$modelName];
$model->validate($attributes);
foreach($model->getErrors() as $attribute=>$errors)
$result[CHtml::activeId($model,$attribute)]=$errors;
}
return function_exists('json_encode') ? json_encode($result) : CJSON::encode($result);
}
|
[
"public",
"static",
"function",
"validate",
"(",
"$",
"models",
",",
"$",
"attributes",
"=",
"null",
",",
"$",
"loadInput",
"=",
"true",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"models",
")",
")",
"$",
"models",
"=",
"array",
"(",
"$",
"models",
")",
";",
"foreach",
"(",
"$",
"models",
"as",
"$",
"model",
")",
"{",
"$",
"modelName",
"=",
"CHtml",
"::",
"modelName",
"(",
"$",
"model",
")",
";",
"if",
"(",
"$",
"loadInput",
"&&",
"isset",
"(",
"$",
"_POST",
"[",
"$",
"modelName",
"]",
")",
")",
"$",
"model",
"->",
"attributes",
"=",
"$",
"_POST",
"[",
"$",
"modelName",
"]",
";",
"$",
"model",
"->",
"validate",
"(",
"$",
"attributes",
")",
";",
"foreach",
"(",
"$",
"model",
"->",
"getErrors",
"(",
")",
"as",
"$",
"attribute",
"=>",
"$",
"errors",
")",
"$",
"result",
"[",
"CHtml",
"::",
"activeId",
"(",
"$",
"model",
",",
"$",
"attribute",
")",
"]",
"=",
"$",
"errors",
";",
"}",
"return",
"function_exists",
"(",
"'json_encode'",
")",
"?",
"json_encode",
"(",
"$",
"result",
")",
":",
"CJSON",
"::",
"encode",
"(",
"$",
"result",
")",
";",
"}"
] |
Validates one or several models and returns the results in JSON format.
This is a helper method that simplifies the way of writing AJAX validation code.
@param mixed $models a single model instance or an array of models.
@param array $attributes list of attributes that should be validated. Defaults to null,
meaning any attribute listed in the applicable validation rules of the models should be
validated. If this parameter is given as a list of attributes, only
the listed attributes will be validated.
@param boolean $loadInput whether to load the data from $_POST array in this method.
If this is true, the model will be populated from <code>$_POST[ModelClass]</code>.
@return string the JSON representation of the validation error messages.
|
[
"Validates",
"one",
"or",
"several",
"models",
"and",
"returns",
"the",
"results",
"in",
"JSON",
"format",
".",
"This",
"is",
"a",
"helper",
"method",
"that",
"simplifies",
"the",
"way",
"of",
"writing",
"AJAX",
"validation",
"code",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/widgets/CActiveForm.php#L977-L992
|
train
|
yiisoft/yii
|
framework/web/widgets/captcha/CCaptcha.php
|
CCaptcha.registerClientScript
|
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);
}
|
php
|
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);
}
|
[
"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",
".=",
"\"\njQuery(document).on('click', '$selector', function(){\n\tjQuery.ajax({\n\t\turl: \"",
".",
"CJSON",
"::",
"encode",
"(",
"$",
"url",
")",
".",
"\",\n\t\tdataType: 'json',\n\t\tcache: false,\n\t\tsuccess: function(data) {\n\t\t\tjQuery('#$id').attr('src', data['url']);\n\t\t\tjQuery('body').data('{$this->captchaAction}.hash', [data['hash1'], data['hash2']]);\n\t\t}\n\t});\n\treturn false;\n});\n\"",
";",
"$",
"cs",
"->",
"registerScript",
"(",
"'Yii.CCaptcha#'",
".",
"$",
"id",
",",
"$",
"js",
")",
";",
"}"
] |
Registers the needed client scripts.
|
[
"Registers",
"the",
"needed",
"client",
"scripts",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/widgets/captcha/CCaptcha.php#L110-L156
|
train
|
yiisoft/yii
|
framework/web/widgets/captcha/CCaptcha.php
|
CCaptcha.checkRequirements
|
public static function checkRequirements($extension=null)
{
if(extension_loaded('imagick'))
{
$imagick=new 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;
}
|
php
|
public static function checkRequirements($extension=null)
{
if(extension_loaded('imagick'))
{
$imagick=new 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;
}
|
[
"public",
"static",
"function",
"checkRequirements",
"(",
"$",
"extension",
"=",
"null",
")",
"{",
"if",
"(",
"extension_loaded",
"(",
"'imagick'",
")",
")",
"{",
"$",
"imagick",
"=",
"new",
"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
|
[
"Checks",
"if",
"specified",
"graphic",
"extension",
"support",
"is",
"loaded",
"."
] |
af3cbce71db83c4476c8a4289517b2984c740f31
|
https://github.com/yiisoft/yii/blob/af3cbce71db83c4476c8a4289517b2984c740f31/framework/web/widgets/captcha/CCaptcha.php#L167-L190
|
train
|
sendgrid/sendgrid-php
|
lib/mail/SpamCheck.php
|
SpamCheck.jsonSerialize
|
public function jsonSerialize()
{
return array_filter(
[
'enable' => $this->getEnable(),
'threshold' => $this->getThreshold(),
'post_to_url' => $this->getPostToUrl()
],
function ($value) {
return $value !== null;
}
) ?: null;
}
|
php
|
public function jsonSerialize()
{
return array_filter(
[
'enable' => $this->getEnable(),
'threshold' => $this->getThreshold(),
'post_to_url' => $this->getPostToUrl()
],
function ($value) {
return $value !== null;
}
) ?: null;
}
|
[
"public",
"function",
"jsonSerialize",
"(",
")",
"{",
"return",
"array_filter",
"(",
"[",
"'enable'",
"=>",
"$",
"this",
"->",
"getEnable",
"(",
")",
",",
"'threshold'",
"=>",
"$",
"this",
"->",
"getThreshold",
"(",
")",
",",
"'post_to_url'",
"=>",
"$",
"this",
"->",
"getPostToUrl",
"(",
")",
"]",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"value",
"!==",
"null",
";",
"}",
")",
"?",
":",
"null",
";",
"}"
] |
Return an array representing a SpamCheck object for the Twilio SendGrid API
@return null|array
|
[
"Return",
"an",
"array",
"representing",
"a",
"SpamCheck",
"object",
"for",
"the",
"Twilio",
"SendGrid",
"API"
] |
37fa19d3ae019842f07a2a43e92ed0f566ad927d
|
https://github.com/sendgrid/sendgrid-php/blob/37fa19d3ae019842f07a2a43e92ed0f566ad927d/lib/mail/SpamCheck.php#L148-L160
|
train
|
sendgrid/sendgrid-php
|
lib/mail/TrackingSettings.php
|
TrackingSettings.setGanalytics
|
public function setGanalytics(
$enable,
$utm_source = null,
$utm_medium = null,
$utm_term = null,
$utm_content = null,
$utm_campaign = null
) {
if ($enable instanceof Ganalytics) {
$ganalytics = $enable;
$this->ganalytics = $ganalytics;
return;
}
$this->ganalytics = new Ganalytics(
$enable,
$utm_source,
$utm_medium,
$utm_term,
$utm_content,
$utm_campaign
);
}
|
php
|
public function setGanalytics(
$enable,
$utm_source = null,
$utm_medium = null,
$utm_term = null,
$utm_content = null,
$utm_campaign = null
) {
if ($enable instanceof Ganalytics) {
$ganalytics = $enable;
$this->ganalytics = $ganalytics;
return;
}
$this->ganalytics = new Ganalytics(
$enable,
$utm_source,
$utm_medium,
$utm_term,
$utm_content,
$utm_campaign
);
}
|
[
"public",
"function",
"setGanalytics",
"(",
"$",
"enable",
",",
"$",
"utm_source",
"=",
"null",
",",
"$",
"utm_medium",
"=",
"null",
",",
"$",
"utm_term",
"=",
"null",
",",
"$",
"utm_content",
"=",
"null",
",",
"$",
"utm_campaign",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"enable",
"instanceof",
"Ganalytics",
")",
"{",
"$",
"ganalytics",
"=",
"$",
"enable",
";",
"$",
"this",
"->",
"ganalytics",
"=",
"$",
"ganalytics",
";",
"return",
";",
"}",
"$",
"this",
"->",
"ganalytics",
"=",
"new",
"Ganalytics",
"(",
"$",
"enable",
",",
"$",
"utm_source",
",",
"$",
"utm_medium",
",",
"$",
"utm_term",
",",
"$",
"utm_content",
",",
"$",
"utm_campaign",
")",
";",
"}"
] |
Set the Google analytics settings on a TrackingSettings object
@param Ganalytics|bool $enable The Ganalytics object or an indication
if the setting is enabled
@param string|null $utm_source Name of the referrer source. (e.g.
Google, SomeDomain.com, or
Marketing Email)
@param string|null $utm_medium Name of the marketing medium. (e.g.
Email)
@param string|null $utm_term Used to identify any paid keywords
@param string|null $utm_content Used to differentiate your campaign from
advertisements
@param string|null $utm_campaign The name of the campaign
|
[
"Set",
"the",
"Google",
"analytics",
"settings",
"on",
"a",
"TrackingSettings",
"object"
] |
37fa19d3ae019842f07a2a43e92ed0f566ad927d
|
https://github.com/sendgrid/sendgrid-php/blob/37fa19d3ae019842f07a2a43e92ed0f566ad927d/lib/mail/TrackingSettings.php#L200-L221
|
train
|
sendgrid/sendgrid-php
|
lib/mail/TrackingSettings.php
|
TrackingSettings.jsonSerialize
|
public function jsonSerialize()
{
return array_filter(
[
'click_tracking' => $this->getClickTracking(),
'open_tracking' => $this->getOpenTracking(),
'subscription_tracking' => $this->getSubscriptionTracking(),
'ganalytics' => $this->getGanalytics()
],
function ($value) {
return $value !== null;
}
) ?: null;
}
|
php
|
public function jsonSerialize()
{
return array_filter(
[
'click_tracking' => $this->getClickTracking(),
'open_tracking' => $this->getOpenTracking(),
'subscription_tracking' => $this->getSubscriptionTracking(),
'ganalytics' => $this->getGanalytics()
],
function ($value) {
return $value !== null;
}
) ?: null;
}
|
[
"public",
"function",
"jsonSerialize",
"(",
")",
"{",
"return",
"array_filter",
"(",
"[",
"'click_tracking'",
"=>",
"$",
"this",
"->",
"getClickTracking",
"(",
")",
",",
"'open_tracking'",
"=>",
"$",
"this",
"->",
"getOpenTracking",
"(",
")",
",",
"'subscription_tracking'",
"=>",
"$",
"this",
"->",
"getSubscriptionTracking",
"(",
")",
",",
"'ganalytics'",
"=>",
"$",
"this",
"->",
"getGanalytics",
"(",
")",
"]",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"value",
"!==",
"null",
";",
"}",
")",
"?",
":",
"null",
";",
"}"
] |
Return an array representing a TrackingSettings object for the Twilio SendGrid API
@return null|array
|
[
"Return",
"an",
"array",
"representing",
"a",
"TrackingSettings",
"object",
"for",
"the",
"Twilio",
"SendGrid",
"API"
] |
37fa19d3ae019842f07a2a43e92ed0f566ad927d
|
https://github.com/sendgrid/sendgrid-php/blob/37fa19d3ae019842f07a2a43e92ed0f566ad927d/lib/mail/TrackingSettings.php#L238-L251
|
train
|
sendgrid/sendgrid-php
|
lib/mail/ClickTracking.php
|
ClickTracking.jsonSerialize
|
public function jsonSerialize()
{
return array_filter(
[
'enable' => $this->getEnable(),
'enable_text' => $this->getEnableText()
],
function ($value) {
return $value !== null;
}
) ?: null;
}
|
php
|
public function jsonSerialize()
{
return array_filter(
[
'enable' => $this->getEnable(),
'enable_text' => $this->getEnableText()
],
function ($value) {
return $value !== null;
}
) ?: null;
}
|
[
"public",
"function",
"jsonSerialize",
"(",
")",
"{",
"return",
"array_filter",
"(",
"[",
"'enable'",
"=>",
"$",
"this",
"->",
"getEnable",
"(",
")",
",",
"'enable_text'",
"=>",
"$",
"this",
"->",
"getEnableText",
"(",
")",
"]",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"value",
"!==",
"null",
";",
"}",
")",
"?",
":",
"null",
";",
"}"
] |
Return an array representing a ClickTracking object for the Twilio SendGrid API
@return null|array
|
[
"Return",
"an",
"array",
"representing",
"a",
"ClickTracking",
"object",
"for",
"the",
"Twilio",
"SendGrid",
"API"
] |
37fa19d3ae019842f07a2a43e92ed0f566ad927d
|
https://github.com/sendgrid/sendgrid-php/blob/37fa19d3ae019842f07a2a43e92ed0f566ad927d/lib/mail/ClickTracking.php#L102-L113
|
train
|
sendgrid/sendgrid-php
|
lib/mail/Footer.php
|
Footer.jsonSerialize
|
public function jsonSerialize()
{
return array_filter(
[
'enable' => $this->getEnable(),
'text' => $this->getText(),
'html' => $this->getHtml()
],
function ($value) {
return $value !== null;
}
) ?: null;
}
|
php
|
public function jsonSerialize()
{
return array_filter(
[
'enable' => $this->getEnable(),
'text' => $this->getText(),
'html' => $this->getHtml()
],
function ($value) {
return $value !== null;
}
) ?: null;
}
|
[
"public",
"function",
"jsonSerialize",
"(",
")",
"{",
"return",
"array_filter",
"(",
"[",
"'enable'",
"=>",
"$",
"this",
"->",
"getEnable",
"(",
")",
",",
"'text'",
"=>",
"$",
"this",
"->",
"getText",
"(",
")",
",",
"'html'",
"=>",
"$",
"this",
"->",
"getHtml",
"(",
")",
"]",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"value",
"!==",
"null",
";",
"}",
")",
"?",
":",
"null",
";",
"}"
] |
Return an array representing a Footer object for the Twilio SendGrid API
@return null|array
|
[
"Return",
"an",
"array",
"representing",
"a",
"Footer",
"object",
"for",
"the",
"Twilio",
"SendGrid",
"API"
] |
37fa19d3ae019842f07a2a43e92ed0f566ad927d
|
https://github.com/sendgrid/sendgrid-php/blob/37fa19d3ae019842f07a2a43e92ed0f566ad927d/lib/mail/Footer.php#L131-L143
|
train
|
sendgrid/sendgrid-php
|
lib/mail/Header.php
|
Header.jsonSerialize
|
public function jsonSerialize()
{
return array_filter(
[
'key' => $this->getKey(),
'value' => $this->getValue()
],
function ($value) {
return $value !== null;
}
) ?: null;
}
|
php
|
public function jsonSerialize()
{
return array_filter(
[
'key' => $this->getKey(),
'value' => $this->getValue()
],
function ($value) {
return $value !== null;
}
) ?: null;
}
|
[
"public",
"function",
"jsonSerialize",
"(",
")",
"{",
"return",
"array_filter",
"(",
"[",
"'key'",
"=>",
"$",
"this",
"->",
"getKey",
"(",
")",
",",
"'value'",
"=>",
"$",
"this",
"->",
"getValue",
"(",
")",
"]",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"value",
"!==",
"null",
";",
"}",
")",
"?",
":",
"null",
";",
"}"
] |
Return an array representing a Header object for the Twilio SendGrid API
@return null|array
|
[
"Return",
"an",
"array",
"representing",
"a",
"Header",
"object",
"for",
"the",
"Twilio",
"SendGrid",
"API"
] |
37fa19d3ae019842f07a2a43e92ed0f566ad927d
|
https://github.com/sendgrid/sendgrid-php/blob/37fa19d3ae019842f07a2a43e92ed0f566ad927d/lib/mail/Header.php#L104-L115
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.