示例#1
0
 public function testListExtraction()
 {
     $result = Util::extractLists('(1:online,2:offline)');
     $this->assertCount(1, $result);
     $this->assertCount(2, $result[0]);
     $result = Util::extractLists('param1 "param 2" param3 (a,b,c)');
     $this->assertCount(1, $result);
     $this->assertArrayHasKey('a', $result[0]);
     $this->assertEquals('a', $result[0]['a']);
     $result = Util::extractLists('(a:dog,horse,c:cow) (green, blue, red ,purple)');
     $this->assertCount(2, $result);
     $this->assertArrayHasKey('a', $result[0]);
     $this->assertArrayHasKey('horse', $result[0]);
     $this->assertArrayHasKey('c', $result[0]);
     $this->assertContains('green', $result[1]);
     $this->assertContains('blue', $result[1]);
     $this->assertContains('red', $result[1]);
     $this->assertContains('purple', $result[1]);
     $result = Util::extractLists('(a:"Lassy",\'Black Beauty \',c: Milka Cow )');
     $this->assertCount(1, $result);
     $this->assertContains('Lassy', $result[0]);
     $this->assertContains('Black Beauty ', $result[0]);
     $this->assertContains('Milka Cow', $result[0]);
 }
示例#2
0
 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;
 }