public function validate($value, Constraint $constraint) { if (!$constraint instanceof OrchestrationEntity) { throw new \InvalidArgumentException('Given constraint must ne instance of OrchestrationEntity class'); } // orchestration exists try { $orchestration = $constraint->getOrchestrationManager()->findOrchestrationById($value, $constraint->getToken(), true); if (!$orchestration) { throw new \Exception('Orchestration does not exists'); } } catch (\Exception $e) { $this->context->addViolation($constraint->message, array('%string%' => $value)); return; } }
public function validate($value, Constraint $constraint) { if (!$constraint instanceof UniqueOrchestrationEntity) { throw new \InvalidArgumentException('Given constraint must ne instance of UniqueOrchestrationEntity class'); } if ($value) { try { $orchestrations = $constraint->getOrchestrationManager()->findOrchestrations(array('projectId' => $constraint->getToken()->getProjectId())); $configurationOrchestrations = array_filter($orchestrations, function ($orchestration) use($value) { return $orchestration->getConfigurationId() == $value; }); if (!empty($configurationOrchestrations)) { throw new \Exception('Configuration table is used by other orchestration'); } } catch (\Exception $e) { $this->context->addViolation($constraint->message, array('%string%' => $value)); return; } } }