1 | <?php |
||
8 | class DefaultNamingStrategy implements NamingStrategyInterface |
||
9 | { |
||
10 | private $beanPrefix = ''; |
||
11 | private $beanSuffix = ''; |
||
12 | private $baseBeanPrefix = 'Abstract'; |
||
13 | private $baseBeanSuffix = ''; |
||
14 | private $daoPrefix = ''; |
||
15 | private $daoSuffix = 'Dao'; |
||
16 | private $baseDaoPrefix = 'Abstract'; |
||
17 | private $baseDaoSuffix = 'Dao'; |
||
18 | private $exceptions = []; |
||
19 | |||
20 | /** |
||
21 | * Sets the string prefix to any bean class name. |
||
22 | * |
||
23 | * @param string $beanPrefix |
||
24 | */ |
||
25 | public function setBeanPrefix(string $beanPrefix) |
||
29 | |||
30 | /** |
||
31 | * Sets the string suffix to any bean class name. |
||
32 | * |
||
33 | * @param string $beanSuffix |
||
34 | */ |
||
35 | public function setBeanSuffix(string $beanSuffix) |
||
39 | |||
40 | /** |
||
41 | * Sets the string prefix to any base bean class name. |
||
42 | * |
||
43 | * @param string $baseBeanPrefix |
||
44 | */ |
||
45 | public function setBaseBeanPrefix(string $baseBeanPrefix) |
||
49 | |||
50 | /** |
||
51 | * Sets the string suffix to any base bean class name. |
||
52 | * |
||
53 | * @param string $baseBeanSuffix |
||
54 | */ |
||
55 | public function setBaseBeanSuffix(string $baseBeanSuffix) |
||
59 | |||
60 | /** |
||
61 | * Sets the string prefix to any DAO class name. |
||
62 | * |
||
63 | * @param string $daoPrefix |
||
64 | */ |
||
65 | public function setDaoPrefix(string $daoPrefix) |
||
69 | |||
70 | /** |
||
71 | * Sets the string suffix to any DAO class name. |
||
72 | * |
||
73 | * @param string $daoSuffix |
||
74 | */ |
||
75 | public function setDaoSuffix(string $daoSuffix) |
||
79 | |||
80 | /** |
||
81 | * Sets the string prefix to any base DAO class name. |
||
82 | * |
||
83 | * @param string $baseDaoPrefix |
||
84 | */ |
||
85 | public function setBaseDaoPrefix(string $baseDaoPrefix) |
||
89 | |||
90 | /** |
||
91 | * Sets the string suffix to any base DAO class name. |
||
92 | * |
||
93 | * @param string $baseDaoSuffix |
||
94 | */ |
||
95 | public function setBaseDaoSuffix(string $baseDaoSuffix) |
||
99 | |||
100 | |||
101 | /** |
||
102 | * Returns the bean class name from the table name (excluding the namespace). |
||
103 | * |
||
104 | * @param string $tableName |
||
105 | * @return string |
||
106 | */ |
||
107 | public function getBeanClassName(string $tableName): string |
||
111 | |||
112 | /** |
||
113 | * Returns the base bean class name from the table name (excluding the namespace). |
||
114 | * |
||
115 | * @param string $tableName |
||
116 | * @return string |
||
117 | */ |
||
118 | public function getBaseBeanClassName(string $tableName): string |
||
122 | |||
123 | /** |
||
124 | * Returns the name of the DAO class from the table name (excluding the namespace). |
||
125 | * |
||
126 | * @param string $tableName |
||
127 | * @return string |
||
128 | */ |
||
129 | public function getDaoClassName(string $tableName): string |
||
133 | |||
134 | /** |
||
135 | * Returns the name of the base DAO class from the table name (excluding the namespace). |
||
136 | * |
||
137 | * @param string $tableName |
||
138 | * @return string |
||
139 | */ |
||
140 | public function getBaseDaoClassName(string $tableName): string |
||
144 | |||
145 | /** |
||
146 | * Tries to put string to the singular form (if it is plural) and camel case form. |
||
147 | * We assume the table names are in english. |
||
148 | * |
||
149 | * @param $str string |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | private function toSingularCamelCase(string $str): string |
||
170 | |||
171 | /** |
||
172 | * Returns the class name for the DAO factory. |
||
173 | * |
||
174 | * @return string |
||
175 | */ |
||
176 | public function getDaoFactoryClassName(): string |
||
180 | |||
181 | /** |
||
182 | * Sets exceptions in the naming of classes. |
||
183 | * The key is the name of the table, the value the "base" name of beans and DAOs. |
||
184 | * |
||
185 | * This is very useful for dealing with plural to singular translations in non english table names. |
||
186 | * |
||
187 | * For instance if you are dealing with a table containing horses in French ("chevaux" that has a singular "cheval"): |
||
188 | * |
||
189 | * [ |
||
190 | * "chevaux" => "Cheval" |
||
191 | * ] |
||
192 | * |
||
193 | * @param array<string,string> $exceptions |
||
194 | */ |
||
195 | public function setExceptions(array $exceptions) |
||
199 | } |
||
200 |