13 * to license@zend.com so we can send you a copy immediately. |
13 * to license@zend.com so we can send you a copy immediately. |
14 * |
14 * |
15 * @category Zend |
15 * @category Zend |
16 * @package Zend_Tool |
16 * @package Zend_Tool |
17 * @subpackage Framework |
17 * @subpackage Framework |
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
18 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
19 * @license http://framework.zend.com/license/new-bsd New BSD License |
20 * @version $Id: ControllerFile.php 23204 2010-10-21 15:35:21Z ralph $ |
20 * @version $Id: ControllerFile.php 24593 2012-01-05 20:35:02Z matthew $ |
21 */ |
21 */ |
22 |
22 |
23 /** |
23 /** |
24 * This class is the front most class for utilizing Zend_Tool_Project |
24 * This class is the front most class for utilizing Zend_Tool_Project |
25 * |
25 * |
26 * A profile is a hierarchical set of resources that keep track of |
26 * A profile is a hierarchical set of resources that keep track of |
27 * items within a specific project. |
27 * items within a specific project. |
28 * |
28 * |
29 * @category Zend |
29 * @category Zend |
30 * @package Zend_Tool |
30 * @package Zend_Tool |
31 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
31 * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) |
32 * @license http://framework.zend.com/license/new-bsd New BSD License |
32 * @license http://framework.zend.com/license/new-bsd New BSD License |
33 */ |
33 */ |
34 class Zend_Tool_Project_Context_Zf_ControllerFile extends Zend_Tool_Project_Context_Filesystem_File |
34 class Zend_Tool_Project_Context_Zf_ControllerFile extends Zend_Tool_Project_Context_Filesystem_File |
35 { |
35 { |
36 |
36 |
98 * |
98 * |
99 * @return string |
99 * @return string |
100 */ |
100 */ |
101 public function getContents() |
101 public function getContents() |
102 { |
102 { |
103 $className = ($this->_moduleName) ? ucfirst($this->_moduleName) . '_' : ''; |
103 $filter = new Zend_Filter_Word_DashToCamelCase(); |
|
104 |
|
105 $className = ($this->_moduleName) ? $filter->filter(ucfirst($this->_moduleName)) . '_' : ''; |
104 $className .= ucfirst($this->_controllerName) . 'Controller'; |
106 $className .= ucfirst($this->_controllerName) . 'Controller'; |
105 |
107 |
106 $codeGenFile = new Zend_CodeGenerator_Php_File(array( |
108 $codeGenFile = new Zend_CodeGenerator_Php_File(array( |
107 'fileName' => $this->getPath(), |
109 'fileName' => $this->getPath(), |
108 'classes' => array( |
110 'classes' => array( |
109 new Zend_CodeGenerator_Php_Class(array( |
111 new Zend_CodeGenerator_Php_Class(array( |
110 'name' => $className, |
112 'name' => $className, |
132 new Zend_CodeGenerator_Php_Method(array( |
134 new Zend_CodeGenerator_Php_Method(array( |
133 'name' => 'errorAction', |
135 'name' => 'errorAction', |
134 'body' => <<<EOS |
136 'body' => <<<EOS |
135 \$errors = \$this->_getParam('error_handler'); |
137 \$errors = \$this->_getParam('error_handler'); |
136 |
138 |
137 if (!\$errors) { |
139 if (!\$errors || !\$errors instanceof ArrayObject) { |
138 \$this->view->message = 'You have reached the error page'; |
140 \$this->view->message = 'You have reached the error page'; |
139 return; |
141 return; |
140 } |
142 } |
141 |
143 |
142 switch (\$errors->type) { |
144 switch (\$errors->type) { |
143 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE: |
145 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE: |
144 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: |
146 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: |
145 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: |
147 case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: |
146 |
|
147 // 404 error -- controller or action not found |
148 // 404 error -- controller or action not found |
148 \$this->getResponse()->setHttpResponseCode(404); |
149 \$this->getResponse()->setHttpResponseCode(404); |
|
150 \$priority = Zend_Log::NOTICE; |
149 \$this->view->message = 'Page not found'; |
151 \$this->view->message = 'Page not found'; |
150 break; |
152 break; |
151 default: |
153 default: |
152 // application error |
154 // application error |
153 \$this->getResponse()->setHttpResponseCode(500); |
155 \$this->getResponse()->setHttpResponseCode(500); |
|
156 \$priority = Zend_Log::CRIT; |
154 \$this->view->message = 'Application error'; |
157 \$this->view->message = 'Application error'; |
155 break; |
158 break; |
156 } |
159 } |
157 |
160 |
158 // Log exception, if logger available |
161 // Log exception, if logger available |
159 if (\$log = \$this->getLog()) { |
162 if (\$log = \$this->getLog()) { |
160 \$log->crit(\$this->view->message, \$errors->exception); |
163 \$log->log(\$this->view->message, \$priority, \$errors->exception); |
|
164 \$log->log('Request Parameters', \$priority, \$errors->request->getParams()); |
161 } |
165 } |
162 |
166 |
163 // conditionally display exceptions |
167 // conditionally display exceptions |
164 if (\$this->getInvokeArg('displayExceptions') == true) { |
168 if (\$this->getInvokeArg('displayExceptions') == true) { |
165 \$this->view->exception = \$errors->exception; |
169 \$this->view->exception = \$errors->exception; |