diff --git a/src/DomainContent/FieldValueBuilder/BaseFieldValueBuilder.php b/src/DomainContent/FieldValueBuilder/BaseFieldValueBuilder.php deleted file mode 100644 index 40521193..00000000 --- a/src/DomainContent/FieldValueBuilder/BaseFieldValueBuilder.php +++ /dev/null @@ -1,53 +0,0 @@ - ["[AuthorFieldValue]", '@=resolver("DomainFieldValue", [value, "%s"]).authors'], - 'ezbinaryfile' => 'BinaryFileFieldValue', - 'ezboolean' => ['Boolean', '@=resolver("DomainFieldValue", [value, "%s"]).bool'], - 'ezcountry' => 'String', - 'ezdate' => ['DateTime', '@=resolver("DomainFieldValue", [value, "%s"]).value'], - 'ezdatetime' => ['DateTime', '@=resolver("DomainFieldValue", [value, "%s"]).value'], - 'ezemail' => 'String', - 'ezfloat' => ['Float', '@=resolver("DomainFieldValue", [value, "%s"]).value'], - 'ezgmaplocation' => 'MapLocationFieldValue', - 'ezimage' => 'ImageFieldValue', - 'ezimageasset' => ['ImageFieldValue', '@=resolver("DomainImageAssetFieldValue", [value, "%s"]).value'], - 'ezinteger' => ['Int', '@=resolver("DomainFieldValue", [value, "%s"]).value'], - 'ezkeyword' => ['[String]', '@=resolver("DomainFieldValue", [value, "%s"]).values'], - 'ezmedia' => 'MediaFieldValue', - 'ezobjectrelation' => 'RelationFieldValue', - 'ezobjectrelationlist' => 'RelationListFieldValue', - 'ezrichtext' => 'RichTextFieldValue', - 'ezstring' => 'String', - 'eztext' => 'String', - ]; - - public function buildDefinition(FieldDefinition $fieldDefinition) - { - $mapping = $this->mapFieldTypeIdentifierToGraphQLType($fieldDefinition->fieldTypeIdentifier); - - if (is_array($mapping)) { - list($type, $resolver) = $mapping; - } else { - $type = $mapping; - $resolver = self::DEFAULT_RESOLVER; - } - - return [ - 'type' => $type, - 'resolve' => sprintf($resolver, $fieldDefinition->identifier), - ]; - } - - private function mapFieldTypeIdentifierToGraphQLType($fieldTypeIdentifier) - { - return isset($this->typesMap[$fieldTypeIdentifier]) ? $this->typesMap[$fieldTypeIdentifier] : 'GenericFieldValue'; - } -} \ No newline at end of file diff --git a/src/DomainContent/FieldValueBuilder/FieldValueBuilder.php b/src/DomainContent/FieldValueBuilder/FieldValueBuilder.php deleted file mode 100644 index 392b99fb..00000000 --- a/src/DomainContent/FieldValueBuilder/FieldValueBuilder.php +++ /dev/null @@ -1,13 +0,0 @@ -nameHelper = $nameHelper; - $this->contentTypeService = $contentTypeService; - } - - public function buildDefinition(FieldDefinition $fieldDefinition) - { - $settings = $fieldDefinition->getFieldSettings(); - $constraints = $fieldDefinition->getValidatorConfiguration(); - - if (count($settings['selectionContentTypes']) === 1) { - $contentType = $this->contentTypeService->loadContentTypeByIdentifier($settings['selectionContentTypes'][0]); - $type = $this->nameHelper->domainContentName($contentType); - } else { - $type = 'DomainContent'; - } - - $isMultiple = 'false'; - if ($constraints['RelationListValueValidator']['selectionLimit'] !== 1) { - $isMultiple = 'true'; - $type = "[$type]"; - } - - $resolver = sprintf( - '@=resolver("DomainRelationFieldValue", [value, "%s", %s])', - $fieldDefinition->identifier, - $isMultiple - ); - - return ['type' => $type, 'resolve' => $resolver]; - } - - private function mapFieldTypeIdentifierToGraphQLType($fieldTypeIdentifier) - { - return isset($this->typesMap[$fieldTypeIdentifier]) ? $this->typesMap[$fieldTypeIdentifier] : 'GenericFieldValue'; - } -} \ No newline at end of file diff --git a/src/DomainContent/FieldValueBuilder/SelectionFieldValueBuilder.php b/src/DomainContent/FieldValueBuilder/SelectionFieldValueBuilder.php deleted file mode 100644 index bacb7172..00000000 --- a/src/DomainContent/FieldValueBuilder/SelectionFieldValueBuilder.php +++ /dev/null @@ -1,22 +0,0 @@ -getFieldSettings(); - - return [ - 'type' => $settings['isMultiple'] ? '[String]' : 'String', - 'resolve' => sprintf( - '@=resolver("SelectionFieldValue", [value, "%s"])', - $fieldDefinition->identifier - ) - ]; - } -} \ No newline at end of file diff --git a/src/DomainContent/NameHelper.php b/src/DomainContent/NameHelper.php deleted file mode 100644 index 6072afe1..00000000 --- a/src/DomainContent/NameHelper.php +++ /dev/null @@ -1,116 +0,0 @@ -caseConverter = new CamelCaseToSnakeCaseNameConverter(null, false); - } - - public function domainContentCollectionField(ContentType $contentType) - { - return $this->pluralize(lcfirst($this->toCamelCase($contentType->identifier))); - } - public function domainContentName(ContentType $contentType) - { - return ucfirst($this->toCamelCase($contentType->identifier)) . 'Content'; - } - - public function domainContentTypeName(ContentType $contentType) - { - return ucfirst($this->toCamelCase($contentType->identifier)) . 'ContentType'; - } - - public function domainContentField(ContentType $contentType) - { - return lcfirst($this->toCamelCase($contentType->identifier)); - } - - public function domainGroupName(ContentTypeGroup $contentTypeGroup) - { - return 'DomainGroup' . ucfirst($this->toCamelCase($this->sanitizeContentTypeGroupIdentifier($contentTypeGroup))); - } - - public function domainGroupField(ContentTypeGroup $contentTypeGroup) - { - return lcfirst($this->toCamelCase($this->sanitizeContentTypeGroupIdentifier($contentTypeGroup))); - } - - public function fieldDefinitionField(FieldDefinition $fieldDefinition) - { - return lcfirst($this->toCamelCase($fieldDefinition->identifier)); - } - - private function toCamelCase($string) - { - return $this->caseConverter->denormalize($string); - } - - private function pluralize($name) - { - if (substr($name, -1) === 'f') { - return substr($name, 0, -1) . "ves"; - } - - if (substr($name, -1) === 'fe') { - return substr($name, 0, -2) . "ves"; - } - - if (substr($name, -1) === 'y') { - - if (in_array(substr($name, -2, 1), ['a', 'e', 'i', 'o', 'u'])) { - return $name . 's'; - } else { - return substr($name, 0, -1) . "ies"; - } - } - - if (substr($name, -2) === 'is') { - return substr($name, 0, -2) . "es"; - } - - if (substr($name, -2) === 'us') { - return substr($name, 0, -2) . "i"; - } - - if (in_array(substr($name, -2), ['on', 'um'])) { - return substr($name, 0, -2) . "a"; - } - - if (substr($name, -2) === 'is') { - return substr($name, 0, -2) . "es"; - } - - if ( - preg_match('/(s|sh|ch|x|z)$/', $name) || - substr($name, -1) === 'o' - ) { - return $name . 'es'; - } - - return $name . 's'; - } - - /** - * Removes potential spaces in content types groups names. - * (content types groups identifiers are actually their name) - * - * @param ContentTypeGroup $contentTypeGroup - * @return string - */ - protected function sanitizeContentTypeGroupIdentifier(ContentTypeGroup $contentTypeGroup): string - { - return str_replace(' ', '_', $contentTypeGroup->identifier); - } -} \ No newline at end of file diff --git a/src/DomainContent/SchemaWorker/BaseWorker.php b/src/DomainContent/SchemaWorker/BaseWorker.php deleted file mode 100644 index 1b92f6b2..00000000 --- a/src/DomainContent/SchemaWorker/BaseWorker.php +++ /dev/null @@ -1,22 +0,0 @@ -nameHelper = $nameHelper; - } - - protected function getNameHelper() - { - return $this->nameHelper; - } -} \ No newline at end of file diff --git a/src/DomainContent/SchemaWorker/ContentType/AddContentTypeToContentTypeIdentifierList.php b/src/DomainContent/SchemaWorker/ContentType/AddContentTypeToContentTypeIdentifierList.php deleted file mode 100644 index 58f8b4fb..00000000 --- a/src/DomainContent/SchemaWorker/ContentType/AddContentTypeToContentTypeIdentifierList.php +++ /dev/null @@ -1,44 +0,0 @@ -getDescriptions(); - - if (!isset($schema['ContentTypeIdentifier'])) { - $this->initType($schema); - } - - $schema - ['ContentTypeIdentifier'] - ['config']['values'] - [$contentType->identifier] = [ - 'description' => isset($descriptions['eng-GB']) ? $descriptions['eng-GB'] : 'No description available', - ]; - } - - private function initType(&$schema) - { - $schema['ContentTypeIdentifier'] = ['type' => 'enum']; - } - - public function canWork(array $schema, array $args) - { - $canWork = - isset($args['ContentType']) - && $args['ContentType'] instanceof ContentType - && !isset($schema['ContentTypeIdentifier']['config']['values'][$args['ContentType']->identifier]); - - return $canWork; - } -} \ No newline at end of file diff --git a/src/DomainContent/SchemaWorker/ContentType/AddDomainContentToDomainGroup.php b/src/DomainContent/SchemaWorker/ContentType/AddDomainContentToDomainGroup.php deleted file mode 100644 index 8368aeb2..00000000 --- a/src/DomainContent/SchemaWorker/ContentType/AddDomainContentToDomainGroup.php +++ /dev/null @@ -1,140 +0,0 @@ -getDescriptions(); - - $schema - [$this->getGroupName($contentTypeGroup)] - ['config']['fields'] - [$this->getContentCollectionField($contentType)] = [ - 'type' => sprintf("[%s]", $this->getContentName($contentType)), - // @todo Improve description to mention that it is a collection ? - 'description' => isset($descriptions['eng-GB']) ? $descriptions['eng-GB'] : 'No description available', - 'resolve' => sprintf( - '@=resolver("DomainContentItemsByTypeIdentifier", ["%s", args])', - $contentType->identifier - ), - 'args' => [ - 'query' => [ - 'type' => "ContentSearchQuery", - 'description' => "A Content query used to filter results" - ], - 'sortBy' => [ - 'type' => '[SortByOptions]', - 'description' => "A sort clause, or array of clauses. Add _desc after a clause to reverse it" - ], - ], - ]; - - $schema - [$this->getGroupName($contentTypeGroup)] - ['config']['fields'] - [$this->getContentField($contentType)] = [ - 'type' => $this->getContentName($contentType), - 'description' => isset($descriptions['eng-GB']) ? $descriptions['eng-GB'] : 'No description available', - 'resolve' => sprintf('@=resolver("DomainContentItem", [args, "%s"])', $contentType->identifier), - 'args' => [ - // @todo How do we constraint this so that it only takes an id of an item of that type ? - // same approach than GlobalId ? (-) - 'id' => [ - 'type' => 'Int', - 'description' => sprintf('A %s content id', $contentType->identifier), - ], - 'locationId' => [ - 'type' => 'Int', - 'description' => sprintf('A %s content location id', $contentType->identifier), - ], - 'remoteId' => [ - 'type' => 'String', - 'description' => sprintf('A %s content remote id', $contentType->identifier), - ] - ] - ]; - - $schema[$this->getGroupTypesName($contentTypeGroup)] - ['config']['fields'] - [$this->getNameHelper()->domainContentField($contentType)] = [ - 'type' => $this->getNameHelper()->domainContentTypeName($contentType), - 'resolve' => sprintf( - '@=resolver("ContentType", [{"identifier": "%s"}])', - $contentType->identifier - ), - ]; - } - - public function canWork(array $schema, array $args) - { - return - isset($args['ContentType']) - && $args['ContentType'] instanceof ContentType - && isset($args['ContentTypeGroup']) - && $args['ContentTypeGroup'] instanceof ContentTypeGroup - && !$this->isFieldDefined($args['ContentTypeGroup'], $args['ContentType']); - } - - /** - * @param $contentTypeGroup - * @return string - */ - protected function getGroupName($contentTypeGroup): string - { - return $this->getNameHelper()->domainGroupName($contentTypeGroup); - } - - /** - * @param $contentTypeGroup - * @return string - */ - protected function getGroupTypesName($contentTypeGroup): string - { - return $this->getNameHelper()->domainGroupName($contentTypeGroup) . 'Types'; - } - - /** - * @param $contentType - * @return string - */ - protected function getContentCollectionField($contentType): string - { - return $this->getNameHelper()->domainContentCollectionField($contentType); - } - - /** - * @param $contentType - * @return string - */ - protected function getContentField($contentType): string - { - return $this->getNameHelper()->domainContentField($contentType); - } - - /** - * @param $contentType - * @return string - */ - protected function getContentName($contentType): string - { - return $this->getNameHelper()->domainContentName($contentType); - } - - private function isFieldDefined(ContentTypeGroup $contentTypeGroup, ContentType $contentType) - { - return isset( - $schema - [$this->getGroupName($contentTypeGroup)] - ['config']['fields'] - [$this->getContentCollectionField($contentType)] - ); - } -} \ No newline at end of file diff --git a/src/DomainContent/SchemaWorker/ContentType/DefineDomainContent.php b/src/DomainContent/SchemaWorker/ContentType/DefineDomainContent.php deleted file mode 100644 index f157a711..00000000 --- a/src/DomainContent/SchemaWorker/ContentType/DefineDomainContent.php +++ /dev/null @@ -1,48 +0,0 @@ -getDomainContentName($contentType)] = [ - 'type' => 'object', - 'inherits' => ['AbstractDomainContent'], - 'config' => [ - 'fields' => [], - 'interfaces' => ['DomainContent'], - ] - ]; - - $schema[$this->getNameHelper()->domainContentTypeName($contentType)] = [ - 'type' => 'object', - 'inherits' => ['BaseDomainContentType'], - 'config' => [ - 'interfaces' => ['DomainContentType'], - 'fields' => [] - ], - ]; - } - - public function canWork(array $schema, array $args) - { - return - isset($args['ContentType']) && $args['ContentType'] instanceof ContentType - && !isset($schema[$this->getDomainContentName($args['ContentType'])]); - } - - /** - * @param $contentType - * @return string - */ - protected function getDomainContentName(ContentType $contentType): string - { - return $this->getNameHelper()->domainContentName($contentType); - } -} \ No newline at end of file diff --git a/src/DomainContent/SchemaWorker/ContentTypeGroup/AddDomainGroupToDomain.php b/src/DomainContent/SchemaWorker/ContentTypeGroup/AddDomainGroupToDomain.php deleted file mode 100644 index 29c61a52..00000000 --- a/src/DomainContent/SchemaWorker/ContentTypeGroup/AddDomainGroupToDomain.php +++ /dev/null @@ -1,47 +0,0 @@ -getGroupField($args['ContentTypeGroup'])] = [ - 'type' => $this->getGroupName($args['ContentTypeGroup']), - 'description' => $contentTypeGroup->getDescription('eng-GB'), - 'resolve' => sprintf( - "@=resolver(\"ContentTypeGroupByIdentifier\", [\"%s\"])", - $args['ContentTypeGroup']->identifier - ), - ]; - } - - public function canWork(array $schema, array $args) - { - return isset($args['ContentTypeGroup']) && $args['ContentTypeGroup'] instanceof ContentTypeGroup - && !isset($schema['Domain']['config']['fields'][$this->getGroupName($args['ContentTypeGroup'])]); - } - - /** - * @param ContentTypeGroup $contentTypeGroup - * @return string - */ - private function getGroupField(ContentTypeGroup $contentTypeGroup): string - { - return $this->getNameHelper()->domainGroupField($contentTypeGroup); - } - - /** - * @param ContentTypeGroup $contentTypeGroup - * @return string - */ - private function getGroupName(ContentTypeGroup $contentTypeGroup): string - { - return $this->getNameHelper()->domainGroupName($contentTypeGroup); - } -} \ No newline at end of file diff --git a/src/DomainContent/SchemaWorker/ContentTypeGroup/DefineDomainGroup.php b/src/DomainContent/SchemaWorker/ContentTypeGroup/DefineDomainGroup.php deleted file mode 100644 index 9464cb64..00000000 --- a/src/DomainContent/SchemaWorker/ContentTypeGroup/DefineDomainGroup.php +++ /dev/null @@ -1,53 +0,0 @@ -getGroupName($args['ContentTypeGroup'])] = [ - 'type' => 'object', - 'inherits' => ['DomainContentTypeGroup'], - 'config' => [ - 'fields' => [ - '_types' => [ - 'type' => $this->getGroupTypesName($args['ContentTypeGroup']), - 'resolve' => [] - ] - ], - ] - ]; - - // Type that indexes the types from a group by identifier - $schema[$this->getGroupTypesName($args['ContentTypeGroup'])] = [ - 'type' => 'object', - 'config' => ['fields' => []] - ]; - } - - public function canWork(array $schema, array $args) - { - return - isset($args['ContentTypeGroup']) && $args['ContentTypeGroup'] instanceof ContentTypeGroup - && !isset($schema[$this->getGroupName($args['ContentTypeGroup'])]); - } - - /** - * @param ContentTypeGroup $contentTypeGroup - * @return string - */ - protected function getGroupName(ContentTypeGroup $contentTypeGroup): string - { - return $this->getNameHelper()->domainGroupName($contentTypeGroup); - } - - private function getGroupTypesName($contentTypeGroup): string - { - return $this->getNameHelper()->domainGroupName($contentTypeGroup) . 'Types'; - } -} \ No newline at end of file diff --git a/src/DomainContent/SchemaWorker/FieldDefinition/AddFieldDefinitionToDomainContent.php b/src/DomainContent/SchemaWorker/FieldDefinition/AddFieldDefinitionToDomainContent.php deleted file mode 100644 index 712f6724..00000000 --- a/src/DomainContent/SchemaWorker/FieldDefinition/AddFieldDefinitionToDomainContent.php +++ /dev/null @@ -1,118 +0,0 @@ -fieldValueBuilders = $fieldValueBuilders; - $this->defaultFieldValueBuilder = $defaultFieldValueBuilder; - } - - public function work(array &$schema, array $args) - { - $fieldDefinition = $args['FieldDefinition']; - $fieldDefinitionField = $this->getFieldDefinitionField($args['FieldDefinition']); - $domainContentName = $this->getDomainContentName($args['ContentType']); - - $schema[$domainContentName]['config']['fields'][$fieldDefinitionField] = $this->getDefinition($fieldDefinition); - - $descriptions = $fieldDefinition->getDescriptions(); - if (isset($descriptions['eng-GB'])) { - $fields[$fieldDefinitionField]['description'] = $descriptions['eng-GB']; - } - - $schema - [$this->getNameHelper()->domainContentTypeName($args['ContentType'])] - ['config']['fields'] - [$fieldDefinitionField] = [ - 'type' => $this->getFieldDefinitionType($args['FieldDefinition']), - 'resolve' => sprintf( - '@=value.getFieldDefinition("%s")', - $args['FieldDefinition']->identifier - ), - ]; - } - - private function getDefinition(FieldDefinition $fieldDefinition) - { - return isset($this->fieldValueBuilders[$fieldDefinition->fieldTypeIdentifier]) - ? $this->fieldValueBuilders[$fieldDefinition->fieldTypeIdentifier]->buildDefinition($fieldDefinition) - : $this->defaultFieldValueBuilder->buildDefinition($fieldDefinition); - } - - public function canWork(array $schema, array $args) - { - return - isset($args['FieldDefinition']) - && $args['FieldDefinition'] instanceof FieldDefinition - & isset($args['ContentType']) - && $args['ContentType'] instanceof ContentType - && !$this->isFieldDefined($schema, $args); - } - - /** - * @param ContentType $contentType - * @return string - */ - protected function getDomainContentName(ContentType $contentType): string - { - return $this->getNameHelper()->domainContentName($contentType); - } - - /** - * @param FieldDefinition $fieldDefinition - * @return string - */ - protected function getFieldDefinitionField(FieldDefinition $fieldDefinition): string - { - return $this->getNameHelper()->fieldDefinitionField($fieldDefinition); - } - - private function isFieldDefined($schema, $args) - { - return isset( - $schema[$this->getDomainContentName($args['ContentType'])] - ['config']['fields'] - [$this->getFieldDefinitionField($args['FieldDefinition'])]); - } - - private function getFieldDefinitionType(FieldDefinition $fieldDefinition) - { - $map = [ - 'ezbinaryfile' => 'BinaryFieldDefinition', - 'ezboolean' => 'CheckboxFieldDefinition', - 'ezcountry' => 'CountryFieldDefinition', - 'ezmediafile' => 'CheckboxFieldDefinition', - 'ezfloat' => 'FloatFieldDefinition', - 'ezimage' => 'BinaryFieldDefinition', - 'ezinteger' => 'IntegerFieldDefinition', - 'ezmedia' => 'MediaFieldDefinition', - 'ezobjectrelation' => 'RelationFieldDefinition', - 'ezobjectrelationlist' => 'RelationListFieldDefinition', - 'ezstring' => 'TextLineFieldDefinition', - 'ezselection' => 'SelectionFieldDefinition', - 'eztext' => 'TextBlockFieldDefinition', - ]; - - return isset($map[$fieldDefinition->fieldTypeIdentifier]) - ? $map[$fieldDefinition->fieldTypeIdentifier] - : 'FieldDefinition'; - } -} \ No newline at end of file diff --git a/src/DomainContent/SchemaWorker/SchemaWorker.php b/src/DomainContent/SchemaWorker/SchemaWorker.php deleted file mode 100644 index 26f66240..00000000 --- a/src/DomainContent/SchemaWorker/SchemaWorker.php +++ /dev/null @@ -1,26 +0,0 @@ -