1 | <?php |
||
12 | class Helper |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * @param string $name |
||
17 | * @param string $type |
||
18 | * @param string $comment |
||
19 | * @param array $constraintsParts |
||
20 | * @return PropertyManager |
||
21 | */ |
||
22 | public static function prepareProperty($name, $type, $comment = "", array $constraintsParts = []) |
||
23 | { |
||
24 | $propertyManager = new PropertyManager(); |
||
25 | $propertyManager->setName($name); |
||
26 | $propertyManager->setType($type); |
||
27 | $propertyManager->setComment($comment); |
||
28 | |||
29 | $constraintCollection = new ArrayCollection(); |
||
30 | foreach ($constraintsParts as $constraintPart) { |
||
31 | $constraintCollection->add($constraintPart); |
||
32 | } |
||
33 | |||
34 | $propertyManager->setConstraints($constraintCollection); |
||
35 | |||
36 | return $propertyManager; |
||
37 | } |
||
38 | |||
39 | /** |
||
40 | * @param string $namespace |
||
41 | * @return ClassManager |
||
42 | */ |
||
43 | public static function prepareBasicClassManager($namespace = "\AppBundle\Entity\User") |
||
44 | { |
||
45 | $classManager = new ClassManager(); |
||
46 | $classManager->setNamespace($namespace); |
||
47 | $classManager->setComment("User entity for tests"); |
||
48 | |||
49 | $propertiesCollection = new ArrayCollection(); |
||
50 | $propertiesCollection->add(self::prepareProperty("full_name", "string", "", ["NotBlank()"])); |
||
51 | $propertiesCollection->add(self::prepareProperty("email", "string", "", ["Email(message = \"Invalid email!\")"])); |
||
52 | $propertiesCollection->add(self::prepareProperty("active", "boolean", "Wether user active", ["Type(type='boolean')", "IsTrue()"])); |
||
53 | $propertiesCollection->add(self::prepareProperty("new_posts", "Doctrine\Common\Collections\ArrayCollection<AppBundle\Entity\Post>", "User new posts", ["NotNull()", "Valid()"])); |
||
54 | |||
55 | $classManager->setProperties($propertiesCollection); |
||
56 | |||
57 | return $classManager; |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @return string |
||
62 | */ |
||
63 | public static function getStructureYaml() |
||
64 | { |
||
65 | return ' |
||
66 | - |
||
67 | namespace: \AppBundle\Entity\User |
||
68 | extends: \AppBundle\Entity\Base |
||
69 | comment: "New User entity" |
||
70 | multiline_comment: |
||
71 | - \'lorem ipsum\' |
||
72 | - \'second row\' |
||
73 | - \'@\Doctrine\Common\Annotations\Entity()\' |
||
74 | properties: |
||
75 | - |
||
76 | name: username |
||
77 | type: string |
||
78 | comment: "Username for login" |
||
79 | constraints: |
||
80 | - NotBlank(message = "Login can not be empty") |
||
81 | - NotNull(message = "Login can not be null") |
||
82 | - |
||
83 | name: email |
||
84 | type: string |
||
85 | comment: "User email" |
||
86 | multiline_comment: |
||
87 | - \'@\Doctrine\Common\Annotations\Column()\' |
||
88 | - \'lorem ipsum\' |
||
89 | - \'third row\' |
||
90 | constraints: |
||
91 | - NotBlank() |
||
92 | - Email(message = "Invalid email") |
||
93 | - |
||
94 | name: active |
||
95 | type: boolean |
||
96 | comment: "Wether user is active or not" |
||
97 | constraints: |
||
98 | - IsTrue() |
||
99 | - |
||
100 | name: posts |
||
101 | type: Doctrine\Common\Collections\ArrayCollection<AppBundle\Entity\Post> |
||
102 | comment: User posts |
||
103 | - |
||
104 | # default comment |
||
105 | name: created_at |
||
106 | type: DateTime |
||
107 | - |
||
108 | # default comment |
||
109 | name: updated_at |
||
110 | type: DateTime |
||
111 | - |
||
112 | # default comment |
||
113 | name: last_post |
||
114 | serialized_name: lastPost |
||
115 | type: AppBundle\Entity\Post |
||
116 | optional: true |
||
117 | - |
||
118 | namespace: \AppBundle\Entity\Post |
||
119 | # no comment |
||
120 | properties: |
||
121 | - |
||
122 | name: content |
||
123 | type: string |
||
124 | comment: "Post content" |
||
125 | constraints: |
||
126 | - NotBlank() |
||
127 | - |
||
128 | # default comment |
||
129 | name: created_at |
||
130 | type: DateTime |
||
131 | - |
||
132 | # default comment |
||
133 | name: updated_at |
||
134 | type: DateTime'; |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @return string |
||
139 | */ |
||
140 | public static function getStructureYamlForTemplateChangeTest() |
||
189 | |||
190 | public static function getStructureYamlForTestInlineClassConfuration() |
||
203 | } |
||
204 |