Handle process flag

@param Envelope $envelope
@param $flag
@return void
321761
protected function handleProcessFlag(Envelope $envelope, DeliveryResult $flag)
    {
        $this->countMessagesConsumed++;

        switch ($flag) {
            case DeliveryResult::MSG_REJECT():
                $this->queue->nack($envelope->getDeliveryTag(), Constants::AMQP_NOPARAM);
                $this->logger->debug('Rejected message', $this->extractMessageInformation($envelope));
                break;
            case DeliveryResult::MSG_REJECT_REQUEUE():
                $this->queue->nack($envelope->getDeliveryTag(), Constants::AMQP_REQUEUE);
                $this->logger->debug('Rejected and requeued message', $this->extractMessageInformation($envelope));
                break;
            case DeliveryResult::MSG_ACK():
                $this->countMessagesUnacked++;
                $this->lastDeliveryTag = $envelope->getDeliveryTag();
                $this->timestampLastMessage = microtime(true);
                $this->ack();
                break;
            case DeliveryResult::MSG_DEFER():
                $this->countMessagesUnacked++;
                $this->lastDeliveryTag = $envelope->getDeliveryTag();
                $this->timestampLastMessage = microtime(true);
                break;
        }
    }
1366458
public function handle(ReactionHasBeenRemoved $event): void
    {
        $reaction = $event->getReaction();
        $reactant = $reaction->getReactant();

        (new ReactionCounterService($reactant))
            ->removeReaction($reaction);

        (new ReactionTotalService($reactant))
            ->removeReaction($reaction);
    }
483622
protected function handleSignals(): void
    {
        foreach ([SIGTERM, SIGQUIT, SIGABRT, SIGINT] as $signal) {
            pcntl_signal($signal, function ($signal) {
                $this->terminate($signal);
            });
        }
    }
528761
public function removeFlag($flag)
    {
        
        $currentFlags = $this->getFlags();
        for ($i = 0; $i < count($currentFlags); $i++){
            if ($currentFlags[$i] == $flag){
                break;
            }
        }
        
        if ($i <= count($currentFlags)){
            // The flag is found.
            unset($currentFlags[$i]);
            $this->setFlags($currentFlags);
        }
        
    }
1113969
public function setExtractFlags($flag)
    {
        switch ($flag) {
            case self::EXTR_DATA:
            case self::EXTR_PRIORITY:
            case self::EXTR_BOTH:
                $this->extractFlag = $flag;
                break;
            default:
                throw new Exception\InvalidArgumentException("The extract flag specified is not valid");
        }
    }
1148763
private function _setLoggingFlag($flag, $boolean = true)
    {
        if ($boolean) {
            $this->_logLevel |= $flag;
        } else {
            $this->_logLevel &= ~$flag;
        }
    }
885377
public function handleDbEvent($e) {
    $statement = $e->getParam('statement', null);
    if ($statement != null) {
      $this->statements[] = [$statement->getSql(), $statement->getParameterContainer()->getNamedArray()];
    }
  }
1166875
public function process ()
    {
        if ($this->isProcessed)
            return;
        $this->isProcessed = true;
        foreach ($this->getFields() as $field)
            /* @var $field Field */
            $field->preprocess();
        $this->isUserSubmitted = $this->getValue($this->getSubmitConfirmFieldName(), 'false') == 'true' || $this->forceSubmit;
        if ($this->isUserSubmitted) {
            foreach ($this->getFields() as $field)
                $field->restoreValue($this->method);

            $this->activateHandlers();

            if ($this->isValid()) {
                $this->submit();
            }
        }
    }
675627
public function handle(Envelope $envelope, StackInterface $stack): Envelope
    {
        $message = $envelope->getMessage();
        $msg = $message->getMessage();

        if (!$msg instanceof AbstractPushMessage) {
            return $stack->next()->handle($envelope, $stack);
        }

        if (0 === \count($envelope->all(ReceivedStamp::class))) {
            return $stack->next()->handle($envelope, $stack);
        }

        $rawMessage = $msg->getRawMessage();

        foreach ($rawMessage->getRecipients() as $recipient) {
            foreach ($this->repository->findUserEnableDevices($recipient->getUser()) as $device) {
                $this->sender->sendTo($device, $rawMessage);
            }
        }

        return $stack->next()->handle($envelope, $stack);
    }
473987
private function message_has_flag($messageid, $flag) {
        // Get the current mailbox.
        $mailbox = $this->get_mailbox();

        // Grab messagedata including flags.
        $query = new \Horde_Imap_Client_Fetch_Query();
        $query->flags();
        $query->structure();
        $messagedata = $this->client->fetch($mailbox, $query, array(
            'ids' => $messageid,
        ))->first();
        $flags = $messagedata->getFlags();

        return in_array($flag, $flags);
    }
1032493
private function process(array $element, $parent = null)
    {
        $apiElement = $element['element'];

        if (isset($this->elementMap[$apiElement])) {
            $this->processElement(
                $element,
                $this->elementMap[$apiElement],
                $parent
            );
        }

        if ($element['element'] === 'category') {
            // todo extend the element map to check for classes, then merge processCategory into processElement
            $this->processCategory($element, $parent);
        }
    }
443245
public void setResponse(Envelope response) {
    if (response.hasControl() && response.getControl().hasError()) {
      setException(new Exception(response.getControl().getError()));
      return;
    }
    try {
      set(clientMethod.outputParser().parseFrom(response.getPayload()));
      clientLogger.logSuccess(clientMethod);
    } catch (InvalidProtocolBufferException ipbe) {
      setException(ipbe);
    }
  }
1010684
public function setStatus($status, $envelope = null)
	{
		// Check if we're not in a final state yet
		if ($this->status > 0) {
			throw new \RuntimeException('Cannot change status from final state ' . $this->status . ' to state ' . $status . '.');
		}

		// Check if this is a valid state
		if ( !in_array($status, array_keys(self::$statusDescriptionMapping)) ) {
			throw new \InvalidArgumentException('Status ' . $status . ' is not a valid status.');
		}

		// Check if the retry envelope is not this envelope
		if ($this === $envelope) {
			throw new \InvalidArgumentException('Retry envelope cannot be set to this envelope.');
		}

		// Save it!
		$this->status = $status;
		$this->retryEnvelope = $envelope;
	}
185977
public function handle(ReactionHasBeenAdded $event): void
    {
        $reaction = $event->getReaction();
        $reactant = $reaction->getReactant();

        (new ReactionCounterService($reactant))
            ->addReaction($reaction);

        (new ReactionTotalService($reactant))
            ->addReaction($reaction);
    }
91119
public void schedule(Envelope envelope, long time) {
        if (envelope.getMailbox() != this) {
            throw new RuntimeException("envelope.mailbox != this mailbox");
        }

        envelopes.putEnvelope(envelope, time);
    }
232806
private function rejectDispatch($exception, Envelope $envelope, Queue $queue)
    {
        // Make sure the exception is not interfering.
        // Previously failing jobs handling have been moved to a middleware.
        //
        // Emit an event to let others log that exception
        $this->dispatcher->dispatch(BernardEvents::REJECT, new RejectEnvelopeEvent($envelope, $queue, $exception));

        if ($this->options['stop-on-error']) {
            throw $exception;
        }
    }
1106394
public function del($fd, $flag)
    {
        switch ($flag) {
            case static::EV_READ:
            case static::EV_WRITE:
                $fd_key    = (int)$fd;
                if(isset($this->fdEvents[$fd_key][$flag])){
                    $this->fdEvents[$fd_key][$flag]->del();
                    $this->fdEvents[$fd_key][$flag]->free();
                    unset($this->fdEvents[$fd_key][$flag]);
                }
            case static::EV_SIGNAL:
                if(isset($this->signalEvents[$fd])) {
                    $this->signalEvents[$fd]->del();
                    $this->signalEvents[$fd]->free();
                    unset($this->signalEvents[$fd]);
                }
                break;
            case static::EV_INTERVAL:
            case static::EV_TIMEOUT:
                if(isset($this->timerEvents[$fd])) {
                    static::unsetId($fd);
                    $this->timerEvents[$fd]->del();
                    $this->timerEvents[$fd]->free();
                    unset($this->timerEvents[$fd]);
                }
                
                break;
                
        }
    }