Browse Source

PHP 5.4 supports $this with closures.

tags/2.0.0-beta
resurtm 11 years ago
parent
commit
9e1b498fb5
  1. 5
      extensions/mutex/yii/mutex/Mutex.php
  2. 7
      framework/yii/base/ErrorHandler.php
  3. 7
      framework/yii/db/Connection.php
  4. 5
      framework/yii/debug/Module.php
  5. 7
      framework/yii/grid/ActionColumn.php
  6. 5
      framework/yii/widgets/BaseListView.php

5
extensions/mutex/yii/mutex/Mutex.php

@ -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);
}
});
}

7
framework/yii/base/ErrorHandler.php

@ -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;

7
framework/yii/db/Connection.php

@ -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);
}

5
framework/yii/debug/Module.php

@ -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) {

7
framework/yii/grid/ActionColumn.php

@ -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 '';
}

5
framework/yii/widgets/BaseListView.php

@ -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 {

Loading…
Cancel
Save