public function testParamExtraction() { $result = Util::extractParams('param1 "param 2" param3 (a,b,c)'); $this->assertCount(3, $result); $this->assertEquals('param1', $result[0]); $this->assertEquals('param 2', $result[1]); $this->assertEquals('param3', $result[2]); // params cannot contain quotation marks, so a string like the following will break the extraction deterministic $result = Util::extractParams('"That is a not working "quote""'); $this->assertCount(3, $result); }
public static function parseAnnotation(DataTypeDefinition $dataTypeDefinition, FormElementDefinitionCollection $currentFormElementDefinitionCollection, $line) { $p = strpos($line, ' '); if ($p) { $annotationName = trim(substr($line, 1, $p)); $onTheRight = substr($line, $p + 1); $lists = Util::extractLists($onTheRight); $params = Util::extractParams($onTheRight); $numericalLists = Util::extractLists($onTheRight, true); } else { $annotationName = substr($line, 1); $lists = array(); $params = array(); $numericalLists = array(); } switch ($annotationName) { case 'title': $annotation = new DataTypeTitleAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'description': $annotation = new DataTypeDescriptionAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'name': $annotation = new ContentTypeNameAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'languages': $annotation = new DataTypeLanguagesAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'status': $annotation = new ContentTypeStatusAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'subtypes': $annotation = new ContentTypeSubtypesAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'workspaces': $annotation = new DataTypeWorkspacesAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'sortable': $annotation = new DataTypeSortableAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'time-shiftable': $annotation = new DataTypeTimeShiftableAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'default-value': $annotation = new FormElementDefaultValueAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'help': $annotation = new FormElementHelpAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'hint': $annotation = new FormElementHintAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'info': $annotation = new FormElementInfoAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'placeholder': $annotation = new FormElementPlaceholderAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'hidden-properties': $annotation = new FormElementCollectionHiddenPropertiesAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'insert': $annotation = new InsertAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists); break; case 'custom': $annotation = new CustomAnnotation($dataTypeDefinition, $currentFormElementDefinitionCollection, $params, $lists, $numericalLists); break; default: throw new CMDLParserException('Unknown annotation ' . $annotationName . '.', CMDLParserException::CMDL_UNKNOWN_ANNOTATION); break; } $dataTypeDefinition = $annotation->apply(); return $dataTypeDefinition; }