Commit 9e1b498f by resurtm

PHP 5.4 supports $this with closures.

parent 89394db0
......@@ -34,11 +34,10 @@ abstract class Mutex extends Component
public function init()
{
if ($this->autoRelease) {
$mutex = $this;
$locks = &$this->_locks;
register_shutdown_function(function () use ($mutex, &$locks) {
register_shutdown_function(function () use ($this, &$locks) {
foreach ($locks as $lock) {
$mutex->release($lock);
$this->release($lock);
}
});
}
......
......@@ -175,10 +175,9 @@ class ErrorHandler extends Component
$html = rtrim($html, '\\');
} elseif (strpos($code, '()') !== false) {
// method/function call
$self = $this;
$html = preg_replace_callback('/^(.*)\(\)$/', function ($matches) use ($self) {
return '<a href="http://yiiframework.com/doc/api/2.0/' . $self->htmlEncode($matches[1]) . '" target="_blank">' .
$self->htmlEncode($matches[1]) . '</a>()';
$html = preg_replace_callback('/^(.*)\(\)$/', function ($matches) use ($this) {
return '<a href="http://yiiframework.com/doc/api/2.0/' . $this->htmlEncode($matches[1]) . '" target="_blank">' .
$this->htmlEncode($matches[1]) . '</a>()';
}, $code);
}
return $html;
......
......@@ -508,13 +508,12 @@ class Connection extends Component
*/
public function quoteSql($sql)
{
$db = $this;
return preg_replace_callback('/(\\{\\{(%?[\w\-\. ]+%?)\\}\\}|\\[\\[([\w\-\. ]+)\\]\\])/',
function ($matches) use ($db) {
function ($matches) use ($this) {
if (isset($matches[3])) {
return $db->quoteColumnName($matches[3]);
return $this->quoteColumnName($matches[3]);
} else {
return str_replace('%', $db->tablePrefix, $db->quoteTableName($matches[2]));
return str_replace('%', $this->tablePrefix, $this->quoteTableName($matches[2]));
}
}, $sql);
}
......
......@@ -57,9 +57,8 @@ class Module extends \yii\base\Module
$this->dataPath = Yii::getAlias($this->dataPath);
$this->logTarget = Yii::$app->getLog()->targets['debug'] = new LogTarget($this);
// do not initialize view component before application is ready (needed when debug in preload)
$module = $this;
Yii::$app->on(Application::EVENT_BEFORE_ACTION, function() use ($module) {
Yii::$app->getView()->on(View::EVENT_END_BODY, array($module, 'renderToolbar'));
Yii::$app->on(Application::EVENT_BEFORE_ACTION, function() use ($this) {
Yii::$app->getView()->on(View::EVENT_END_BODY, array($this, 'renderToolbar'));
});
foreach (array_merge($this->corePanels(), $this->panels) as $id => $config) {
......
......@@ -88,11 +88,10 @@ class ActionColumn extends Column
*/
protected function renderDataCellContent($model, $index)
{
$column = $this;
return preg_replace_callback('/\\{(\w+)\\}/', function ($matches) use ($model, $column) {
return preg_replace_callback('/\\{(\w+)\\}/', function ($matches) use ($this, $model) {
$name = $matches[1];
if (isset($column->buttons[$name])) {
return call_user_func($column->buttons[$name], $model, $column);
if (isset($this->buttons[$name])) {
return call_user_func($this->buttons[$name], $model, $this);
} else {
return '';
}
......
......@@ -92,9 +92,8 @@ abstract class BaseListView extends Widget
public function run()
{
if ($this->dataProvider->getCount() > 0 || $this->empty === false) {
$widget = $this;
$content = preg_replace_callback("/{\\w+}/", function ($matches) use ($widget) {
$content = $widget->renderSection($matches[0]);
$content = preg_replace_callback("/{\\w+}/", function ($matches) use ($this) {
$content = $this->renderSection($matches[0]);
return $content === false ? $matches[0] : $content;
}, $this->layout);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment