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() public function init()
{ {
if ($this->autoRelease) { if ($this->autoRelease) {
$mutex = $this;
$locks = &$this->_locks; $locks = &$this->_locks;
register_shutdown_function(function () use ($mutex, &$locks) { register_shutdown_function(function () use ($this, &$locks) {
foreach ($locks as $lock) { 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, '\\'); $html = rtrim($html, '\\');
} elseif (strpos($code, '()') !== false) { } elseif (strpos($code, '()') !== false) {
// method/function call // method/function call
$self = $this; $html = preg_replace_callback('/^(.*)\(\)$/', function ($matches) use ($this) {
$html = preg_replace_callback('/^(.*)\(\)$/', function ($matches) use ($self) { return '<a href="http://yiiframework.com/doc/api/2.0/' . $this->htmlEncode($matches[1]) . '" target="_blank">' .
return '<a href="http://yiiframework.com/doc/api/2.0/' . $self->htmlEncode($matches[1]) . '" target="_blank">' . $this->htmlEncode($matches[1]) . '</a>()';
$self->htmlEncode($matches[1]) . '</a>()';
}, $code); }, $code);
} }
return $html; return $html;

7
framework/yii/db/Connection.php

@ -508,13 +508,12 @@ class Connection extends Component
*/ */
public function quoteSql($sql) public function quoteSql($sql)
{ {
$db = $this;
return preg_replace_callback('/(\\{\\{(%?[\w\-\. ]+%?)\\}\\}|\\[\\[([\w\-\. ]+)\\]\\])/', return preg_replace_callback('/(\\{\\{(%?[\w\-\. ]+%?)\\}\\}|\\[\\[([\w\-\. ]+)\\]\\])/',
function ($matches) use ($db) { function ($matches) use ($this) {
if (isset($matches[3])) { if (isset($matches[3])) {
return $db->quoteColumnName($matches[3]); return $this->quoteColumnName($matches[3]);
} else { } else {
return str_replace('%', $db->tablePrefix, $db->quoteTableName($matches[2])); return str_replace('%', $this->tablePrefix, $this->quoteTableName($matches[2]));
} }
}, $sql); }, $sql);
} }

5
framework/yii/debug/Module.php

@ -57,9 +57,8 @@ class Module extends \yii\base\Module
$this->dataPath = Yii::getAlias($this->dataPath); $this->dataPath = Yii::getAlias($this->dataPath);
$this->logTarget = Yii::$app->getLog()->targets['debug'] = new LogTarget($this); $this->logTarget = Yii::$app->getLog()->targets['debug'] = new LogTarget($this);
// do not initialize view component before application is ready (needed when debug in preload) // 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 ($this) {
Yii::$app->on(Application::EVENT_BEFORE_ACTION, function() use ($module) { Yii::$app->getView()->on(View::EVENT_END_BODY, array($this, 'renderToolbar'));
Yii::$app->getView()->on(View::EVENT_END_BODY, array($module, 'renderToolbar'));
}); });
foreach (array_merge($this->corePanels(), $this->panels) as $id => $config) { 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) protected function renderDataCellContent($model, $index)
{ {
$column = $this; return preg_replace_callback('/\\{(\w+)\\}/', function ($matches) use ($this, $model) {
return preg_replace_callback('/\\{(\w+)\\}/', function ($matches) use ($model, $column) {
$name = $matches[1]; $name = $matches[1];
if (isset($column->buttons[$name])) { if (isset($this->buttons[$name])) {
return call_user_func($column->buttons[$name], $model, $column); return call_user_func($this->buttons[$name], $model, $this);
} else { } else {
return ''; return '';
} }

5
framework/yii/widgets/BaseListView.php

@ -92,9 +92,8 @@ abstract class BaseListView extends Widget
public function run() public function run()
{ {
if ($this->dataProvider->getCount() > 0 || $this->empty === false) { if ($this->dataProvider->getCount() > 0 || $this->empty === false) {
$widget = $this; $content = preg_replace_callback("/{\\w+}/", function ($matches) use ($this) {
$content = preg_replace_callback("/{\\w+}/", function ($matches) use ($widget) { $content = $this->renderSection($matches[0]);
$content = $widget->renderSection($matches[0]);
return $content === false ? $matches[0] : $content; return $content === false ? $matches[0] : $content;
}, $this->layout); }, $this->layout);
} else { } else {

Loading…
Cancel
Save