context->getObject(); $type = $object->getType(); $markingType = $object->getMarkingType(); $name = $this->context->getObject(); $supports = $object->getSupport(); //Validate Format YAML try { $yaml = Yaml::parse($value,100,2); } catch (DumpException $e) { $this->context->buildViolation("errors.workflow_template_format_error")->setParameter('%string%', "")->addViolation(); return; } catch (ParseException $e) { $this->context->buildViolation("errors.workflow_template_format_error")->setParameter('%string%', "")->addViolation(); return; } if(!is_array($yaml)) { $this->context->buildViolation("errors.workflow_template_format_error")->setParameter('%string%', "")->addViolation(); return; } if($yaml) { $no_valid_key = false; foreach($yaml as $key => $d) { if(!in_array($key,$valids_keys)) { $no_valid_key = true; $this->context->buildViolation("errors.workflow_template_key_invalid")->setParameter('%key%', $key)->addViolation(); } } if($no_valid_key) return; } else { $this->context->buildViolation("errors.workflow_template_format_error")->setParameter('%string%', "")->addViolation(); return; } //Validate Template SUPPORTS if(!is_null($supports)) { if(count($supports) == 0) { $this->context->buildViolation("errors.workflow_template_supports_empty")->setParameter('%string%', "")->addViolation(); } else { foreach($supports as $k => $class) { if(!class_exists($class)) { $this->context->buildViolation("errors.workflow_template_supports_class_error")->setParameter('%class%', $class)->addViolation(); } } } } else { $this->context->buildViolation("errors.workflow_template_supports_undefined")->setParameter('%string%', "")->addViolation(); } //Validate Template PLACES $places = array(); if(isset($yaml['places'])) { $places = $yaml['places']; } else { $this->context->buildViolation("errors.workflow_template_places_undefined")->setParameter('%string%', "")->addViolation(); } $transitions = array(); if(isset($yaml['transitions'])) { foreach($yaml['transitions'] as $k => $data) { if(isset($data['from']) && isset($data['to'])) { $transitions[] = new Transition($k,$data['from'],$data['to']); } else { $this->context->buildViolation("errors.workflow_template_transitions_format")->setParameter('%transition%', $k)->addViolation(); } } } else { $this->context->buildViolation("errors.workflow_template_transitions_undefined")->setParameter('%string%', "")->addViolation(); } //Validate Definition if($type == "workflow") { $mt = ($markingType == "single_state"); $validator = new WorkflowValidator($mt); } else { $validator = new StateMachineValidator(); } $initialPlace = null; if(isset($yaml['initial_place'])) { $initialPlace = $yaml['initial_place']; } try { $definition = new Definition($places,$transitions,$initialPlace); $validator->validate($definition, $name); } catch (\Exception $e) { $this->context->buildViolation("Exception: ".$e->getMessage())->setParameter('%string%', "")->addViolation(); return; } catch (\LogicException $e) { $this->context->buildViolation("Exception: ".$e->getMessage())->setParameter('%string%', "")->addViolation(); return; } } }