Api to buffer events to store, to reduce db queries.

@param \core\event\base $event
355822
protected function buffer_event(\core\event\base $event) {

        // If there are no subscriptions for this event do not buffer it.
        if (!\tool_monitor\subscription_manager::event_has_subscriptions($event->eventname, $event->courseid)) {
            return;
        }

        $eventdata = $event->get_data();
        $eventobj = new \stdClass();
        $eventobj->eventname = $eventdata['eventname'];
        $eventobj->contextid = $eventdata['contextid'];
        $eventobj->contextlevel = $eventdata['contextlevel'];
        $eventobj->contextinstanceid = $eventdata['contextinstanceid'];
        if ($event->get_url()) {
            // Get link url if exists.
            $eventobj->link = $event->get_url()->out();
        } else {
            $eventobj->link = '';
        }
        $eventobj->courseid = $eventdata['courseid'];
        $eventobj->timecreated = $eventdata['timecreated'];

        $this->buffer[] = $eventobj;
        $this->count++;
    }
946335
public function eventAfterDelete($event)
    {
        if ($this->isLoggable()) {
            Yii::$app->db->createCommand()->insert('{{%admin_ngrest_log}}', [
                'user_id' => $this->getUserId(),
                'timestamp_create' => time(),
                'route' => $this->route,
                'api' => $this->api,
                'is_insert' => false,
                'is_update' => false,
                'is_delete' => true,
                'attributes_json' => $this->toJson($event->sender->getAttributes()),
                'table_name' => $event->sender->tableName(),
                'pk_value' => implode("-", $event->sender->getPrimaryKey(true)),
            ])->execute();
        }
    }
1126655
public function onGetDatabaseResources(GetDatabaseResourcesEvent $event)
    {
        // prevent errors on command such as cache:clear if doctrine schema has not been updated yet
        if (StorageInterface::STORAGE_ORM == $this->storageType && !$this->storage->translationsTablesExist()) {
            $resources = array();
        } else {
            $resources = $this->storage->getTransUnitDomainsByLocale();
        }

        $event->setResources($resources);
    }
989639
public function onPreSerialize(PreSerializeEvent $event)
    {
        $object = $event->getObject();
        if ($object instanceof ExtRefHoldingDocumentInterface && $object->isEmptyExtRefObject() === true) {
            $event->setType('Empty', [$object]);
        }
    }
1186656
public function onPreAutoloadDump(Event $event)
    {
        $basePath = $this->getBasePath($event);
        $lockPath = "{$basePath}/pre.lock";

        $shouldOptimize = $this->shouldOptimize($event);

        if ($shouldOptimize) {
            file_put_contents($lockPath, time());

            if (!file_exists("{$basePath}/vendor/autoload.php")) {
                return;
            }

            require_once "{$basePath}/vendor/autoload.php";

            $directory = new RecursiveDirectoryIterator($basePath);

            $files = new RecursiveIteratorIterator(
                $directory, RecursiveIteratorIterator::SELF_FIRST
            );

            foreach ($files as $file) {
                if (stripos($file, "{$basePath}/vendor") === 0) {
                    continue;
                }

                if ($file->getExtension() !== "pre") {
                    continue;
                }

                $pre = $file->getPathname();
                $php = preg_replace("/pre$/", "php", $pre);

                compile(
                    $pre, $php, $format = true, $comment = false
                );
            }
        } else {
            if (file_exists($lockPath)) {
                unlink($basePath . "/pre.lock");
            }
        }
    }
857105
public function beforeSend($event = null)
    {
        if (isset($this->stream)) {
            return;
        }
        if (isset($this->controller) && $this->task) {
            if ($this->isInstructable) {
                $this->format = static::FORMAT_JSON;
                $this->data = $this->generateInstructions();
            } else {
                $this->handleFlashStatus();
                if ($this->redirect) {
                    $this->redirect($this->redirect);
                } elseif ($this->refresh) {
                    $this->refresh();
                } else {
                    if (is_null($this->content)) {
                        $this->content = $this->renderContent(true);
                    }
                }
            }
        }
    }
564525
protected function handle(Event $event): void
    {
        $method = 'apply'.ClassName::short($event);

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

        $this->$method($event);
    }
26013
public function onFlushPage(Event $event)
    {
        // Checks if page caching is available
        $this->object = $event->getTarget();
        if (false === ($this->object instanceof Page) || false === $this->checkCachePageEvent(false)) {
            return;
        }

        if (true === $this->page_cache_deletion_done) {
            return;
        }

        $pages = ScheduledEntities::getScheduledEntityUpdatesByClassname(
            $this->application->getEntityManager(), 'BackBee\NestedNode\Page'
        );
        if (0 === count($pages)) {
            return;
        }

        $page_uids = array();
        foreach ($pages as $page) {
            $page_uids[] = $page->getUid();
        }

        $this->cache_page->removeByTag($page_uids);
        $this->page_cache_deletion_done = true;
        $this->application->debug(sprintf(
            'Remove cache for `%s(%s)`.',
            get_class($this->object),
            implode(', ', $page_uids)
        ));
    }
453667
public function beforeApiRequestSend($event)
    {
        $request = $event->request;
        $data = $request->getData();
        $data['openid'] = $this->getOpenid();
        $request->setData($data);

        parent::beforeApiRequestSend($event);
    }
1310723
private function fireEvent($event)
    {
        $env = $this->formatEventName($event);

        if (emitter()->bound($env)) {
            emitter()->emit($env, $this);
        }
    }
1140200
public function handleApiEvent($event)
    {
        $eventName = str_replace('.queued', null, $event->name);
        $ckey = 'event:' . $eventName;
        $records = Cache::remember($ckey, Config::get('df.default_cache_ttl'), function () use ($eventName) {
            return ServiceEventMap::whereEvent($eventName)->get()->all();
        });
        if (empty($records)) {
            // Look for wildcard events by service (example: user.*)
            $serviceName = substr($eventName, 0, strpos($eventName, '.'));
            $wildcardEvent = $serviceName . '.*';
            $ckey = 'event:' . $wildcardEvent;
            $records = Cache::remember($ckey, Config::get('df.default_cache_ttl'), function () use ($wildcardEvent) {
                return ServiceEventMap::whereEvent($wildcardEvent)->get()->all();
            });
        }

        /** @var BaseModel $record */
        foreach ($records as $record) {
            Log::debug('Service event handled: ' . $eventName);
            /** @var BaseRestService $service */
            $service = \ServiceManager::getServiceById($record->service_id);
            Event::fire(new ServiceAssignedEvent($service, $event, $record->toArray()));
        }
    }
761521
protected function dispatchEvent($event)
    {
        if (!$this->container) {
            throw new \RuntimeException("The container has not been set up.");
        }
        $dir = $this->container->getParameter('base_dir');
        if (!is_dir($dir) || !is_readable($dir)) {
            throw new \RuntimeException("'${dir}' is not a valid readable directory.");
        }
        $dispatcher = $this->container->get('event_dispatcher');
        $dispatcher->dispatch($event);
    }
1011092
final private function replayChange(Event $event)
    {
        $this->apply($event->payload());
        $this->lastCommittedEventSequenceNumber = $event->sequenceNumber();
    }
85211
public function setEvent($event)
  {
    if ($event === '?' || $event === '') {
      $this->event = null;
    } else {
      $event = Util::foreignLettersToEnglishLetters($event);
      $event = Util::titleCaseIfCurrentlyAllCaps($event);
      $this->event = $event === '?' ? null : $event;
    }
  }
302888
public static function dispatch(\core\event\base $event) {
        if (during_initial_install()) {
            return;
        }
        if (!$event->is_triggered() or $event->is_dispatched()) {
            throw new \coding_exception('Illegal event dispatching attempted.');
        }

        self::$buffer[] = $event;

        if (self::$dispatching) {
            return;
        }

        self::$dispatching = true;
        self::process_buffers();
        self::$dispatching = false;
    }
325619
public static function execute(Event $event) {
    $composer = $event->getComposer();
    $handler = new static(
      $composer->getPackage(),
      $composer->getLocker()
    );
    $encoder = new IniEncoder();
    $make = $handler->make();
    $core = $handler->makeCore($make);
    file_put_contents('drupal-org-core.make', $encoder->encode($core));
    file_put_contents('drupal-org.make', $encoder->encode($make));
  }
1283784
protected function eventWasProcessed($event)
    {
        if ($this->eventExpired($event)) {
            return true;
        }

        $this->resetEventCache($event);

        return false;
    }