private function generateField(array $config, array $class, \EasyRdf_Resource $type, $typeName, $propertyName, \EasyRdf_Resource $property = null)
{
$typeConfig = isset($config['types'][$typeName]) ? $config['types'][$typeName] : null;
$typesDefined = !empty($config['types']);
// Warn when property are not part of GoodRelations
if ($config['checkIsGoodRelations']) {
if (!$this->goodRelationsBridge->exist($propertyName)) {
$this->logger->warning(sprintf('The property "%s" (type "%s") is not part of GoodRelations.', $propertyName, $type->localName()));
}
}
// Ignore or warn when properties are legacy
if (!empty($property) && preg_match('/legacy spelling/', $property->get('rdfs:comment'))) {
if (isset($typeConfig['properties'])) {
$this->logger->warning(sprintf('The property "%s" (type "%s") is legacy.', $propertyName, $type->localName()));
} else {
$this->logger->info(sprintf('The property "%s" (type "%s") is legacy. Ignoring.', $propertyName, $type->localName()));
return $class;
}
}
$propertyConfig = isset($typeConfig['properties'][$propertyName]) ? $typeConfig['properties'][$propertyName] : null;
$ranges = [];
if (isset($propertyConfig['range']) && $propertyConfig['range']) {
$ranges[] = $propertyConfig['range'];
} elseif (!empty($property)) {
foreach ($property->all(self::SCHEMA_ORG_RANGE) as $range) {
if (!$typesDefined || $this->isDatatype($range->localName()) || isset($config['types'][$range->localName()])) {
$ranges[] = $range->localName();
}
}
}
$numberOfRanges = count($ranges);
if (0 === $numberOfRanges) {
$this->logger->error(sprintf('The property "%s" (type "%s") has an unknown type. Add its type to the config file.', $propertyName, $type->localName()));
} else {
if ($numberOfRanges > 1) {
$this->logger->warning(sprintf('The property "%s" (type "%s") has several types. Using the first one.', $propertyName, $type->localName()));
}
$cardinality = isset($propertyConfig['cardinality']) ? $propertyConfig['cardinality'] : false;
if (!$cardinality || $cardinality === CardinalitiesExtractor::CARDINALITY_UNKNOWN) {
$cardinality = $property ? $this->cardinalities[$propertyName] : CardinalitiesExtractor::CARDINALITY_1_1;
}
$ormColumn = isset($propertyConfig['ormColumn']) ? $propertyConfig['ormColumn'] : null;
$isArray = in_array($cardinality, [CardinalitiesExtractor::CARDINALITY_1_N, CardinalitiesExtractor::CARDINALITY_N_N]);
if (isset($propertyConfig['nullable']) && false === $propertyConfig['nullable']) {
$isNullable = false;
} else {
$isNullable = !in_array($cardinality, [CardinalitiesExtractor::CARDINALITY_1_1, CardinalitiesExtractor::CARDINALITY_1_N]);
}
$columnPrefix = false;
$isEmbedded = isset($propertyConfig['embedded']) ? $propertyConfig['embedded'] : false;
if (true === $isEmbedded) {
$columnPrefix = isset($propertyConfig['columnPrefix']) ? $propertyConfig['columnPrefix'] : false;
}
$class['fields'][$propertyName] = ['name' => $propertyName, 'resource' => $property, 'range' => $ranges[0], 'cardinality' => $cardinality, 'ormColumn' => $ormColumn, 'isArray' => $isArray, 'isNullable' => $isNullable, 'isUnique' => isset($propertyConfig['unique']) && $propertyConfig['unique'], 'isCustom' => empty($property), 'isEmbedded' => $isEmbedded, 'columnPrefix' => $columnPrefix, 'isId' => false];
if ($isArray) {
$class['hasConstructor'] = true;
if ($config['doctrine']['useCollection'] && !in_array(self::DOCTRINE_COLLECTION_USE, $class['uses'])) {
$class['uses'][] = self::DOCTRINE_COLLECTION_USE;
}
}
}
return $class;
}