on() 공개 메소드

public on ( $name, $callback )
 function testUpdatePropertiesEventSuccess()
 {
     $tree = [new SimpleCollection('foo')];
     $server = new Server($tree);
     $server->on('propPatch', function ($path, PropPatch $propPatch) {
         $propPatch->handle(['{DAV:}foo', '{DAV:}foo2'], function () {
             return ['{DAV:}foo' => 200, '{DAV:}foo2' => 201];
         });
     });
     $result = $server->updateProperties('foo', ['{DAV:}foo' => 'bar', '{DAV:}foo2' => 'bla']);
     $expected = ['{DAV:}foo' => 200, '{DAV:}foo2' => 201];
     $this->assertEquals($expected, $result);
 }
예제 #2
0
<?php

require_once __DIR__ . '/../vendor/autoload.php';
use CapMousse\ReactRestify\{Server, Runner};
use CapMousse\ReactRestify\Async\Timeout;
use CapMousse\ReactRestify\Promise\AsyncPromise;
$server = new Server("ReactAPI", "0.0.0.1");
$server->post('/', function ($req, $res, $next) {
    $image = (object) $req->httpRequest->getFiles()['filename'];
    AsyncPromise::run(function ($image) {
        file_put_contents(__DIR__ . "/" . rand() . ".jpg", $image->stream);
    }, $image)->then(function () use($res, $next) {
        $res->addHeader("Content-Type", "text/html");
        $res->write("result");
        $next();
    });
});
$server->on('NotFound', function ($request, $response, $next) {
    $response->write('You fail, 404');
    $response->setStatus(404);
    $next();
});
$runner = new Runner($server);
$runner->listen(8080);