@param EventInterface $event

@return ValidationResult
342466
public function validate(EventInterface $event)
    {
        $schema = $this->getEventSchema($event);
        if ($schema === null) {
            return new ValidationResult($this, $event, true);
        }

        $schemaValidator = $this->makeSchemaValidator($event, $schema);
        if ($schemaValidator->passes()) {
            return new ValidationResult($this, $event, true);
        } else {
            $errors = $schemaValidator->errors();
            return new ValidationResult($this, $event, false, $errors);
        }
    }
692222
public function add(EventInterface $event)
    {
        $index = $this->computeIndex($event);
        if (isset($this->events[$index])) {
            $this->events[$index][] = $event;
        } else {
            $this->events[$index] = array($event);
        }

        ++$this->count;
    }
1372044
public function populateImagickInstance(EventInterface $event) {
        $event->getInputLoaderManager()->setImagick($this->imagick);
        $event->getOutputConverterManager()->setImagick($this->imagick);
    }
787136
protected function prepEventForDispatch(EventInterface $event)
    {
        // automagically inject attributes from injectors
        $attributes = $this->getValuesFromAttributeInjectors();
        $e = clone $event; // we don't want to manipulate the original event
        foreach ($attributes as $k => $v) {
            if (!$e->hasAttribute($k)) {
                $e->setAttribute($k, $v);
            }
        }
        return $e;
    }
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();
    }
665686
public function loadImage(EventInterface $event) {
        $request = $event->getRequest();
        $response = $event->getResponse();

        $event->getDatabase()->load(
            $request->getUser(),
            $request->getImageIdentifier(),
            $response->getModel()
        );
    }
40397
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());

            // load the service instance and create the SSL file if not available
            /** @var \AppserverIo\Appserver\Core\Api\ContainerService $service */
            $service = $applicationServer->newService('AppserverIo\Appserver\Core\Api\ContainerService');
            $service->createSslCertificate(new \SplFileInfo($service->getConfDir(CreateSslCertificateListener::DEFAULT_CERTIFICATE_NAME)));

        } catch (\Exception $e) {
            $applicationServer->getSystemLogger()->error($e->__toString());
        }
    }
45422
public function check(EventInterface $event)
    {
        // Check result
        $result = $event->getResult();
        if (!$result instanceof ViewModel) {
            return;
        }

        // Check for xhr request
        $request = $event->getRequest();
        if ($request->isXmlHttpRequest()) {

            // Set terminal
            $result->setTerminal(true);
            $event->setViewModel($result);
        }
    }
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;
    }
1305987
public function deleteFromCache(EventInterface $event) {
        $request = $event->getRequest();
        $cacheDir = $this->getCacheDir($request->getUser(), $request->getImageIdentifier());

        if (is_dir($cacheDir)) {
            $this->rmdir($cacheDir);
        }
    }
775270
public function save(EventInterface $event)
    {
        $this->events[(string) $event->uuid()][] = new $event(
            $event->uuid(),
            $event->type(),
            $event->body(),
            $this->count($event->uuid()),
            $event->occurredOn()->format('Y-m-d H:i:s.u')
        );
    }
785878
public function inspect(EventInterface $event)
    {
        if (! $event instanceof MvcEvent) {
            return new NullInspection();
        }

        $request = $event->getRequest();

        if (! $request instanceof RequestInterface) {
            return new NullInspection();
        }

        return new RequestInspection($request);
    }
255137
public function dispatch($channel, EventInterface $event)
    {
        $event = $this->prepEventForDispatch($event);
        if ($this->validator) {
            $result = $this->validator->validate($event);
            if ($result->passes()) {
                $this->adapter->publish($channel, $event->toMessage());
            } else {
                // pass to validation fail handler?
                if ($this->validationFailHandler) {
                    call_user_func($this->validationFailHandler, $result);
                }

                if ($this->throwValidationExceptionsOnDispatch) {
                    throw new ValidationException($result);
                }
            }
        } else {
            $this->adapter->publish($channel, $event->toMessage());
        }
    }
156949
public function populate(EventInterface $event) {
        $image = $event->getRequest()->getImage();

        // Get EXIF-properties from image
        $imagick = $this->getImagick();
        $imagick->readImageBlob($image->getBlob());
        $properties = $imagick->getImageProperties();

        // Fix trailing spaces
        foreach ($properties as $key => $value) {
            unset($properties[$key]);
            $properties[trim($key)] = $value;
        }

        // Filter and parse properties
        $properties = $this->filterProperties($properties);
        $properties = $this->parseProperties($properties);

        // Set properties to save on successful image insertion
        $this->properties = $properties;

        return $properties;
    }
952273
public function subscribe(EventInterface $event) {
        $events = [];

        // Enable the event listener only for resources and methods specified
        foreach ($this->params['allowedMethods'] as $resource => $methods) {
            foreach ($methods as $method) {
                $eventName = $resource . '.' . strtolower($method);
                $events[$eventName] = ['invoke' => 1000];
            }

            // Always enable the listener for the OPTIONS method
            $eventName = $resource . '.options';
            $events[$eventName] = ['options' => 20];
        }

        $manager = $event->getManager();
        $manager->addCallbacks($event->getHandler(), $events);

        // Add OPTIONS to the Allow header
        $event->getResponse()->headers->set('Allow', 'OPTIONS', false);
    }
543875
private function evaluateGuard(EventInterface $event)
    {
        foreach ((array) $this->guardEvaluators as $guardEvaluator) {
            $result = call_user_func([$guardEvaluator, 'evaluate'], $event, $this->getPayload(), $this);
            if (!$result) {
                return false;
            }
        }

        return true;
    }
555843
private function validateRule(EventInterface $event, array $rule) {
        $acl = $event->getAccessControl();

        $allowedProperties = ['resources', 'group', 'users'];
        $unknownProperties = array_diff(array_keys($rule), $allowedProperties);

        if (!empty($unknownProperties)) {
            throw new RuntimeException('Found unknown properties in rule: [' . implode(', ', $unknownProperties) . ']', 400);
        }

        if (isset($rule['resources']) && isset($rule['group'])) {
            throw new RuntimeException('Both resources and group found in rule', 400);
        }

        if (!isset($rule['resources']) && !isset($rule['group'])) {
            throw new RuntimeException('Neither group nor resources found in rule', 400);
        }

        if (isset($rule['resources']) && !$this->isStringArray($rule['resources'])) {
            throw new RuntimeException('Illegal value in resources array. String array expected', 400);
        }

        if (isset($rule['group'])) {
            if (!is_string($rule['group'])) {
                throw new RuntimeException('Group must be specified as a string value', 400);
            }

            if (!$acl->getGroup($rule['group'])) {
                throw new RuntimeException('Group \'' . $rule['group'] . '\' does not exist', 400);
            }
        }

        if (!isset($rule['users'])) {
            throw new RuntimeException('Users not specified in rule', 400);
        }

        if ($rule['users'] !== '*' && !$this->isStringArray($rule['users'])) {
            throw new RuntimeException('Illegal value for users property. Allowed: \'*\' or array with users', 400);
        }
    }