Skip to content

Commit

Permalink
Documentation for Events updated
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Nov 26, 2016
1 parent 092430d commit f1f357b
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 29 deletions.
20 changes: 13 additions & 7 deletions docs/guide-fr/concept-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ Il y a encore une manière plus abstraite d'utiliser les événements. Vous pouv
Par exemple, vous pouvez créer l'interface suivante :

```php
namespace app\interfaces;

interface DanceEventInterface
{
const EVENT_DANCE = 'dance';
Expand Down Expand Up @@ -260,32 +262,36 @@ class Developer extends Component implements DanceEventInterface
Pour gérer l'évenement `EVENT_DANCE` déclenché par n'importe laquelle de ces classes, appelez [[yii\base\Event::on()|Event::on()]] et passez-lui le nom de l'interface comme premier argument :

```php
Event::on('DanceEventInterface', DanceEventInterface::EVENT_DANCE, function ($event) {
Yii::trace($event->sender->className . ' danse'); // enregistrer le message disant que le chien ou le développeur danse.
})
Event::on('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE, function ($event) {
Yii::trace(get_class($event->sender) . ' just danced'); // Will log that Dog or Developer danced
});
```

Vous pouvez déclencher l'événement de ces classes :

```php
Event::trigger(DanceEventInterface::className(), DanceEventInterface::EVENT_DANCE);
// trigger event for Dog class
Event::trigger(Dog::className(), DanceEventInterface::EVENT_DANCE);

// trigger event for Developer class
Event::trigger(Developer::className(), DanceEventInterface::EVENT_DANCE);
```

Notez bien que vous ne pouvez pas déclencher l'événement de toutes les classes qui implémentent l'interface :,

```php
// NE FONCTIONNE PAS
Event::trigger('DanceEventInterface', DanceEventInterface::EVENT_DANCE); // error
Event::trigger('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE);
```

Pour détacher le gestionnaire d'événement, appelez [[yii\base\Event::off()|Event::off()]]. Par exemple :

```php
// détache $handler
Event::off('DanceEventInterface', DanceEventInterface::EVENT_DANCE, $handler);
Event::off('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE, $handler);

// détache tous les gestionnaires de DanceEventInterface::EVENT_DANCE
Event::off('DanceEventInterface', DanceEventInterface::EVENT_DANCE);
Event::off('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE);
```


Expand Down
20 changes: 13 additions & 7 deletions docs/guide-ja/concept-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ Event::off(Foo::className(), Foo::EVENT_HELLO);
例えば、次のようなインタフェイスを作ります。

```php
namespace app\interfaces;

interface DanceEventInterface
{
const EVENT_DANCE = 'dance';
Expand Down Expand Up @@ -289,33 +291,37 @@ class Developer extends Component implements DanceEventInterface
これらのクラスのどれかによってトリガされた `EVENT_DANCE` を扱うためには、インターフェイスの名前を最初の引数にして [[yii\base\Event::on()|Event::on()]] を呼びます。

```php
Event::on('DanceEventInterface', DanceEventInterface::EVENT_DANCE, function ($event) {
Yii::trace($event->sender->className . ' が躍り上がって喜んだ。'); // 犬または開発者が躍り上がって喜んだことをログに記録。
})
Event::on('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE, function ($event) {
Yii::trace(get_class($event->sender) . ' が躍り上がって喜んだ。'); // 犬または開発者が躍り上がって喜んだことをログに記録。
});
```

これらのクラスのイベントをトリガすることも出来ます。

```php
Event::trigger(DanceEventInterface::className(), DanceEventInterface::EVENT_DANCE);
// trigger event for Dog class
Event::trigger(Dog::className(), DanceEventInterface::EVENT_DANCE);

// trigger event for Developer class
Event::trigger(Developer::className(), DanceEventInterface::EVENT_DANCE);
```

ただし、このインタフェイスを実装する全クラスのイベントをトリガすることは出来ない、ということに注意して下さい。

```php
// これは動かない
Event::trigger('DanceEventInterface', DanceEventInterface::EVENT_DANCE); // エラー
Event::trigger('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE);
```

イベントハンドラをデタッチするためには、[[yii\base\Event::off()|Event::off()]] を呼びます。
例えば、

```php
// $handler をデタッチ
Event::off('DanceEventInterface', DanceEventInterface::EVENT_DANCE, $handler);
Event::off('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE, $handler);

// DanceEventInterface::EVENT_DANCE の全てのハンドラをデタッチ
Event::off('DanceEventInterface', DanceEventInterface::EVENT_DANCE);
Event::off('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE);
```


Expand Down
18 changes: 12 additions & 6 deletions docs/guide-ru/concept-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ Event::off(Foo::className(), Foo::EVENT_HELLO);
Например, создадим следующий интерфейс:

```php
namespace app\interfaces;

interface DanceEventInterface
{
const EVENT_DANCE = 'dance';
Expand Down Expand Up @@ -263,32 +265,36 @@ class Developer extends Component implements DanceEventInterface
вызовите [[yii\base\Event::on()|Event:on()]], передав ему в качестве первого параметра имя интерфейса.

```php
Event::on('DanceEventInterface', DanceEventInterface::EVENT_DANCE, function ($event) {
Yii::trace($event->sender->className . ' just danced'); // Оставит запись в журнале о том, что кто-то танцевал
Event::on('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE, function ($event) {
Yii::trace(get_class($event->sender) . ' just danced'); // Оставит запись в журнале о том, что кто-то танцевал
});
```

Вы можете также инициализировать эти события:

```php
Event::trigger(DanceEventInterface::className(), DanceEventInterface::EVENT_DANCE);
// trigger event for Dog class
Event::trigger(Dog::className(), DanceEventInterface::EVENT_DANCE);

// trigger event for Developer class
Event::trigger(Developer::className(), DanceEventInterface::EVENT_DANCE);
```

Однако, невозможно инициализировать событие во всех классах, которые реализуют интерфейс:

```php
// НЕ БУДЕТ РАБОТАТЬ
Event::trigger('DanceEventInterface', DanceEventInterface::EVENT_DANCE); // ошибка
Event::trigger('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE);
```

Отсоединить обработчик события можно с помощью метода [[yii\base\Event::off()|Event::off()]]. Например:

```php
// отсоединяет $handler
Event::off('DanceEventInterface', DanceEventInterface::EVENT_DANCE, $handler);
Event::off('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE, $handler);

// отсоединяются все обработчики DanceEventInterface::EVENT_DANCE
Event::off('DanceEventInterface', DanceEventInterface::EVENT_DANCE);
Event::off('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE);
```

Глобальные события <span id="global-events"></span>
Expand Down
24 changes: 15 additions & 9 deletions docs/guide/concept-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ implement it in classes, where you need it.
For example, we can create the following interface:

```php
namespace app\interfaces;

interface DanceEventInterface
{
const EVENT_DANCE = 'dance';
Expand Down Expand Up @@ -290,35 +292,39 @@ class Developer extends Component implements DanceEventInterface
```

To handle the `EVENT_DANCE`, triggered by any of these classes, call [[yii\base\Event::on()|Event::on()]] and
pass the interface name as the first argument:
pass the interface class name as the first argument:

```php
Event::on('DanceEventInterface', DanceEventInterface::EVENT_DANCE, function ($event) {
Yii::trace($event->sender->className . ' just danced'); // Will log that Dog or Developer danced
})
Event::on('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE, function ($event) {
Yii::trace(get_class($event->sender) . ' just danced'); // Will log that Dog or Developer danced
});
```

You can trigger the event of those classes:

```php
Event::trigger(DanceEventInterface::className(), DanceEventInterface::EVENT_DANCE);
// trigger event for Dog class
Event::trigger(Dog::className(), DanceEventInterface::EVENT_DANCE);

// trigger event for Developer class
Event::trigger(Developer::className(), DanceEventInterface::EVENT_DANCE);
```

But please notice, that you can not trigger all the classes, that implement the interface:

```php
// DOES NOT WORK
Event::trigger('DanceEventInterface', DanceEventInterface::EVENT_DANCE); // error
// DOES NOT WORK. Classes that implement this interface will NOT be triggered.
Event::trigger('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE);
```

To detach event handler, call [[yii\base\Event::off()|Event::off()]]. For example:

```php
// detaches $handler
Event::off('DanceEventInterface', DanceEventInterface::EVENT_DANCE, $handler);
Event::off('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE, $handler);

// detaches all handlers of DanceEventInterface::EVENT_DANCE
Event::off('DanceEventInterface', DanceEventInterface::EVENT_DANCE);
Event::off('app\interfaces\DanceEventInterface', DanceEventInterface::EVENT_DANCE);
```


Expand Down

0 comments on commit f1f357b

Please sign in to comment.