Skip to content

Commit

Permalink
Fixes #100. Fixes #2180. CLogFilter::$logVars can now be array of arr…
Browse files Browse the repository at this point in the history
…ays.
  • Loading branch information
resurtm committed Jun 28, 2013
1 parent 8e5c881 commit f12658e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -82,6 +82,7 @@ Version 1.1.14 work in progress
- Bug #2581: Fixed the bug with empty ajaxVar in jquery.yiilistview.js and jquery.yiigridview.js (seregagl)
- Enh: Better CFileLogRoute performance (Qiang, samdark)
- Enh: Refactored CHttpRequest::getDelete and CHttpRequest::getPut not to use _restParams directly (samdark)
- Enh #100: CLogFilter::$logVars can now be array of arrays intended for designating particular items of the $GLOBALS (resurtm, tomtomsen)
- Enh #118: Proper support of namespaced models in forms (LastDragon-ru, Ekstazi, pgaultier)
- Enh #169: Allow to set AJAX request type for CListView and CGridView (klimov-paul)
- Enh #289: Gii module could be submodule of an another module (resurtm)
Expand Down
30 changes: 25 additions & 5 deletions framework/logging/CLogFilter.php
Expand Up @@ -44,7 +44,7 @@ class CLogFilter extends CComponent implements ILogFilter
public $logVars=array('_GET','_POST','_FILES','_COOKIE','_SESSION','_SERVER');
/**
* @var callable or function which will be used to dump context information.
* Defaults to `var_export`. If you're having problems with circular references
* Defaults to `var_export`. If you're experiencing issues with circular references
* problem change it to `print_r`. Any kind of callable (static methods, user defined
* functions, lambdas, etc.) could also be used.
* @since 1.1.14
Expand Down Expand Up @@ -105,16 +105,36 @@ protected function getContext()
if($this->dumper==='var_export' || $this->dumper==='print_r')
{
foreach($this->logVars as $name)
if(!empty($GLOBALS[$name]))
$context[]="\${$name}=".call_user_func($this->dumper,$GLOBALS[$name],true);
if(($value=$this->getGlobalsValue($name))!==null)
$context[]="\${$name}=".call_user_func($this->dumper,$value,true);
}
else
{
foreach($this->logVars as $name)
if(!empty($GLOBALS[$name]))
$context[]="\${$name}=".call_user_func($this->dumper,$GLOBALS[$name]);
if(($value=$this->getGlobalsValue($name))!==null)
$context[]="\${$name}=".call_user_func($this->dumper,$value);
}

return implode("\n\n",$context);
}

/**
* @param string[] $path
* @return string|null
*/
private function getGlobalsValue(&$path)
{
if(is_scalar($path))
return !empty($GLOBALS[$path]) ? $GLOBALS[$path] : null;
$pathAux=$path;
$parts=array();
$value=$GLOBALS;
do
{
$value=$value[$parts[]=array_shift($pathAux)];
}
while(!empty($value) && !empty($pathAux) && !is_string($value));
$path=implode('.',$parts);
return $value;
}
}

0 comments on commit f12658e

Please sign in to comment.