/** * Returns further information on how to solve the the exception * @access public * @param string $contentType The context type(html|text) * @return string Information about the exception */ public function getInstructions($contentType) { // should the below (determining the method) be the responsibility of the parser? $parserData = Atsumi::app__getParserMetaData(); $parserData = end($parserData['stack']); $this->controller = $parserData['controller']; $this->method = $parserData['method']; if ($this->method == 'methodlessRequest') { $methodArr = explode('/', $parserData['args'][0]); // TODO: This should talk back to the URI parser asking it to parse a page method. $this->method = 'page_' . $methodArr[1]; $this->args = array_slice($parserData['args'], 1); } // create string of args $argString = ''; for ($i = 0; $i < count($this->args); $i++) { $argString .= ($argString == '' ? '' : ', ') . '$arg' . strval($i + 1); } switch ($contentType) { default: case 'text/plain': return sf('--Description\\nYour choosen paser has determined that the \'%s\' method of the \'%s\' controller should be called but the method or controller cannot be found. Please make sure it exists. --Example Code to create the controller and method\\n class %s extends mvc_AbstractController { // The method to be called public function page_%s { // Don\'t forget to set your view $this->setView(\'name_of_view\'); } } --Example code to load a folder containing your controller\\n /* exmaple folders: models, views, controllers. These folders should exist in the \'classes/\' folder */ Atsumi::references(array(\'myproject\' => \'models views controllers\')); ', $this->method, $this->controller, $this->controller, $this->method); break; case 'text/html': return sf('<h4>Description</h4><p>Your choosen paser has determined that the \'<strong>%s</strong>\' method of the \'<strong>%s</strong>\' controller should be called but the method or controller cannot be found. Please make sure it exists.</p> <h4>Example Code to create the controller and method</h4> <pre class="code"> class %s extends mvc_AbstractController { // The method to be called public function %s (%s) { // Don\'t forget to set your view $this->setView(\'name_of_view\'); } } </pre> <h4>Example code to load a folder containing your controller</h4> <pre class="code"> /* exmaple folders: models, views, controllers. These folders should exist in the \'classes/\' folder */ Atsumi::references(array(\'myproject\' => \'models views controllers\')); </pre> ', $this->method, $this->controller, $this->controller, $this->method, $argString); break; } }
public function getData($method = null, $controller = null) { $parserData = Atsumi::app__getParserMetaData(); $stack = $parserData['spec']; for ($i = count($stack) - 1; $i >= 0; $i--) { $entity = $stack[$i]; /* if they haven't specified a controllero or it's specified and matches then break */ if (is_null($controller) || $entity['controller'] == $controller) { break; } } // TODO: Give this it's own exceptions! if (!is_null($controller) && $entity['controller'] != $controller) { throw new Exception("Controller not found..."); } $controller = is_null($controller) ? $this : new $controller($this->app, $this->errorHandler); // TODO: This only works for page_ not other methods.... // is method is an index? if (is_integer($method)) { $method = $method = substr($entity['method'][count($entity['method']) - 1 - $method]['name'], 5); } else { if (is_null($method)) { $method = substr($entity['method'][count($entity['method']) - 1]['name'], 5); } } $methodName = sf('data_%s', $method); $pageMethod = null; // loop through methods to find the correct one... foreach ($entity['method'] as $methodData) { if ($methodData['name'] == sf('page_%s', $method)) { $pageMethod = $methodData; break; } } // TODO: Give this it's own exceptions! if (is_null($methodData)) { throw new Exception("Method not found..."); } return call_user_func_array(array($controller, $methodName), $methodData['args']); }