Example #1
0
    /**
     * When silent mode is off this function will output debug message and break appliaction flow.
     * Otherwise message will be added to log
     *
     * @param string $message
     * @return void
     */
    public static function debug($message)
    {
        $backtrace = debug_backtrace();
        // Remove info about self from backtrace
        array_shift($backtrace);
        $msg = '
        <p><strong>Requested URL</strong>: ' . Server::getAbsoluteURL() . '</p>
	    <p><strong>Debug message</strong>: ' . $message . '</p>
	    <p><strong>Backtrace:</strong><br>
	    <pre>' . print_r($backtrace, true) . '</pre></p>';
        if (self::$silentMode) {
            self::$log[] = $msg;
        } else {
            echo $msg;
            exit;
        }
    }
Example #2
0
 public function testUrlParsing()
 {
     $url = '/test/test-method/lang-es/page-5/arg1/arg2:test2/arg3:test3,arg4:test4/arg5,arg6';
     Server::getDocumentRoot();
     $controller = new class extends Controller
     {
         public function test_method()
         {
             return 'test';
         }
     };
     $router = new Router(['test' => $controller]);
     $environment = new Environment();
     $framework = new Framework($router, $environment);
     $framework->run($url, TRUE);
     $this->assertEquals('es', $framework->getRouter()->getLang());
     $this->assertEquals(5, $framework->getRouter()->getPage());
     $this->assertEquals('test_method', $framework->getRouter()->getMethod());
     $this->assertEquals($controller, $framework->getRouter()->getController());
     $this->assertEquals($url, $framework->getRouter()->getUrl());
     $this->assertEquals(['arg1', 'arg2' => 'test2', ['arg3' => 'test3', 'arg4' => 'test4'], ['arg5', 'arg6']], $framework->getRouter()->getMethodArguments());
 }
Example #3
0
 /**
  * Make given string a proper URL
  *
  * @author Krzysztof Kalkhoff
  *        
  * @param string $url            
  * @return string
  */
 public static function makeUrl(string $url) : string
 {
     if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
         $url = 'http' . (Server::isSecure() ? 's' : '') . "://" . $url;
     }
     return $url;
 }
Example #4
0
 public function __construct(string $domain = null, string $type = EnvironmentInterface::TYPE_DEVELOPMENT)
 {
     $this->domain = $domain ?? Server::getDomain();
     $this->type = $type;
 }
Example #5
0
 /**
  * Create request object using $_GET and $_POST
  *
  * @return Request
  */
 public static function createFromGlobals()
 {
     return new self($_GET, $_POST, Server::getHeaders(), Server::getRequestMethod());
 }