Esempio n. 1
0
 /**
  * Print the greeting
  *
  * @return boolean Returns if the request has been successfully dispatched
  */
 public function greet()
 {
     /** @var \Cundd\Rest\Request $request */
     $request = $this->getRequest();
     $this->app->path('/', function ($request) {
         $greeting = 'What\'s up?';
         $hour = date('H');
         if ($hour <= '10') {
             $greeting = 'Good Morning!';
         } else {
             if ($hour >= '23') {
                 $greeting = 'Hy! Still awake?';
             }
         }
         return $greeting;
     });
     $response = $this->app->run($request);
     $responseString = (string) $response;
     $this->logResponse('response: ' . $response->status(), array('response' => '' . $responseString));
     echo $responseString;
     return TRUE;
 }
Esempio n. 2
0
 function testGetWithQueryString()
 {
     $app = new Bullet\App();
     $app->path('test', function ($request) use($app) {
         $app->get(function ($request) {
             return 'foo=' . $request->foo;
         });
     });
     $req = new Bullet\Request('GET', '/test?foo=bar');
     $res = $app->run($req);
     $this->assertEquals('foo=bar', $res->content());
 }
Esempio n. 3
0
 public function testClosureBinding()
 {
     $app = new Bullet\App();
     $app->path('closure-binding', function ($request) {
         return $this->url('/worked/');
     });
     $result = $app->run(new Bullet\Request('GET', '/closure-binding/'));
     $this->assertEquals('cli:/worked/', $result->content());
 }
Esempio n. 4
0
 public function testEventBeforeResponseHandler()
 {
     Template::config(array('path_layouts' => $this->templateDir . 'layouts/'));
     $app = new Bullet\App();
     $app->path('variableSet', function ($request) use($app) {
         return $app->template('variableSet', array('variable' => 'one'))->layout('div');
     });
     $app->on('beforeResponseHandler', function (\Bullet\Request $request, \Bullet\Response $response, $rawResponse) use($app) {
         $rawResponse->set('variable', 'two')->layout(false);
     });
     $res = $app->run('GET', '/variableSet/');
     $this->assertEquals('two', $res->content());
 }
Esempio n. 5
0
 /**
  * Register the callback for the given HTTP method(s)
  *
  * @param string]string[] $method
  * @param \Closure $callback
  * @return $this
  */
 public function registerHttpMethod($methods, \Closure $callback)
 {
     $this->app->method($methods, $callback);
     return $this;
 }
Esempio n. 6
0
 /**
  * @requires PHP 5.4
  */
 public function testPHP5_4ClosureBinding()
 {
     $app = new Bullet\App();
     // Skip test for HHVM
     if ($app->request()->isHHVM()) {
         $this->markTestSkipped('HHVM does not support Closure::bindTo');
     }
     $app->path('php5_4', function ($request) {
         return $this->url('/worked/');
     });
     $result = $app->run('GET', '/php5_4/');
     $this->assertEquals('cli:/worked/', $result->content());
 }