Skip to content

Commit a9acbe0

Browse files
authored
Fixed indents
1 parent 0bccf20 commit a9acbe0

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

doc/listeners-and-event-handlers.md

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,40 @@
66
There is no specific internal event handling mechanism, but one can be approximated by implementing one yourself. For example, a basic implementation of an [observer model](https://en.wikipedia.org/wiki/Observer_pattern) event handling system:
77
```php
88
<?php
9-
abstract class SubjectBase {
10-
abstract public function handleEvent();
9+
abstract class SubjectBase {
10+
abstract public function handleEvent();
1111
}
1212

13-
class Observer {
14-
private $subjects = array();
13+
class Observer {
14+
private $subjects = array();
1515
public function registerSubject($subject) {
16-
array_push($this->subjects, $subject);
16+
array_push($this->subjects, $subject);
1717
}
1818
public function notifySubjects() {
1919
foreach($this->subjects as $s) {
20-
$s->handleEvent();
20+
$s->handleEvent();
2121
}
2222
}
2323
}
2424
class Subject extends SubjectBase {
25-
private $name;
25+
private $name;
2626
public function __construct($name) {
27-
$this->name = $name;
27+
$this->name = $name;
2828
}
29-
public function handleEvent($event) { // In this example, events are just Strings. However more a more sophisticated Event object could be constructed and utilized to increase usefulness
30-
print "Subject name: ".$this->name." is handling this event: ".$event;
29+
public function handleEvent($event) { // In this example, events are just Strings. However more a more sophisticated Event object could be constructed and utilized to increase usefulness
30+
print "Subject name: ".$this->name." is handling this event: ".$event;
3131
}
3232
}
33-
33+
3434
$a = new Subject("foo");
3535
$b = new Subject("bar");
3636
$c = new Subject("baz");
37-
37+
3838
$observer = new Observer();
3939
$observer->registerSubject($a);
4040
$observer->registerSubject($b);
4141
$observer->registerSubject($c);
42-
42+
4343
$observer->notifySubjects("myEvent");
4444
?>
4545
```
@@ -53,19 +53,19 @@ Subject name: baz is handling this event: myEvent
5353
Much like PHP, there exists no native library functions specifically for event handling. Yet, just like PHP, event-based architectures can be created. A basic observer model pattern can be approximated in a way similar to which follows:
5454
```python
5555
class Subject:
56-
def __init__(self, name):
57-
self.name = name
58-
def handleEvent(self, event):
59-
print("Subject name: %s is handling this event: %s"%(self.name, event))
60-
56+
def __init__(self, name):
57+
self.name = name
58+
def handleEvent(self, event):
59+
print("Subject name: %s is handling this event: %s"%(self.name, event))
60+
6161
class Observer:
62-
subjects = []
63-
def registerSubject(self, subject):
64-
self.subjects.append(subject)
62+
subjects = []
63+
def registerSubject(self, subject):
64+
self.subjects.append(subject)
6565
def notifySubjects(self, event):
66-
for s in self.subjects:
67-
s.handleEvent(event)
68-
66+
for s in self.subjects:
67+
s.handleEvent(event)
68+
6969
a = Subject("foo")
7070
b = Subject("bar")
7171
c = Subject("baz")

0 commit comments

Comments
 (0)