firefly-iii/app/Providers/EventServiceProvider.php

67 lines
1.7 KiB
PHP
Raw Normal View History

2015-02-05 21:52:16 -06:00
<?php namespace FireflyIII\Providers;
2015-02-05 21:39:52 -06:00
use FireflyIII\Models\Account;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal;
2015-02-05 21:39:52 -06:00
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
2015-02-11 00:35:10 -06:00
/**
* Class EventServiceProvider
*
* @package FireflyIII\Providers
*/
class EventServiceProvider extends ServiceProvider
{
2015-02-05 21:39:52 -06:00
2015-02-11 00:35:10 -06:00
/**
* The event handler mappings for the application.
*
* @var array
*/
protected $listen
= [
'event.name' => [
2015-02-11 00:35:10 -06:00
'EventListener',
],
'App\Events\JournalDeleted' => [
'App\Handlers\Events\JournalDeletedHandler@handle',
],
2015-02-11 00:35:10 -06:00
];
2015-02-05 21:39:52 -06:00
2015-02-11 00:35:10 -06:00
/**
* Register any other events for your application.
*
* @param \Illuminate\Contracts\Events\Dispatcher $events
*
* @return void
*/
public function boot(DispatcherContract $events)
{
parent::boot($events);
2015-02-05 21:39:52 -06:00
TransactionJournal::deleted(
function (TransactionJournal $journal) {
/** @var Transaction $transaction */
foreach ($journal->transactions()->get() as $transaction) {
$transaction->delete();
}
}
);
Account::deleted(
function (Account $account) {
/** @var Transaction $transaction */
foreach ($account->transactions()->get() as $transaction) {
$journal = $transaction->transactionJournal()->first();
$journal->delete();
}
}
);
2015-02-11 00:35:10 -06:00
}
2015-02-05 21:39:52 -06:00
}