예제 #1
0
파일: HahnsTest.php 프로젝트: pklink/hahns
 public function testParameter()
 {
     // register parameter
     $this->instance->parameter('type', function () {
     });
     // register parameter with invalid type
     try {
         $this->instance->parameter([], function () {
         });
         $this->fail();
     } catch (InvalidArgumentException $e) {
     }
     // register invalid parameter
     try {
         $this->instance->parameter('type', 'invalid');
         $this->fail();
     } catch (ErrorException $e) {
     }
     // with app as parameter
     $tmp = '';
     $this->instance->get('/bla', function (\Hahns\Hahns $app) use(&$tmp) {
         $tmp = $app;
     });
     $this->instance->run('/bla', 'get');
     $this->assertInstanceOf('\\Hahns\\Hahns', $tmp);
     // register parameter as singleton (default)
     $hahns = new \Hahns\Hahns();
     $hahns->parameter('\\IsSingleton', function () {
         return new IsSingleton();
     });
     // regiser parameter as non-singleton
     $hahns->parameter('\\IsNotSingleton', function () {
         return new IsNotSingleton();
     }, false);
     // test singleton parameter
     $tmp = '';
     $hahns->get('/singleton', function (IsSingleton $p) use($tmp) {
         $tmp = $p->test;
     });
     $hahns->run('/singleton', 'get');
     $test = $tmp;
     $hahns->run('/singleton', 'get');
     $this->assertEquals($test, $tmp);
     // test non-singleton parameter
     $tmp = '';
     $hahns->get('/is/not/singleton', function (IsNotSingleton $p) use(&$tmp) {
         $tmp = $p->test;
     });
     $hahns->run('/is/not/singleton', 'get');
     $test = $tmp;
     $hahns->run('/is/not/singleton', 'get');
     $this->assertNotEquals($test, $tmp);
 }
예제 #2
0
파일: server.php 프로젝트: pklink/hahns
<?php

require __DIR__ . '/../../vendor/autoload.php';
// create app
$app = new \Hahns\Hahns();
require '_server/json-get.php';
require '_server/json-get-serviceholder.php';
require '_server/json-post.php';
require '_server/json-put.php';
require '_server/json-patch.php';
require '_server/json-delete.php';
require '_server/header.php';
require '_server/redirect.php';
require '_server/parameters.php';
require '_server/text-get.php';
require '_server/html-get.php';
require '_server/events.php';
require '_server/not-found.php';
require '_server/error.php';
require '_server/named-routes.php';
require '_server/any.php';
$app->on(\Hahns\Hahns::EVENT_NOT_FOUND, function () {
    echo '1';
});
// run app
$app->run();