Improve event emitter trait

This commit is contained in:
Sam Georges 2014-05-15 17:23:46 +10:00
parent 5bf215e648
commit bdff075058
7 changed files with 24 additions and 24 deletions

View File

@ -79,11 +79,11 @@ class FormController extends ControllerBehavior
*/
$this->formWidget = $this->makeWidget('Backend\Widgets\Form', $config);
$this->formWidget->bind('form.extendFieldsBefore', function($host) {
$this->formWidget->bindEvent('form.extendFieldsBefore', function($host) {
$this->controller->formExtendFieldsBefore($host);
});
$this->formWidget->bind('form.extendFields', function($host) {
$this->formWidget->bindEvent('form.extendFields', function($host) {
$this->controller->formExtendFields($host);
});

View File

@ -128,23 +128,23 @@ class ListController extends ControllerBehavior
/*
* Extensibility helpers
*/
$widget->bind('list.extendQueryBefore', function($host, $query) use ($definition) {
$widget->bindEvent('list.extendQueryBefore', function($host, $query) use ($definition) {
$this->controller->listExtendQueryBefore($query, $definition);
});
$widget->bind('list.extendQuery', function($host, $query) use ($definition) {
$widget->bindEvent('list.extendQuery', function($host, $query) use ($definition) {
$this->controller->listExtendQuery($query, $definition);
});
$widget->bind('list.injectRowClass', function($host, $record) use ($definition) {
$widget->bindEvent('list.injectRowClass', function($host, $record) use ($definition) {
return $this->controller->listInjectRowClass($record, $definition);
});
$widget->bind('list.overrideColumnValue', function($host, $record, $column, $value) use ($definition) {
$widget->bindEvent('list.overrideColumnValue', function($host, $record, $column, $value) use ($definition) {
return $this->controller->listOverrideColumnValue($record, $column->columnName, $definition);
});
$widget->bind('list.overrideHeaderValue', function($host, $column, $value) use ($definition) {
$widget->bindEvent('list.overrideHeaderValue', function($host, $column, $value) use ($definition) {
return $this->controller->listOverrideHeaderValue($column->columnName, $definition);
});
@ -162,7 +162,7 @@ class ListController extends ControllerBehavior
* Link the Search Widget to the List Widget
*/
if ($searchWidget = $toolbarWidget->getSearchWidget()) {
$searchWidget->bind('search.submit', function() use ($widget, $searchWidget) {
$searchWidget->bindEvent('search.submit', function() use ($widget, $searchWidget) {
$widget->setSearchTerm($searchWidget->getActiveTerm());
return $widget->onRender();
});

View File

@ -498,7 +498,7 @@ class RelationController extends ControllerBehavior
$config->showCheckboxes = true;
$widget = $this->makeWidget('Backend\Widgets\Lists', $config);
$widget->bind('list.extendQueryBefore', function($host, $query) {
$widget->bindEvent('list.extendQueryBefore', function($host, $query) {
$this->relationObject->setQuery($query);
$this->relationObject->addConstraints();
});
@ -572,7 +572,7 @@ class RelationController extends ControllerBehavior
* Exclude exisiting relationships
*/
if ($this->manageMode == 'pivot' || $this->manageMode == 'list') {
$widget->bind('list.extendQueryBefore', function($host, $query) {
$widget->bindEvent('list.extendQueryBefore', function($host, $query) {
/*
* Where not in the current list of related records

View File

@ -218,7 +218,7 @@ class Form extends WidgetBase
* Extensibility
*/
Event::fire('backend.form.extendFieldsBefore', [$this]);
$this->trigger('form.extendFieldsBefore', $this);
$this->fireEvent('form.extendFieldsBefore', $this);
/*
* Outside fields
@ -248,7 +248,7 @@ class Form extends WidgetBase
* Extensibility
*/
Event::fire('backend.form.extendFields', [$this]);
$this->trigger('form.extendFields', $this);
$this->fireEvent('form.extendFields', $this);
/*
* Convert automatic spanned fields

View File

@ -259,7 +259,7 @@ class Lists extends WidgetBase
* Extensibility
*/
Event::fire('backend.list.extendQueryBefore', [$this, $query]);
$this->trigger('list.extendQueryBefore', $this, $query);
$this->fireEvent('list.extendQueryBefore', [$this, $query]);
/*
* Related custom selects, must come first
@ -331,7 +331,7 @@ class Lists extends WidgetBase
* Extensibility
*/
Event::fire('backend.list.extendQuery', [$this, $query]);
$this->trigger('list.extendQuery', $this, $query);
$this->fireEvent('list.extendQuery', [$this, $query]);
// Grouping due to the joinWith() call
$query->select($selects);
@ -517,8 +517,8 @@ class Lists extends WidgetBase
if ($response = Event::fire('backend.list.overrideHeaderValue', [$this, $column, $value], true))
$value = $response;
if (($response = $this->trigger('list.overrideHeaderValue', $this, $column, $value)) && is_array($response))
$value = array_pop($response);
if ($response = $this->fireEvent('list.overrideHeaderValue', [$this, $column, $value], true))
$value = $response;
return $value;
}
@ -539,8 +539,8 @@ class Lists extends WidgetBase
if ($response = Event::fire('backend.list.overrideColumnValue', [$this, $record, $column, $value], true))
$value = $response;
if (($response = $this->trigger('list.overrideColumnValue', $this, $record, $column, $value)) && is_array($response))
$value = array_pop($response);
if ($response = $this->fireEvent('list.overrideColumnValue', [$this, $record, $column, $value], true))
$value = $response;
return $value;
}
@ -560,8 +560,8 @@ class Lists extends WidgetBase
if ($response = Event::fire('backend.list.injectRowClass', [$this, $record], true))
$value = $response;
if (($response = $this->trigger('list.injectRowClass', $this, $record)) && is_array($response))
$value = array_pop($response);
if ($response = $this->fireEvent('list.injectRowClass', [$this, $record], true))
$value = $response;
return $value;
}

View File

@ -90,7 +90,7 @@ class Search extends WidgetBase
* Trigger class event, merge results as viewable array
*/
$params = func_get_args();
$result = $this->trigger('search.submit', $params);
$result = $this->fireEvent('search.submit', [$params]);
return Util::arrayMerge($result);
}

View File

@ -52,9 +52,9 @@ class SettingsModel extends ModelBehavior
/*
* Access to model's overrides is unavailable, using events instead
*/
$this->model->bind('model.afterFetch', [$this, 'afterModelFetch']);
$this->model->bind('model.beforeSave', [$this, 'beforeModelSave']);
$this->model->bind('model.afterSetAttribute', [$this, 'setModelAttribute']);
$this->model->bindEvent('model.afterFetch', [$this, 'afterModelFetch']);
$this->model->bindEvent('model.beforeSave', [$this, 'beforeModelSave']);
$this->model->bindEvent('model.afterSetAttribute', [$this, 'setModelAttribute']);
/*
* Parse the config