75. Events in Code
class frontendConfiguration extends sfApplicationConfiguration
{
public function configure()
{
$this->dispatcher->connect('registration.complete',
array(SomeClass, 'listenToRegistrationComplete'));
// [...]
}
}
15
76. Events in Code
class frontendConfiguration extends sfApplicationConfiguration
{
public function configure()
{
$this->dispatcher->connect('registration.complete',
array(SomeClass, 'listenToRegistrationComplete'));
// [...]
}
}
15
77. Events in Code
Event Name
class frontendConfiguration extends sfApplicationConfiguration
{
public function configure()
{
$this->dispatcher->connect('registration.complete',
array(SomeClass, 'listenToRegistrationComplete'));
// [...]
}
}
15
78. Events in Code
Event Name
class frontendConfiguration extends sfApplicationConfiguration
{
public function configure()
{
$this->dispatcher->connect('registration.complete',
array(SomeClass, 'listenToRegistrationComplete'));
// [...]
}
}
15
79. Events in Code
Event Name
class frontendConfiguration extends sfApplicationConfiguration
{
public function configure()
{
$this->dispatcher->connect('registration.complete',
array(SomeClass, 'listenToRegistrationComplete'));
// [...]
}
}
Callable
(can be static or non-static)
15
80. Events in Code
$this->dispatcher->notify(new sfEvent($user, 'registration.complete'));
16
81. Events in Code
$this->dispatcher->notify(new sfEvent($user, 'registration.complete'));
16
82. Events in Code
Notification Type
$this->dispatcher->notify(new sfEvent($user, 'registration.complete'));
16
83. Events in Code
Notification Type
$this->dispatcher->notify(new sfEvent($user, 'registration.complete'));
16
84. Events in Code
Notification Type
$this->dispatcher->notify(new sfEvent($user, 'registration.complete'));
Subject
16
85. Events in Code
Notification Type
$this->dispatcher->notify(new sfEvent($user, 'registration.complete'));
Subject
16
86. Events in Code
Event Name
Notification Type
$this->dispatcher->notify(new sfEvent($user, 'registration.complete'));
Subject
16
87. Events in Code
class SomeClass
{
public static function listenToRegistrationComplete(sfEvent $event)
{
$user = $event->getSubject();
// [...]
}
}
17
88. Events in Code
class SomeClass
{
public static function listenToRegistrationComplete(sfEvent $event)
{
$user = $event->getSubject();
// [...]
}
}
17
89. Events in Code
Registered Method
(called via notfiy)
class SomeClass
{
public static function listenToRegistrationComplete(sfEvent $event)
{
$user = $event->getSubject();
// [...]
}
}
17
90. Events in Code
Registered Method
(called via notfiy)
class SomeClass
{
public static function listenToRegistrationComplete(sfEvent $event)
{
$user = $event->getSubject();
// [...]
}
}
17
91. Events in Code
Registered Method
(called via notfiy)
class SomeClass
{
public static function listenToRegistrationComplete(sfEvent $event)
{
$user = $event->getSubject();
// [...]
}
}
Event as Parameter
17
92. Events in Code
Registered Method
(called via notfiy)
class SomeClass
{
public static function listenToRegistrationComplete(sfEvent $event)
{
$user = $event->getSubject();
// [...]
}
}
Event as Parameter
17
93. Events in Code
Registered Method
(called via notfiy)
class SomeClass
{
public static function listenToRegistrationComplete(sfEvent $event)
{
$user = $event->getSubject();
// [...]
}
}
Passed Subject
Event as Parameter
17
96. Events in Code
Notification Type
$returnValue = $this->dispatcher->filter(new sfEvent($blogPost,
'blog_post.render'), $blogPost->getBody());
18
97. Events in Code
Notification Type
$returnValue = $this->dispatcher->filter(new sfEvent($blogPost,
'blog_post.render'), $blogPost->getBody());
18
98. Events in Code
Notification Type
$returnValue = $this->dispatcher->filter(new sfEvent($blogPost,
'blog_post.render'), $blogPost->getBody());
Raw Value
18
99. Events in Code
Notification Type
$returnValue = $this->dispatcher->filter(new sfEvent($blogPost,
'blog_post.render'), $blogPost->getBody());
Raw Value
18
100. Events in Code
Notification Type
$returnValue = $this->dispatcher->filter(new sfEvent($blogPost,
'blog_post.render'), $blogPost->getBody());
Filtered Value
Raw Value
18
101. Events in Code
class MarkdownParser
{
// [...]
public static function listenToRegistrationComplete(sfEvent $event, $body)
{
$markdownParser = new self();
$parsedBody = $markdownParser->parse($body);
// [...]
return $parsedBody;
}
}
19
102. Events in Code
class MarkdownParser
{
// [...]
public static function listenToRegistrationComplete(sfEvent $event, $body)
{
$markdownParser = new self();
$parsedBody = $markdownParser->parse($body);
// [...]
return $parsedBody;
}
}
19
103. Events in Code
Raw Value as Parameter
class MarkdownParser
{
// [...]
public static function listenToRegistrationComplete(sfEvent $event, $body)
{
$markdownParser = new self();
$parsedBody = $markdownParser->parse($body);
// [...]
return $parsedBody;
}
}
19
104. Events in Code
Raw Value as Parameter
class MarkdownParser
{
// [...]
public static function listenToRegistrationComplete(sfEvent $event, $body)
{
$markdownParser = new self();
$parsedBody = $markdownParser->parse($body);
// [...]
return $parsedBody;
}
}
19
105. Events in Code
Raw Value as Parameter
class MarkdownParser
{
// [...]
public static function listenToRegistrationComplete(sfEvent $event, $body)
{
$markdownParser = new self();
$parsedBody = $markdownParser->parse($body);
// [...]
return $parsedBody;
}
}
Filtered Value
19
110. Other Usage Examples
I use events mostly with object
states changes, for example to send
email, notify someone, clear cache,
calculate sth.
snzapka
22
112. Other Usage Examples
I have a centralized "spot" for file
system operations. e.g. when a user
deletes an image from the DB, it
kicks off an event
b00giZm
23
132. Credits
Thanks to:
- Bernhard and Andreas for the reviews and tips.
- Konrad and Samim for the designs and the artworks.
Creative Commons stuff used:
- „Cog, Gear, Settings“ icon by „Visual Pharm“ - http://www.iconfinder.net/icondetails/27879/128/
- „Crying, Man“ icon by Rokey - http://www.iconfinder.net/icondetails/37613/128/
- „Box, Package“ icon by Alessandro Rei - http://www.iconfinder.net/icondetails/6507/128/
34