Handle POST requests

@param EventInterface $event
182476
public function addImage(EventInterface $event) {
        $request = $event->getRequest();
        $response = $event->getResponse();
        $image = $request->getImage();

        // attempt to store the image in the underlying database
        $maxAttempts = 100;
        $config = $event->getConfig();

        // retrieve and instantiate if necessary the image identifier generator
        $imageIdentifierGenerator = $config['imageIdentifierGenerator'];

        if (is_callable($imageIdentifierGenerator) &&
            !($imageIdentifierGenerator instanceof GeneratorInterface)) {
            $imageIdentifierGenerator = $imageIdentifierGenerator();
        }

        for ($attempt = 0; $attempt < $maxAttempts; $attempt++) {
            try {
                $image->setImageIdentifier($imageIdentifierGenerator->generate($image));
                $event->getManager()->trigger('db.image.insert', ['updateIfDuplicate' => $imageIdentifierGenerator->isDeterministic()]);
                break;
            } catch (DuplicateImageIdentifierException $exception) {
                // the image identifier already exists - or was created before we inserted
                // so we retry the event to get the last submitted image
                if ($imageIdentifierGenerator->isDeterministic()) {
                    $event->getManager()->trigger('db.image.insert', ['updateIfDuplicate' => $imageIdentifierGenerator->isDeterministic()]);
                }

                continue;
            }
        }

        // Image Identifier generation failed - throw exception to get us out of this state
        if ($attempt === $maxAttempts) {
            $e = new ImageException('Failed to generate unique image identifier', 503);
            $e->setImboErrorCode(ImageException::IMAGE_IDENTIFIER_GENERATION_FAILED);

            // Tell the client it's OK to retry later
            $event->getResponse()->headers->set('Retry-After', 1);
            throw $e;
        }

        $event->getManager()->trigger('storage.image.insert');

        $model = new Model\ArrayModel();
        $model->setData([
            'imageIdentifier' => $image->getImageIdentifier(),
            'width' => $image->getWidth(),
            'height' => $image->getHeight(),
            'extension' => $image->getExtension(),
        ]);

        $response->setModel($model);
    }
991019
public function save(EventInterface $event)
    {
        $uuid = (string) $event->uuid();
        $version = ($this->count($event->uuid())) ?: 0;
        $type = $event->type();
        $payload = $event->payload();
        $body = serialize($event->body());
        $occurredOn = $event->occurredOn()->format('Y-m-d H:i:s.u');

        $sql = 'INSERT INTO `'.PdoDriver::EVENTSTORE_TABLE_NAME.'` (
                    `uuid`,
                    `version`,
                    `payload`,
                    `type`,
                    `body`,
                    `occurred_on`
                  ) VALUES (
                    :uuid,
                    :version, 
                    :payload, 
                    :type,
                    :body, 
                    :occurred_on
            )';

        $stmt = $this->connection->prepare($sql);
        $stmt->bindParam(':uuid', $uuid);
        $stmt->bindParam(':version', $version);
        $stmt->bindParam(':payload', $payload);
        $stmt->bindParam(':type', $type);
        $stmt->bindParam(':body', $body);
        $stmt->bindParam(':occurred_on', $occurredOn);
        $stmt->execute();
    }
209013
public function handle(EventInterface $event)
    {

        try {
            // load the application server and the naming directory instance
            /** @var \AppserverIo\Psr\ApplicationServer\ApplicationServerInterface $applicationServer */
            $applicationServer = $this->getApplicationServer();
            /** @var \AppserverIo\Psr\Naming\NamingDirectoryInterface $namingDirectory */
            $namingDirectory = $applicationServer->getNamingDirectory();

            // load the configuration filename
            $configurationFilename = $applicationServer->getConfigurationFilename();

            // write a log message that the event has been invoked
            $applicationServer->getSystemLogger()->info($event->getName());

            // load the setup mode from the naming directory
            $setupMode = $namingDirectory->search('php:env/args/s');
            $currentUser = $namingDirectory->search('php:env/currentUser');

            // load the service instance and switch to the new setup mode
            /** @var \AppserverIo\Appserver\Core\Api\ContainerService $service */
            $service = $applicationServer->newService('AppserverIo\Appserver\Core\Api\ContainerService');
            $service->switchSetupMode($setupMode, $configurationFilename, $currentUser);

        } catch (NamingException $ne) {
            $applicationServer->getSystemLogger()->error('Please specify a setup mode, e. g. \'./server.php -s prod\'');
        } catch (\Exception $e) {
            $applicationServer->getSystemLogger()->error($e->__toString());
        }
    }
901792
public function dispatch(EventInterface $event)
    {
        if (array_key_exists($event->getName(), $this->listeners)) {
            foreach ($this->listeners[$event->getName()] as $listener) {
                $listener($event);
            }
        }

        return $event;
    }
804075
protected function handle(Event $event)
    {
        $method = $this->getApplyMethod($event);
        if (!method_exists($this, $method)) {
            return;
        }
        $this->$method($event);
    }
1143383
public function handle(EventInterface $event)
    {
        if ($event instanceof StatsEvent) {
            $this->writeProgressionLine('');
            $this->style->success('Phar creation successful');
            $this->style->table([], [
                ['Path', '<info>' . $event->getStats()->getFinalPath() . '</info>'],
                ['File size', '<info>' . $event->getSize() . '</info>'],
                ['Process duration', '<info>' . $event->getDuration() . '</info>']
            ]);
        }

        if ($event instanceof BuilderAddEvent) {
            $this->writeProgressionLine('Adding <comment>' . $event->getPath() . '</comment>');
        }

        if ($event instanceof CompressorEvent) {
            $this->writeProgressionLine('<info>Compressing...</info>');
        }

        if (0 === strpos($event->getName(), 'options.')) {
            $this->writeProgressionLine(
                '<comment>Read options...</comment> (' . ucfirst(substr($event->getName(), \strlen('options.'))) . ')',
                true
            );
        }
    }
747209
public function updateModel(EventInterface $event) {
        $image = $event->getArgument('image');

        if ($image->hasBeenTransformed()) {
            $image->setBlob($this->imagick->getImageBlob());
        }
    }
1075425
public function process(EventInterface $event)
    {
        $events = $this->getEventManager();
        $mapper = $this->getMapper();
        $optionsProvider = $this->getOptionsProvider();
        $translator = $this->getTranslator();
        $pane = $event->getParam('pane');
        if (! $optionsProvider->hasIdentifier($pane)) {
            return;
        }
        $options = $optionsProvider->getOptions($pane);
        if ($options->getType() == 'search' || $options->getRoot() == 'site') {
            return;
        }
        try {
            $mapper->beginTransaction();
            $tid = $mapper->getTransactionIdentifier();
            $events->trigger(
                __FUNCTION__ . '.clean.pre',
                null,
                [
                    'tid' => $tid,
                ]
            );
            $mapper->clean($tid);
            $mapper->commit();
        } catch (Exception $e) {
            if (DEBUG_MODE) {
                throw new DebugException(
                    $translator->translate('Error: ') . $e->getMessage(),
                    $e->getCode(),
                    $e
                );
            }
            $meta = $mapper->findMetaById($id);
            $name = isset($meta['title']) ? $meta['title'] : $id;
            $this->setValue($name)->error(self::UnexpectedError);
        }

        return $this->redirect($event, 'sc-admin/file/delete');
    }
570296
public function handle(EventInterface $event)
    {

        try {
            // load the application server instance
            /** @var \AppserverIo\Psr\ApplicationServer\ApplicationServerInterface $applicationServer */
            $applicationServer = $this->getApplicationServer();

            // unbind the loggers from the naming directory
            foreach (array_keys($applicationServer->getLoggers()) as $name) {
                $applicationServer->getNamingDirectory()->unbind(sprintf('php:global/log/%s', $name));
            }

            // set the initialized loggers finally
            $applicationServer->setLoggers(array());

        } catch (\Exception $e) {
            error_log($e->__toString());
        }
    }
735100
public function sendResponse(ResponseInterface $response) : void
    {
        if (!headers_sent()) {
            $this->sendStatusLine($response);
            $this->sendHeaders($response);
        }
        $this->eventDispatcher->dispatch(new EventAfterAppReponseHeadersSending($response));
        $this->sendBody($response);
    }
772233
public function handle(EventListenerInterface $listener)
    {
        if (!$listener->getListeners()) {
            return;
        }

        $content = $this->request->getContent();

        try {
            $options = Serializer::parse($content);
        } catch (\InvalidArgumentException $e) {
            $options = [];
        }

        foreach ($listener->getListeners() as $namespace => $callable) {
            $event = new $namespace($options);
            if ($event->isValid()) {
                $listener->trigger($namespace, $event);
                break;
            }
        }
    }
95885
public function submit(FormEvent $event)
    {
        $entity = $event->getData();
        
        if ($entity instanceof FileInterface && null === $entity->getId() && null === $entity->getHash()){
            $event->setData(null);
        }
    }
1015020
public function onRequestSent(Event $event)
    {
        $request = $event['request'];
        $response = $event['response'];
        $exception = $event['exception'];

        $params = $request->getParams();
        $retries = (int) $params->get(self::RETRY_PARAM);
        $delay = $this->strategy->getBackoffPeriod($retries, $request, $response, $exception);

        if ($delay !== false) {
            // Calculate how long to wait until the request should be retried
            $params->set(self::RETRY_PARAM, ++$retries)
                ->set(self::DELAY_PARAM, microtime(true) + $delay);
            // Send the request again
            $request->setState(RequestInterface::STATE_TRANSFER);
            $this->dispatch(self::RETRY_EVENT, array(
                'request'  => $request,
                'response' => $response,
                'handle'   => $exception ? $exception->getCurlHandle() : null,
                'retries'  => $retries,
                'delay'    => $delay
            ));
        }
    }
160921
public function handle(EventInterface $event)
    {

        try {
            // load the application server instance
            /** @var \AppserverIo\Psr\ApplicationServer\ApplicationServerInterface $applicationServer */
            $applicationServer = $this->getApplicationServer();

            // write a log message that the event has been invoked
            $applicationServer->getSystemLogger()->info($event->getName());

            // print a message with the old UID/EUID
            $applicationServer->getSystemLogger()->info("Running as " . posix_getuid() . "/" . posix_geteuid());

            // extract the variables
            $uid = 0;
            extract(posix_getpwnam('root'));

            // switcht the effective UID to the passed user
            if (posix_seteuid($uid) === false) {
                $applicationServer->getSystemLogger()->error(sprintf('Can\'t switch UID to \'%s\'', $uid));
            }

            // print a message with the new UID/EUID
            $applicationServer->getSystemLogger()->info("Running as " . posix_getuid() . "/" . posix_geteuid());

            // @TODO Switch group also!!!!

        } catch (\Exception $e) {
            $applicationServer->getSystemLogger()->error($e->__toString());
        }
    }
998842
public function remove(EventInterface $event)
    {
        $index = $this->computeIndex($event);
        if (isset($this->events[$index])) {
            foreach ($this->events[$index] as $key => $internalEvent) {
                if ($event->getUid() == $internalEvent->getUid()) {
                    unset($this->events[$index][$key]);
                    --$this->count;
                }
            }
        }
    }
524692
public function record(EventInterface $event)
    {
        $eventUuid = $event->uuid();
        $this->recordedEvents[(string) $eventUuid] = $event;
    }
120259
public function deleteImage(EventInterface $event) {
        $event->getManager()->trigger('db.image.delete');
        $event->getManager()->trigger('storage.image.delete');

        $model = new Model\ArrayModel();
        $model->setData([
            'imageIdentifier' => $event->getRequest()->getImageIdentifier(),
        ]);

        $event->getResponse()->setModel($model);
    }