called on the first schema validation, before anything else.

@param ConstraintEventSchema $event event

@return void
505435
public function onSchemaValidation(ConstraintEventSchema $event)
    {
        $this->currentSchema = $event->getSchema();
        $this->currentData = $event->getElement();
    }
924979
public function validate($value, Constraint $constraint)
    {
        $value = trim($value);

        parent::validate($value, $constraint);
    }
447946
public function checkIncrementalDate(ConstraintEventFormat $event)
    {
        $schema = $event->getSchema();

        if (!isset($schema->{'x-constraints'}) ||
            (is_array($schema->{'x-constraints'}) && !in_array('incrementalDate', $schema->{'x-constraints'}))
        ) {
            return;
        }

        // get the current record
        $path = $this->utils->getNormalizedPathFromPointer($event->getPath());
        $currentRecord = $this->utils->getCurrentEntity([$path]);

        if (is_null($currentRecord)) {
            return;
        }

        $data = $event->getElement();

        // get the current value in database
        $accessor = PropertyAccess::createPropertyAccessor();

        if (!$accessor->isReadable($currentRecord, $path)) {
            // value is not saved in db..
            return;
        }

        $storedValue = $accessor->getValue($currentRecord, $path);
        $storedDate = Rfc3339::createFromString($storedValue);
        $userDate = Rfc3339::createFromString($data);

        if ($userDate <= $storedDate) {
            $event->addError(
                sprintf('The date must be greater than the saved date %s', $storedValue)
            );
        }
    }
1240346
public function beforeFind(Event $event)
    {
        $related = $this->_getRelatedModels();
        if ($related === []) {
            $this->associations = [];
        } else {
            $this->associations = $this->_associations(array_keys($related));
        }

        if (!$event->getSubject()->query->getContain()) {
            $event->getSubject()->query->contain($related);
        }
    }
1341716
public function validate(SchemaDescriptor $schema)
    {
        if ($prevSchema = SchemaStore::getPreviousSchema($schema->getId())) {
            if (!$prevSchema instanceof SchemaDescriptor) {
                throw new \RuntimeException(sprintf(
                    'Un-parsed schema "%s".',
                    $prevSchema['id']
                ));
            }

            /** @var \Gdbots\Pbjc\Validator\Constraint $constraint */
            foreach ($this->constraints as $constraint) {
                $constraint->validate($prevSchema, $schema);
            }
        }

        $constraint = new Constraint\SchemaDependencyVersion();
        $constraint->validate($schema, $schema);

        $constraint = new Constraint\SchemaInheritanceFields();
        $constraint->validate($schema, $schema);

        $constraint = new Constraint\FieldValidEnumValue();
        $constraint->validate($schema, $schema);
    }
357127
public function beforeFilter($event)
    {
        $this->setController($event->subject());

        if (method_exists($this->Controller, 'initMenuItems')) {
            $this->Controller->initMenuItems($event);
        }
    }
726144
public function makeSchemaValidator(EventInterface $event, $schema)
    {
        // we can't validate on an array, only an object
        // so we need to convert the event payload to an object
        $payload = $event->toMessage();
        $payload = json_encode($payload); // back to json
        $payload = json_decode($payload); // from json to an object

        return new Validator($payload, $schema);
    }
883339
public function after($event = []) {
		$modelDynSchema = ClassRegistry::init('CakeLdap.DynSchema');
		$modelDynSchema->updateSchema($event, $this->connection);
	}
860830
public function validate($value, Constraint $constraint): void
    {
        // Build a list of values.
        $item_values = [];
        foreach ($value as $item) {
            $item_value = $this->property_accessor->getValue($item, $constraint->property);

            // If any value is repeated build a violation.
            if (isset($item_values[$item_value])) {
                $this->context->buildViolation($constraint->message)
                    ->setParameter('{{ string }}', $constraint->property)
                    ->addViolation();
            }
            $item_values[$item_value] = true;
        }
    }
1031569
public function beforeValidationOnCreate(Event $event, Model $model)
    {
        if ($model instanceof ICredentialsHolder) {
            $this->createPassword($model);
        }
    }
196832
public function validate($value, Constraint $constraint)
  {
    $valid = false;
    foreach ($constraint->format as $format)
    {
      $date = \DateTime::createFromFormat($format, $value);
      if ($date instanceof \DateTime)
      {
        $valid = true;
        break;
      }
    }
    if ($valid === false)
    {
      $this->context->addViolation($constraint->message, array('%invalid%' => $value));
    }
  }
1268283
public function preCreate(CreateEvent $event)
    {
        /** @var Role $role */
        $role = $event->getObject();

        if (!$role->getWorkspace()) {
            $role->setName(strtoupper('role_'.$role->getTranslationKey()));
        }
    }
1279300
public function onKernelException(GetResponseForExceptionEvent $event): void
    {
        $exception = $event->getException();
        if (!$exception instanceof ValidationException) {
            return;
        }

        $format = ErrorFormatGuesser::guessErrorFormat($event->getRequest(), $this->errorFormats);

        $event->setResponse(new Response(
                $this->serializer->serialize($exception->getConstraintViolationList(), $format['key']),
                Response::HTTP_BAD_REQUEST,
                [
                    'Content-Type' => sprintf('%s; charset=utf-8', $format['value'][0]),
                    'X-Content-Type-Options' => 'nosniff',
                    'X-Frame-Options' => 'deny',
                ]
        ));
    }
410632
public function beforeInsert($event)
    {
        $fields = $this->fields;
        $nowDate = gmdate($this->databaseTimeFormat);
        if (!$this->isActuallyDirty()) {
            return;
        }

        if (isset($this->fields['createdField']) && !$this->owner->isAttributeChanged($this->fields['createdField'])) {
            $this->owner->{$this->fields['createdField']} = $nowDate;
        }
        if (isset($this->fields['createdByField']) && !$this->owner->isAttributeChanged($this->fields['createdByField'])) {
            $this->owner->{$this->fields['createdByField']} = self::_getUserId();
        }

        if (isset($this->fields['modifiedField']) && !$this->owner->isAttributeChanged($this->fields['modifiedField'])) {
            $this->owner->{$this->fields['modifiedField']} = $nowDate;
        }
        if (isset($this->fields['modifiedByField']) && !$this->owner->isAttributeChanged($this->fields['modifiedByField'])) {
            $this->owner->{$this->fields['modifiedByField']} = self::_getUserId();
        }
    }
521062
public function applyConstraints($instance, stdClass $schema, Context $context)
    {
        $cacheKey = gettype($instance).spl_object_hash($schema);
        $constraints = & $this->constraintsCache[$cacheKey];

        if ($constraints === null) {
            $version = $this->getVersion($schema);
            $instanceType = Types::getPrimitiveTypeOf($instance);
            $constraints = $this->registry->getConstraintsForType($version, $instanceType);
            $constraints = $this->filterConstraintsForSchema($constraints, $schema);
        }

        foreach ($constraints as $constraint) {
            $constraint->apply($instance, $schema, $context, $this);
        }
    }
641891
public function beforeValidationOnUpdate(Event $event, Model $model)
    {
        if($model instanceof ITimestampable) {
            $now = $this->getNow();
            $model->setUpdatedAt($now);
        }
    }
79959
public function validate($value, Constraint $constraint)
    {
        /**@var $constraint CodeUnit */
        if (!in_array($value, $this->codes)) {
            $this->context->buildViolation($constraint->message)
                ->setParameter('{{ value }}', $value)
                ->addViolation();
        }
    }