Store the recorded entries if totally done processing the current job.

@param  \Illuminate\Queue\Events\JobProcessed $event
@param  \Illuminate\Foundation\Application  $app
@return void
161980
protected static function storeIfDoneProcessingJob($event, $app)
    {
        array_pop(static::$processingJobs);

        if (empty(static::$processingJobs)) {
            static::store($app[EntriesRepository::class]);

            if ($event->connectionName !== 'sync') {
                static::stopRecording();
            }
        }
    }
666768
protected function raiseBeforeJobEvent($connection, Job $job)
    {
        if (isset($this->events)) {
            $this->events->dispatch('nova.queue.processing', array($connection, $job));
        }
    }
49109
protected function handle($event): void
    {
        $method = $this->getApplyMethod($event);

        if (!method_exists($this, $method)) {
            return;
        }

        $this->$method($event);
    }
716684
public function boot(Application $app)
    {
        $config = $app['config'];
        if (isset($config['orm.subscribers'])) {
            $app->extend('db.event_manager', function($eventMgr) use($app, $config) {
                /** @var EventManager $eventMgr */
                foreach ($config['orm.subscribers'] as $class) {
                    if (isset($app[$class])) {
                        $eventMgr->addEventSubscriber($app[$class]);
                    } else {
                        $eventMgr->addEventSubscriber(new $class());
                    }
                }
                return $eventMgr;
            });
        }
    }
218914
protected function job(): void
    {
        $labels = $this->retrieve([
            'corporation_id' => $this->getCorporationId(),
        ]);

        if ($labels->isCachedLoad()) return;

        collect($labels)->each(function ($label) {

            CorporationContactLabel::firstOrNew([
                'corporation_id' => $this->getCorporationId(),
                'label_id'       => $label->label_id,
            ])->fill([
                'label_name' => $label->label_name,
            ])->save();
        });

        CorporationContactLabel::where('corporation_id', $this->getCorporationId())
            ->whereNotIn('label_id', collect($labels)->pluck('label_id')->flatten()->all())
            ->delete();
    }
585991
protected function runApplicationWithEvents()
    {
        $this->prepareEnvironment();

        if (static::$before) {
            $this->runBeforeCallbacks();
        }
        // read configs/general.php for register aliases
        $this->readGeneralConfigs();
        // register all aliases
        $this->registerAliases();
        // register helpers;
        $this->resolveHelpers();

        //execute the service providers
        $this->prepareServiceProviders();

        if (static::$after) {
            $this->runAfterCallbacks();
        }
    }
1315535
public function attachEvents()
    {
        $appEvents = $this->container->get('event')->getAppEvents();

        if (!empty($appEvents)) {
            foreach ($appEvents as $event => $namespace) {
                // attach all before and after event to handler
                $this->container->get('event')->attach("$event", $namespace);
            }
        }
    }
299267
public void onApplicationEvent(ApplicationEvent event)
    {
        if ((event instanceof LoginEvent)
                && (event.getSource() != LoginEvent.NO_AUTHENTICATION))
            handleLoginEvent((LoginEvent) event);
        else if ((event instanceof LogoutEvent))
            handleLogoutEvent((LogoutEvent) event);
    }
1200545
public function recordThat(Message $event): void
    {
        if (! \array_key_exists($event->messageName(), $this->eventApplyMap)) {
            throw new \RuntimeException('Wrong event recording detected. Unknown event passed to GenericAggregateRoot: ' . $event->messageName());
        }

        $this->version += 1;

        $event = $event->withAddedMetadata('_aggregate_id', $this->aggregateId());
        $event = $event->withAddedMetadata('_aggregate_version', $this->version);
        $this->recordedEvents[] = $event;

        $this->apply($event);
    }
990880
public function register($app)
    {
        Queue::createPayloadUsing(function ($connection, $queue, $payload) {
            return ['telescope_uuid' => optional($this->recordJob($connection, $queue, $payload))->uuid];
        });

        $app['events']->listen(JobProcessed::class, [$this, 'recordProcessedJob']);
        $app['events']->listen(JobFailed::class, [$this, 'recordFailedJob']);
    }
937261
public static function onApplicationReady(Event $event)
    {
        $app = $event->getTarget();

        $twigAdapter = $app->getRenderer()->getAdapter('twig');
        if (null === $twigAdapter) {
            return;
        }

        foreach ($app->getContainer()->findTaggedServiceIds('twig.extension') as $id => $data) {
            $twigAdapter->addExtension($app->getContainer()->get($id));
        }
    }
731466
public function fire(Application $app)
    {
        if (!$this->confirmToProceed()) {
            return;
        }

        $this->output->writeln('<info>Run application migrations ...</info>');
        $this->call('migrate');

        $this->output->writeln('<info>Run modules migrations ...</info>');
        $installer = new ModulesInstaller($app['modules.loader']->getRegisteredModules());

        $installer->cleanOutputMessages();

        if ($this->input->getOption('rollback')) {
            $installer->resetModules();
        }

        $installer->migrateModules();

        foreach ($installer->getOutputMessages() as $message) {
            $this->output->writeln($message);
        }

        // Finally, if the "seed" option has been given, we will re-run the database
        // seed task to re-populate the database, which is convenient when adding
        // a migration and a seed at the same time, as it is only this command.
        if ($this->input->getOption('seed')) {
            $this->call('db:seed');
            $this->call('modules:seed');
        }
    }
708910
public void onApplicationEvent(ApplicationEvent e) {
		if (e instanceof LifecycleApplicationEvent) {
			LifecycleApplicationEvent le = (LifecycleApplicationEvent) e;
			if (shouldHandleEvent(e)) {
				if (le.getEventType() == LifecycleApplicationEvent.CREATED) {
					handleNewObject(le.getObject());
				} else if (le.getEventType() == LifecycleApplicationEvent.MODIFIED) {
					handleUpdatedObject(le.getObject());
				} else if (le.getEventType() == LifecycleApplicationEvent.DELETED) {
					handleDeletedObject(le.getObject());
				}
			}
		}
	}
433420
public function boot(Event $event, Application $app)
    {
        /** @var IConfig $config */
        $config = $this->di->get('config');
        //获取概率xhprof
        $prob = (int)$config->get('xhprof.prob', 1);
        if ($prob <= 0 || $prob > 1) {
            $prob = 1;
        }
        $mtMax = intval(1 / $prob);
        //在一定概率下执行
        if (mt_rand(1, $mtMax) == 1) {
            xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
            $this->xhprofOn = true;
        }
    }
158851
public function process(array &$job)
    {
        $this->job = &$job;
        $this->errors = array();

        if (empty($this->job['data']['sources'][$this->job['done']])) {
            $this->job['status'] = false;
            $this->job['done'] = $this->job['total'];
        } else {
            $this->install();
            $this->job['done']++;
            $this->job['errors'] += $this->countErrors();
        }
    }
219824
protected function setupEventListening(Container $app)
    {
        $app['events']->listen('content.rendering', function (View $view) use ($app) {
            if ($viewData = array_merge($view->getFactory()->getShared(), $view->getData())) {
                $decorator = $app['autopresenter'];
                foreach ($viewData as $key => $value) {
                    $view[$key] = $decorator->decorate($value);
                }
            }
        });
    }
980347
protected function job(): void
    {
        while (true) {

            $contacts = $this->retrieve([
                'corporation_id' => $this->getCorporationId(),
            ]);

            if ($contacts->isCachedLoad()) return;

            collect($contacts)->each(function ($contact) {

                CorporationContact::firstOrNew([
                    'corporation_id' => $this->getCorporationId(),
                    'contact_id'     => $contact->contact_id,
                ])->fill([
                    'standing'     => $contact->standing,
                    'contact_type' => $contact->contact_type,
                    'is_watched'   => $contact->is_watched ?? false,
                    'label_ids'    => $contact->label_ids ?? null,
                ])->save();
            });

            $this->known_contact_ids->push(collect($contacts)
                ->pluck('contact_id')->flatten()->all());

            if (! $this->nextPage($contacts->pages))
                break;
        }

        // Cleanup old contacts
        CorporationContact::where('corporation_id', $this->getCorporationId())
            ->whereNotIn('contact_id', $this->known_contact_ids->flatten()->all())
            ->delete();
    }