55namespace DragonCode \LaravelFeed \Services ;
66
77use DragonCode \LaravelFeed \Converters \Converter ;
8+ use DragonCode \LaravelFeed \Events \FeedFinishedEvent ;
9+ use DragonCode \LaravelFeed \Events \FeedStartingEvent ;
810use DragonCode \LaravelFeed \Exceptions \FeedGenerationException ;
911use DragonCode \LaravelFeed \Feeds \Feed ;
1012use DragonCode \LaravelFeed \Helpers \ConverterHelper ;
1517use Throwable ;
1618
1719use function blank ;
20+ use function event ;
1821use function get_class ;
1922use function implode ;
2023
@@ -28,10 +31,9 @@ public function __construct(
2831
2932 public function feed (Feed $ feed , ?OutputStyle $ output = null ): void
3033 {
31- $ file = $ this ->openFile (
32- $ path = $ feed ->path ()
33- );
3434 try {
35+ $ this ->started ($ feed );
36+
3537 $ file = $ this ->openFile (
3638 $ path = $ feed ->path ()
3739 );
@@ -45,8 +47,9 @@ public function feed(Feed $feed, ?OutputStyle $output = null): void
4547
4648 $ this ->release ($ file , $ path );
4749
48- $ this ->setLastActivity ($ feed );
4950 $ this ->setLastActivity ($ feed );
51+
52+ $ this ->finished ($ feed , $ path );
5053 } catch (Throwable $ e ) {
5154 throw new FeedGenerationException (get_class ($ feed ), $ e );
5255 }
@@ -162,4 +165,14 @@ protected function progressBar(int $count, ?OutputStyle $output): ?ProgressBar
162165 {
163166 return $ output ?->createProgressBar($ count );
164167 }
168+
169+ protected function started (Feed $ feed ): void
170+ {
171+ event (new FeedStartingEvent (get_class ($ feed )));
172+ }
173+
174+ protected function finished (Feed $ feed , string $ path ): void
175+ {
176+ event (new FeedFinishedEvent (get_class ($ feed ), $ path ));
177+ }
165178}
0 commit comments