예제 #1
0
 public function testMatch()
 {
     $this->assertEquals('home page', $this->router->match(Yari\Http::GET, '/'));
     $this->assertEquals('/foo page', $this->router->match(Yari\Http::GET, '/foo'));
     $this->assertEquals('/foo/bar page with: uniqueId', $this->router->match(Yari\Http::GET, '/foo/uniqueId'));
     $this->assertEquals('/zaz post page', $this->router->match(Yari\Http::POST, '/zaz'));
     $this->assertEquals('', $this->router->match('HEAD', '/zaz'));
     $this->assertEquals(['GET', 'HEAD', 'POST', 'OPTIONS'], $this->router->options('/zaz'));
     $this->assertEquals([], $this->router->options('/url/does/not/exist'));
 }
예제 #2
0
<?php

require_once __DIR__ . '/vendor/autoload.php';
use Cachet\CacheEngine\RedisCacheEngine;
use Cachet\Controller\GlobalCacheController;
use Cachet\Controller\KeyCacheController;
$router = new Yari\Router();
/**
 * Once requested, redisProvider will create a connection to redis and return it.
 */
$redisProvider = function () {
    $redis = new RedisCacheEngine();
    $redis->connect('192.168.112.111');
    $redis->select(1);
    return $redis;
};
$router->addController('global_cache', function () use($redisProvider) {
    $redis = $redisProvider();
    return new GlobalCacheController($redis);
});
$router->addController('key_cache', function () use($redisProvider) {
    $redis = $redisProvider();
    return new KeyCacheController($redis);
});
$router->get('/cache', 'global_cache:getAllKeyValuePairs');
$router->post('/cache', 'global_cache:createNewKeyValuePair');
$router->delete('/cache', 'global_cache:deleteAllKeyValuePairs');
$router->get('/stats', 'global_cache:getStats');
$router->get('/cache/*key', 'key_cache:getValue');
$router->put('/cache/*key', 'key_cache:update');
$router->delete('/cache/*key', 'key_cache:delete');