Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit b78ddc8

Browse files
authored
update tutorial code example for ZF3 compatibility
If you run the code examples, the call to EventManager::setSharedManager() gives a fatal undefined method error in versions >= 3.0 The proposed revision attempts to address that, and also fixed a couple of typos (one of them also a fatal call to an undefined method).
1 parent 510213c commit b78ddc8

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

doc/book/tutorial.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,22 @@ there is an additional argument at the *start* of the list, `Example`. This
160160
code is basically saying, "Listen to the 'do' event of the 'Example' target,
161161
and, when notified, execute this callback."
162162

163-
This is where the `setIdentifiers()` argument of `EventManager` comes into play.
163+
This is where the `setIdentifiers()` method of `EventManager` comes into play.
164164
The method allows passing an array of strings, defining the names of the context
165165
or targets the given instance will be interested in.
166166

167167
So, getting back to our example, let's assume that the above shared listener is
168-
registered, and also that the `Example` class is defined as above. We can then
169-
execute the following:
168+
registered, and also that the `Example` class is defined as above. (Note that as of
169+
version 3, `setSharedManager()` is removed from `EventManager`; the `SharedEventManager`
170+
instance must instead be injected via the constructor.) We can then execute the following:
170171

171172
```php
172173
$example = new Example();
173-
$example->getEventManager()->setSharedManager($sharedEvents);
174-
$example->do('bar', 'bat');
174+
// prior to version 3:
175+
// $example->getEventManager()->setSharedManager($sharedEvents);
176+
// as of version 3:
177+
$example->setEventManager(new EventManager($sharedEvents));
178+
$example->doIt('bar', 'bat');
175179
```
176180

177181
and expect the following output:

0 commit comments

Comments
 (0)