/** * {@inheritdoc} */ public function parse(ClassMetadata $metadata, $filename, $content) { @(list($name, $extension) = explode('.', $filename)); $elements = explode('-', $name); // Check if the name is in the correct format. if (($metadata->getDateInFilename() ? 4 : 1) > count($elements) || !$extension) { throw new InvalidArgumentException(sprintf('%s doesn\'t have a valid name. Format should be {name}|{Y}-{m}-{d}-{name}.{format}', $filename)); } $contentItem = new $metadata->name(); // Get the slug from the filename. $slug = implode('-', array_slice($elements, $metadata->getDateInFilename() ? 3 : 0)); $metadata->propertyMetadata['slug']->setValue($contentItem, $slug); $metadata->propertyMetadata['format']->setValue($contentItem, $extension); // Get the creation date from the filename. if ($metadata->getDateInFilename()) { if (!($timestamp = strtotime(implode('-', array_slice($elements, 0, 3))))) { throw new InvalidArgumentException(sprintf('%s doesn\'t have a valid date in the filename', $filename)); } $created = new \DateTime(); $created->setTimestamp($timestamp); $metadata->propertyMetadata['created']->setValue($contentItem, $created); } $body = $this->parseContent($contentItem, $metadata, $content, $filename); $this->parseBody($contentItem, $metadata, $body, $extension, $content, $filename); if ($this->eventDispatcher) { $event = new ContentParsedEvent($contentItem); $this->eventDispatcher->dispatch(Events::CONTENT_PARSED, $event); } return $contentItem; }
private function loadPropertyAnnotations(\ReflectionClass $class, ClassMetadata $metadata) { $loaded = false; foreach ($class->getProperties() as $property) { $fabriciusAnnotation = null; foreach ($this->reader->getPropertyAnnotations($property) as $annot) { $loaded = true; if ($annot instanceof Parameter) { if ($fabriciusAnnotation) { throw new MappingException('More than one Fabricius-related annotation found.'); } $fabriciusAnnotation = $annot; } $metadata->addPropertyConstraint($property->getName(), $annot); } if ($fabriciusAnnotation) { $metadata->addPropertyConstraint($property->getName(), $annot); } } return $loaded; }
protected function getFormatterForContentItem($contentItem, ClassMetadata $metadata) { $properties = $metadata->getConstrainedProperties(); foreach ($properties as $property) { foreach ($metadata->getMemberMetadatas($property) as $memberMetadata) { foreach ($memberMetadata->getConstraints() as $constraint) { if ($constraint instanceof Format) { return $memberMetadata->getPropertyValue($contentItem); } } } } }
/** * {@inheritDoc} */ public function getClassName() { return $this->metadata->getName(); }