Ejemplo n.º 1
0
 /**
  * Generate routing logic function.
  *
  * @param string $functionName Function name
  * @return string Routing logic function PHP code
  */
 public function generate($functionName = Core::ROUTING_LOGIC_FUNCTION)
 {
     $this->generator->defFunction($functionName, array('$path', '$method'))->defVar('$matches', array())->newLine('$path = strtok(rtrim($method.\'/\'.ltrim($path, \'/\'),\'/\'),\'?\');')->defVar('$parameters', array());
     // Perform routing logic generation
     $this->innerGenerate2($this->logic);
     $this->generator->newLine('return null;')->endFunction();
     return $this->generator->flush();
 }
Ejemplo n.º 2
0
 /**
  * Generate routing logic function.
  *
  * @param string $functionName Function name
  * @return string Routing logic function PHP code
  */
 public function generate($functionName = Core::ROUTING_LOGIC_FUNCTION)
 {
     $this->generator->defFunction($functionName, array('$path', '$method'))->defVar('$matches', array())->defVar('$parameters', array());
     // Do not generate if we have no http methods supported
     if (count($this->httpMethods)) {
         // Build routes for first method
         $this->buildRoutesByMethod(array_shift($this->httpMethods));
         // Build routes for other methods
         foreach ($this->httpMethods as $method) {
             // Build routes for first method
             $this->buildRoutesByMethod($method, 'defElseIfCondition');
         }
         // Add method not found
         $this->generator->endIfCondition();
     }
     // Add method not found
     $this->generator->newLine('return null;')->endFunction();
     return $this->generator->flush();
 }