129 public function create($name, $controllerName = 'Index', $viewIncluded = true, $module = null) |
129 public function create($name, $controllerName = 'Index', $viewIncluded = true, $module = null) |
130 { |
130 { |
131 |
131 |
132 $this->_loadProfile(); |
132 $this->_loadProfile(); |
133 |
133 |
|
134 // get request/response object |
|
135 $request = $this->_registry->getRequest(); |
|
136 $response = $this->_registry->getResponse(); |
|
137 |
|
138 // determine if testing is enabled in the project |
|
139 require_once 'Zend/Tool/Project/Provider/Test.php'; |
|
140 $testingEnabled = Zend_Tool_Project_Provider_Test::isTestingEnabled($this->_loadedProfile); |
|
141 |
|
142 if ($testingEnabled && !Zend_Tool_Project_Provider_Test::isPHPUnitAvailable()) { |
|
143 $testingEnabled = false; |
|
144 $response->appendContent( |
|
145 'Note: PHPUnit is required in order to generate controller test stubs.', |
|
146 array('color' => array('yellow')) |
|
147 ); |
|
148 } |
|
149 |
134 // Check that there is not a dash or underscore, return if doesnt match regex |
150 // Check that there is not a dash or underscore, return if doesnt match regex |
135 if (preg_match('#[_-]#', $name)) { |
151 if (preg_match('#[_-]#', $name)) { |
136 throw new Zend_Tool_Project_Provider_Exception('Action names should be camel cased.'); |
152 throw new Zend_Tool_Project_Provider_Exception('Action names should be camel cased.'); |
137 } |
153 } |
138 |
154 |
139 $originalName = $name; |
155 $originalName = $name; |
140 $originalControllerName = $controllerName; |
156 $originalControllerName = $controllerName; |
141 |
157 |
142 // ensure it is camelCase (lower first letter) |
158 // ensure it is camelCase (lower first letter) |
143 $name = strtolower(substr($name, 0, 1)) . substr($name, 1); |
159 $name = strtolower(substr($name, 0, 1)) . substr($name, 1); |
144 |
160 |
145 // ensure controller is MixedCase |
161 // ensure controller is MixedCase |
146 $controllerName = ucfirst($controllerName); |
162 $controllerName = ucfirst($controllerName); |
147 |
163 |
148 if (self::hasResource($this->_loadedProfile, $name, $controllerName, $module)) { |
164 if (self::hasResource($this->_loadedProfile, $name, $controllerName, $module)) { |
149 throw new Zend_Tool_Project_Provider_Exception('This controller (' . $controllerName . ') already has an action named (' . $name . ')'); |
165 throw new Zend_Tool_Project_Provider_Exception('This controller (' . $controllerName . ') already has an action named (' . $name . ')'); |
150 } |
166 } |
151 |
167 |
152 $actionMethod = self::createResource($this->_loadedProfile, $name, $controllerName, $module); |
168 $actionMethodResource = self::createResource($this->_loadedProfile, $name, $controllerName, $module); |
153 |
169 |
154 // get request/response object |
170 $testActionMethodResource = null; |
155 $request = $this->_registry->getRequest(); |
171 if ($testingEnabled) { |
156 $response = $this->_registry->getResponse(); |
172 $testActionMethodResource = Zend_Tool_Project_Provider_Test::createApplicationResource($this->_loadedProfile, $controllerName, $name, $module); |
157 |
173 } |
|
174 |
158 // alert the user about inline converted names |
175 // alert the user about inline converted names |
159 $tense = (($request->isPretend()) ? 'would be' : 'is'); |
176 $tense = (($request->isPretend()) ? 'would be' : 'is'); |
160 |
177 |
161 if ($name !== $originalName) { |
178 if ($name !== $originalName) { |
162 $response->appendContent( |
179 $response->appendContent( |
163 'Note: The canonical action name that ' . $tense |
180 'Note: The canonical action name that ' . $tense |
164 . ' used with other providers is "' . $name . '";' |
181 . ' used with other providers is "' . $name . '";' |
165 . ' not "' . $originalName . '" as supplied', |
182 . ' not "' . $originalName . '" as supplied', |
166 array('color' => array('yellow')) |
183 array('color' => array('yellow')) |
167 ); |
184 ); |
168 } |
185 } |
169 |
186 |
170 if ($controllerName !== $originalControllerName) { |
187 if ($controllerName !== $originalControllerName) { |
171 $response->appendContent( |
188 $response->appendContent( |
172 'Note: The canonical controller name that ' . $tense |
189 'Note: The canonical controller name that ' . $tense |
173 . ' used with other providers is "' . $controllerName . '";' |
190 . ' used with other providers is "' . $controllerName . '";' |
174 . ' not "' . $originalControllerName . '" as supplied', |
191 . ' not "' . $originalControllerName . '" as supplied', |
175 array('color' => array('yellow')) |
192 array('color' => array('yellow')) |
176 ); |
193 ); |
177 } |
194 } |
178 |
195 |
179 unset($tense); |
196 unset($tense); |
180 |
197 |
181 if ($request->isPretend()) { |
198 if ($request->isPretend()) { |
182 $response->appendContent( |
199 $response->appendContent( |
183 'Would create an action named ' . $name . |
200 'Would create an action named ' . $name . |
184 ' inside controller at ' . $actionMethod->getParentResource()->getContext()->getPath() |
201 ' inside controller at ' . $actionMethodResource->getParentResource()->getContext()->getPath() |
185 ); |
202 ); |
|
203 |
|
204 if ($testActionMethodResource) { |
|
205 $response->appendContent('Would create an action test in ' . $testActionMethodResource->getParentResource()->getContext()->getPath()); |
|
206 } |
|
207 |
186 } else { |
208 } else { |
187 $response->appendContent( |
209 $response->appendContent( |
188 'Creating an action named ' . $name . |
210 'Creating an action named ' . $name . |
189 ' inside controller at ' . $actionMethod->getParentResource()->getContext()->getPath() |
211 ' inside controller at ' . $actionMethodResource->getParentResource()->getContext()->getPath() |
190 ); |
212 ); |
191 $actionMethod->create(); |
213 $actionMethodResource->create(); |
|
214 |
|
215 if ($testActionMethodResource) { |
|
216 $response->appendContent('Creating an action test in ' . $testActionMethodResource->getParentResource()->getContext()->getPath()); |
|
217 $testActionMethodResource->create(); |
|
218 } |
|
219 |
192 $this->_storeProfile(); |
220 $this->_storeProfile(); |
193 } |
221 } |
194 |
222 |
195 if ($viewIncluded) { |
223 if ($viewIncluded) { |
196 $viewResource = Zend_Tool_Project_Provider_View::createResource($this->_loadedProfile, $name, $controllerName, $module); |
224 $viewResource = Zend_Tool_Project_Provider_View::createResource($this->_loadedProfile, $name, $controllerName, $module); |