/** * Determines if the form has been successfully submitted * if this returns true, you can process the form and redirect. * if it returns false, then you need to draw the form. * @param \snb\http\Request $request * @return bool */ public function onPostValid(Request $request) { // If this is a post request if ($request->getMethod() == 'POST') { // bind the post data to the form $this->bindRequest($request); // check that the form data is valid if ($this->isValid()) { return true; } } // not ready to be processed yet return false; }
/** * isMatch * Trys to match the url of the request to this route * @param string $path - the is the urldecoded path in the url * @param \snb\http\Request $request * @return bool */ public function isMatch($path, Request $request) { // See if it is a match for this route $regex = $this->getRegex(); if (!preg_match($regex, $path, $regs)) { return false; } // OK, this URL is a good one // Check that the request method matches the route $method = $this->getMethod(); $m = explode('|', mb_strtoupper($method)); if (!in_array($request->getMethod(), $m)) { return false; } // Something similar for the protocol $protocol = $this->getProtocol(); $p = explode('|', mb_strtolower($protocol)); if (!in_array($request->getProtocol(), $p)) { return false; } // It is, so prepare the variables and create the controller $p = array(); foreach ($this->vars as $key => $name) { // copy over the default value if there is one if (array_key_exists($name, $this->defaults)) { $p[$name] = $this->defaults[$name]; } // replace it with the value from url, if it was included if (array_key_exists($key + 1, $regs)) { $p[$name] = $regs[$key + 1]; } } // remember these, as someone it likely to want them very soon $this->matchedArgs = $p; $this->matchedUri = $request->getUri(); // This route was a match return true; }