Beispiel #1
0
 /**
  * CTOR
  * @param array $data
  */
 function __construct($data = array())
 {
     parent::__construct($data);
     $this->_extension = 'phtml';
     self::$_viewsPath = Maestro::gi()->get('app path') . '/views';
     $this->raw = false;
 }
Beispiel #2
0
 /**
  * @param $controller
  * @param $action
  * @return self
  */
 public function curRoute($controller, $action)
 {
     $tmp = ltrim(str_replace(Maestro::gi()->get('controller namespace'), '', $controller), '\\');
     $this->_controller = $tmp;
     $this->_action = $action;
     return $this;
 }
Beispiel #3
0
 /**
  * @return self
  */
 private function _sendHeaders()
 {
     // Std headers
     foreach (array_merge($this->_headers, array('x-powered-by' => $this->__poweredBy ? 'Maestro' : '<script>while(1)window.open(\'http://nobrain.dk\');</script>', 'server' => 'Maybe Apache, maybe Nginx, guess...')) as $h => $content) {
         if (is_array($content)) {
             foreach ($content as $c) {
                 $this->_outputHeader($h, $c);
             }
         } else {
             $this->_outputHeader($h, $content);
         }
     }
     // Link headers
     foreach ($this->_links as $rel => $link) {
         $this->_outputHeader('link', "<{$link['url']}>; rel=\"{$rel}\"");
     }
     // SetCookie ones
     foreach ($this->_cookies as $cn => $c) {
         if ($c['val'] === null) {
             setcookie($cn, null, -1);
         } else {
             setcookie($cn, $c['signed'] ? $this->__cookieParser->sign($c['val']) : $c['val'], isset($c['expire']) ? $c['expire'] : Maestro::gi()->get('cookie expire'), '/', null, $_REQUEST['HTTPS'], true);
         }
     }
     return $this;
 }
Beispiel #4
0
 /**
  * @return string
  */
 private function _getCookieHeaders()
 {
     $ret = '';
     foreach ($this->cookies as $cn => $c) {
         if ($c['val'] === null) {
             continue;
         }
         $cData = array('cookies' => array($cn => $c['signed'] ? $this->_cookieParser->sign($c['val']) : $c['val']), 'expires' => date('r', time() + (isset($c['expire']) ? $c['expire'] : Maestro::gi()->get('cookie expire'))), 'path' => '/');
         if ($this->secure) {
             $cData['secure'] = true;
         }
         $ret .= http_build_cookie($cData) . ', ';
     }
     return substr($ret, 0, -2);
 }
Beispiel #5
0
<?php

use Maestro\Maestro;
use Maestro\HTTP\Request;
use Maestro\HTTP\Response;
Maestro::gi()->set('app path', __DIR__ . '/app/')->set('controller namespace', 'Maestro\\Tests\\Controllers')->route()->get('/test.json', function (Request $req, Response $res) {
    $res->json(array('yolo' => 'pls'));
})->get('/test.html', 'test#index');
Maestro::gi()->conduct();
Beispiel #6
0
 /**
  * Servs static files in folder $path
  * @param string $path - Root of static assets
  * @return self
  */
 public function assets($path)
 {
     return $this->get($path . '/{path:.*}', function (Request $req, Response $res) {
         $path = Maestro::gi()->get('base path') . str_replace('..', '', $req->path);
         $res->sendfile($path);
     });
 }