public function testBar()
 {
     $request = new Request(array('SERVER_NAME' => 'www.example.org', 'SERVER_PORT' => 80, 'QUERY_STRING' => '', 'REQUEST_URI' => '/bar', 'SCRIPT_NAME' => '/index.php', 'PATH_INFO' => '/bar', 'REQUEST_METHOD' => 'GET'));
     $service = new Service();
     $service->addModule(new TestModule('foo'));
     $service->addModule(new TestModule('bar'));
     $response = $service->run($request);
     $this->assertSame(array('HTTP/1.1 200 OK', 'Content-Type: text/html;charset=UTF-8', 'Content-Length: 3', '', 'bar'), $response->toArray());
 }
 public function __construct(PdoStorage $db, TemplateManager $templateManager = null)
 {
     parent::__construct();
     $this->db = $db;
     if (null === $templateManager) {
         $templateManager = new TemplateManager();
     }
     $this->templateManager = $templateManager;
     $compatThis =& $this;
     $this->get('*', function (Request $request, UserInfoInterface $userInfo) use($compatThis) {
         $id = $request->getUrl()->getQueryParameter('id');
         if (null !== $id) {
             // specific client requested
             return $compatThis->getClient($id);
         }
         return $compatThis->getClients($request, $userInfo);
     });
     $this->put('*', function (Request $request, UserInfoInterface $userInfo) use($compatThis) {
         $id = $request->getUrl()->getQueryParameter('id');
         $redirectTo = $request->getUrl()->getRootUrl();
         return $compatThis->updateClient($id, $request->getPostParameters(), $redirectTo);
     });
     $this->post('*', function (Request $request, UserInfoInterface $userInfo) use($compatThis) {
         $redirectTo = $request->getUrl()->getRootUrl();
         return $compatThis->addClient($request->getPostParameters(), $redirectTo);
     });
     $this->delete('*', function (Request $request, UserInfoInterface $userInfo) use($compatThis) {
         $id = $request->getUrl()->getQueryParameter('id');
         $redirectTo = $request->getUrl()->getRootUrl();
         return $compatThis->deleteClient($id, $redirectTo);
     });
 }
 public function __construct(PdoStorage $db, IO $io = null, $accessTokenExpiry = 3600)
 {
     parent::__construct();
     $this->db = $db;
     if (null === $io) {
         $io = new IO();
     }
     $this->io = $io;
     $this->accessTokenExpiry = (int) $accessTokenExpiry;
     $compatThis =& $this;
     $this->post('*', function (Request $request, UserInfoInterface $userInfo) use($compatThis) {
         return $compatThis->postToken($request, $userInfo);
     });
 }
 public function __construct(PdoStorage $db, IO $io = null)
 {
     parent::__construct();
     $this->db = $db;
     if (null === $io) {
         $io = new IO();
     }
     $this->io = $io;
     $compatThis =& $this;
     $this->get('*', function (Request $request) use($compatThis) {
         return $compatThis->getTokenIntrospection($request, $request->getUrl()->getQueryParameter('token'));
     });
     $this->post('*', function (Request $request) use($compatThis) {
         return $compatThis->getTokenIntrospection($request, $request->getPostParameter('token'));
     });
 }
 public function __construct(PdoStorage $db, TemplateManager $templateManager = null)
 {
     parent::__construct();
     $this->db = $db;
     if (null === $templateManager) {
         $templateManager = new TemplateManager();
     }
     $this->templateManager = $templateManager;
     $compatThis =& $this;
     $this->get('*', function (Request $request, UserInfoInterface $userInfo) use($compatThis) {
         return $compatThis->getApprovals($request, $userInfo);
     });
     $this->delete('*', function (Request $request, UserInfoInterface $userInfo) use($compatThis) {
         return $compatThis->deleteApproval($request, $userInfo);
     });
 }
 public function __construct(PdoStorage $storage, IO $io = null, $accessTokenExpiry = 3600, $allowRegExpRedirectUriMatch = false)
 {
     parent::__construct();
     $this->storage = $storage;
     if (null === $io) {
         $io = new IO();
     }
     $this->io = $io;
     $this->templateManager = new TemplateManager();
     $this->accessTokenExpiry = $accessTokenExpiry;
     $this->allowRegExpRedirectUriMatch = (bool) $allowRegExpRedirectUriMatch;
     $compatThis =& $this;
     $this->get('*', function (Request $request, UserInfoInterface $userInfo) use($compatThis) {
         return $compatThis->getAuthorization($request, $userInfo);
     });
     $this->post('*', function (Request $request, UserInfoInterface $userInfo) use($compatThis) {
         return $compatThis->postAuthorization($request, $userInfo);
     });
 }
Beispiel #7
0
 public function init(Service $service)
 {
     $service->get(sprintf('/%s', $this->routeName), function (Request $request) {
         return $this->routeName;
     });
 }
Beispiel #8
0
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once dirname(__DIR__) . '/vendor/autoload.php';
use fkooman\Rest\Service;
use fkooman\Http\Response;
use fkooman\Http\Session;
$session = new Session('foo');
$service = new Service();
$service->get('/', function () {
    $response = new Response(200, 'text/plain');
    $response->setBody('Welcome!');
    return $response;
});
$service->get('/:key', function ($key) use($session) {
    $newCount = $session->has($key) ? $session->get($key) + 1 : 1;
    $session->set($key, $newCount);
    $response = new Response(200, 'text/plain');
    $response->setBody(sprintf('count: %d', $newCount));
    return $response;
});
$service->run()->send();
Beispiel #9
0
 public function init(Service $service)
 {
     $service->get('/foo', function () {
         return 'foo';
     });
 }
Beispiel #10
0
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once dirname(__DIR__) . '/vendor/autoload.php';
use fkooman\Http\JsonResponse;
use fkooman\Rest\Service;
use fkooman\Http\Exception\BadRequestException;
$service = new Service();
$service->get('/hello/:str', function ($str) {
    $response = new JsonResponse();
    $response->setBody(array('type' => 'GET', 'response' => sprintf('hello %s', $str)));
    return $response;
});
$service->post('/hello/:str', function ($str) {
    if ('foo' === $str) {
        throw new BadRequestException('you cannot say "foo!"');
    }
    $response = new JsonResponse();
    $response->setBody(array('type' => 'POST', 'response' => sprintf('hello %s', $str)));
    return $response;
});
$service->run()->send();
Beispiel #11
0
<?php

/**
 * Copyright 2015 François Kooman <*****@*****.**>.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
require_once dirname(__DIR__) . '/vendor/autoload.php';
use fkooman\Rest\Service;
$service = new Service();
$service->get('/', function () {
    return '<html><head><title>Test</title></head><body><form method="post"><input type="submit" value="Test"></form></body></html>';
});
$service->post('/', function () {
    return '<html><head><title>Test</title></head><body>OK</body></html>';
});
$service->run()->send();
Beispiel #12
0
* limitations under the License.
*/
require_once dirname(__DIR__) . "/vendor/autoload.php";
use fkooman\Config\Config;
use fkooman\Http\JsonResponse;
use fkooman\Http\Request;
use fkooman\Http\IncomingRequest;
use fkooman\Rest\Service;
use fkooman\Rest\Plugin\BasicAuthentication;
use fkooman\VootProvider\VootStorageException;
try {
    $config = Config::fromIniFile(dirname(__DIR__) . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "voot.ini");
    $vootStorageBackend = sprintf('fkooman\\VootProvider\\%s', $config->getValue('storageBackend'));
    $vootStorage = new $vootStorageBackend($config);
    $request = Request::fromIncomingRequest(new IncomingRequest());
    $service = new Service($request);
    // require authentication?
    if (null !== $config->getValue('basicUser')) {
        $basicAuthPlugin = new BasicAuthentication($config->getValue('basicUser'), $config->getValue('basicPass'), $config->getValue('serviceName'));
        $service->registerBeforeMatchingPlugin($basicAuthPlugin);
    }
    // GROUPS
    $service->match("GET", "/groups/:uid", function ($uid) use($request, $vootStorage) {
        $groups = $vootStorage->isMemberOf($uid, $request->getQueryParameter("startIndex"), $request->getQueryParameter("count"));
        $response = new JsonResponse(200);
        $response->setContent($groups);
        return $response;
    });
    // PEOPLE IN GROUP
    $service->match("GET", "/people/:uid/:gid", function ($uid, $gid) use($request, $vootStorage) {
        $users = $vootStorage->getGroupMembers($uid, $gid, $request->getQueryParameter("startIndex"), $request->getQueryParameter("count"));
Beispiel #13
0
 public function testInit()
 {
     $testPlugin = new TestPlugin();
     $request = new Request(array('SERVER_NAME' => 'www.example.org', 'SERVER_PORT' => 80, 'QUERY_STRING' => '', 'REQUEST_URI' => '/index.php/foo', 'SCRIPT_NAME' => '/index.php', 'PATH_INFO' => '/foo', 'REQUEST_METHOD' => 'GET'));
     $service = new Service();
     $service->getPluginRegistry()->registerDefaultPlugin($testPlugin);
     $this->assertSame(array('HTTP/1.1 200 OK', 'Content-Type: text/html;charset=UTF-8', 'Content-Length: 3', '', 'foo'), $service->run($request)->toArray());
 }
Beispiel #14
0
 public function __construct()
 {
     parent::__construct();
     $this->registerRoutes();
 }