Exemple #1
0
 public function onContentItemParsed(ContentParsedEvent $event)
 {
     $errors = $this->validate($event->getContentItem());
     if (count($errors) > 0) {
         throw new RuntimeException((string) $errors);
     }
 }
Exemple #2
0
 /**
  * {@inheritDoc}
  */
 public function onContentItemParsed(ContentParsedEvent $event)
 {
     $contentItem = $event->getContentItem();
     $metadata = $this->metadata->getMetadataFor($contentItem);
     $format = $this->getFormatterForContentItem($contentItem, $metadata);
     $properties = $metadata->getConstrainedProperties();
     foreach ($properties as $property) {
         foreach ($metadata->getMemberMetadatas($property) as $memberMetadata) {
             $formatValue = false;
             foreach ($memberMetadata->getConstraints() as $constraint) {
                 if (!$formatValue && $constraint->format) {
                     $formatValue = $constraint->format;
                 }
             }
             // If raw is null, this could be a non-required property.
             if (!$formatValue || !($raw = $memberMetadata->getPropertyValue($contentItem))) {
                 continue;
             }
             $formatted = $this->format($raw, $format);
             $memberMetadata->getReflectionMember($contentItem)->setValue($contentItem, $formatted);
         }
     }
 }