예제 #1
0
파일: EpiApi.php 프로젝트: yllus/epiphany
 /**
  * EpiApi::getRoute($route); 
  * @name  getRoute
  * @author  Jaisen Mathai <*****@*****.**>
  * @param string $route
  * @method getRoute
  * @static method
  */
 public function getRoute($route, $httpMethod)
 {
     foreach ($this->regexes as $ind => $regex) {
         if (preg_match($regex, $route, $arguments)) {
             array_shift($arguments);
             $def = $this->routes[$ind];
             if ($httpMethod != $def['httpMethod']) {
                 continue;
             } else {
                 if (is_array($def['callback']) && method_exists($def['callback'][0], $def['callback'][1])) {
                     if (Epi::getSetting('debug')) {
                         getDebug()->addMessage(__CLASS__, sprintf('Matched %s : %s : %s : %s', $httpMethod, $this->route, json_encode($def['callback']), json_encode($arguments)));
                     }
                     return array('callback' => $def['callback'], 'args' => $arguments, 'postprocess' => true);
                 } else {
                     if (function_exists($def['callback'])) {
                         if (Epi::getSetting('debug')) {
                             getDebug()->addMessage(__CLASS__, sprintf('Matched %s : %s : %s : %s', $httpMethod, $this->route, json_encode($def['callback']), json_encode($arguments)));
                         }
                         return array('callback' => $def['callback'], 'args' => $arguments, 'postprocess' => true);
                     }
                 }
             }
             EpiException::raise(new EpiException('Could not call ' . json_encode($def) . " for route {$regex}"));
         }
     }
     EpiException::raise(new EpiException("Could not find route {$this->route} from {$_SERVER['REQUEST_URI']}"));
 }
예제 #2
0
 /**
  * addRoute('/', 'function', 'GET');
  * @name  addRoute
  * @author  Jaisen Mathai <*****@*****.**>
  * @param string $route
  * @param mixed $callback
  * @param mixed $method
  * @param string $callback
  */
 private function addRoute($route, $callback, $method, $postprocess = false)
 {
     $this->routes[] = array('httpMethod' => $method, 'path' => $route, 'callback' => $callback, 'postprocess' => $postprocess);
     $this->regexes[] = "#^{$route}\$#";
     if (Epi::getSetting('debug')) {
         getDebug()->addMessage(__CLASS__, sprintf('Found %s : %s : %s', $method, $route, json_encode($callback)));
     }
 }
예제 #3
0
파일: EpiRoute.php 프로젝트: Hulth/API
 /**
  * addRoute('/', 'function', 'GET');
  * @name  addRoute
  * @author  Jaisen Mathai <*****@*****.**>
  * @param string $route
  * @param mixed $callback
  * @param mixed $method
  * @param string $callback
  */
 private function addRoute($route, $callback, $method, $access, $postprocess = false)
 {
     /*
     	if ( $access == "secure" ) {
     		// user needs to be logged in
     		if ( isset($_SESSION['sessionId']) ) {
     
       		  $this->routes[] = array('httpMethod' => $method, 'path' => $route, 'callback' => $callback, 'postprocess' => $postprocess);
     		  $this->regexes[]= "#^{$route}\$#";
         	  if(Epi::getSetting('debug'))
          	  getDebug()->addMessage(__CLASS__, sprintf('Found %s : %s : %s', $method, $route, json_encode($callback)));
     
     		} else {
     
     			//return 401
     			http_response_code(401);
     			trigger_error('Access is denied');
     
     		}
     
     
     	} else if ( $access == "insecure" ) {
     		// user can see this without being logged in
     
       		  $this->routes[] = array('httpMethod' => $method, 'path' => $route, 'callback' => $callback, 'postprocess' => $postprocess);
     		  $this->regexes[]= "#^{$route}\$#";
         	  if(Epi::getSetting('debug'))
          	  getDebug()->addMessage(__CLASS__, sprintf('Found %s : %s : %s', $method, $route, json_encode($callback)));
     
         }*/
     $this->routes[] = array('httpMethod' => $method, 'path' => $route, 'callback' => $callback, 'postprocess' => $postprocess, 'access' => $access);
     $this->regexes[] = "#^{$route}\$#";
     if (Epi::getSetting('debug')) {
         getDebug()->addMessage(__CLASS__, sprintf('Found %s : %s : %s', $method, $route, json_encode($callback)));
     }
 }
예제 #4
0
 function printDebug()
 {
     echo nl2br("***************DEBUG*****************\n" . getDebug() . "\n**************************************\n");
 }
 protected function writeLinkGroup(DOMElement $parent, Configuration $configuration)
 {
     $linkElement = XmlDom::createElement($parent, 'Link');
     $this->writeSubSystem($linkElement, $this->project);
     XmlDom::createElement($linkElement, 'GenerateDebugInformation', $configuration->getDebug() ? 'true' : 'false');
     if (!$configuration . getDebug()) {
         XmlDom::createElement($linkElement, 'EnableCOMDATFolding', 'true');
         XmlDom::createElement($linkElement, 'OptimizeReferences', 'true');
     }
     if ($configuration->getWarningsAsErrors()) {
         XmlDom::createElement($linkElement, 'TreatLinkerWarningAsErrors', 'true');
     }
     $this->writeAdditionalDependencies($linkElement, $configuration);
 }
예제 #6
0
파일: index.php 프로젝트: Jpsstack/epiphany
<?php

chdir('..');
include_once '../src/Epi.php';
Epi::setPath('base', '../src');
Epi::setSetting('debug', true);
Epi::init('route', 'debug');
getRoute()->get('/', array('MyClass', 'MyMethod'));
getRoute()->get('/sample', array('MyClass', 'MyOtherMethod'));
getRoute()->get('/somepath/source', array('MyClass', 'ViewSource'));
getRoute()->run();
echo '<pre>';
echo getDebug()->renderAscii();
echo '</pre>';
/*
 * ******************************************************************************************
 * Define functions and classes which are executed by EpiCode based on the $_['routes'] array
 * ******************************************************************************************
 */
class MyClass
{
    public static function MyMethod()
    {
        echo '<h1>You are looking at the output from MyClass::MyMethod</h1>
          <ul>
            <li><a href="/debug">Call MyClass::MyMethod</a></li>
            <li><a href="/debug/sample">Call MyClass::MyOtherMethod</a></li>
            <li><a href="/debug/somepath/source">View the source of this page</a></li>
            </ul>
            <p><img src="https://github.com/images/modules/header/logov3-hover.png"></p>';
    }