/**
  */
 public function testEndpointWithComplexRedirectionRequest()
 {
     $_SERVER['SCRIPT_NAME'] = '/apps/index.php';
     $_SERVER['REQUEST_URI'] = '/botk/core/samples/v1/hello/testpar/mypar?thisisavar=value';
     $_SERVER['PATH_INFO'] = '/hello/testpar/mypar';
     $result = EndPointFactory::make()->mountEndPoint('hello', 'EndPointStub')->run();
     $this->assertEquals($result, 'mypar');
 }
示例#2
0
 * limitations under the License.
 * 
 */
require '../../vendor/autoload.php';
use BOTK\Core\EndPointFactory, BOTK\Core\ErrorManager;
// Control errors
use Geocodit\View\GoogleAnalyticsEnabledRenderer;
// for CSS
use BOTK\Context\Context;
// get config vars and other inputs
use BOTK\Context\ContextNameSpace as CX;
// search configs files in  in config and /etc/geocodit directories
if (!isset($_ENV['BOTK_CONFIGDIR'])) {
    if (file_exists(__DIR__ . '/../../config/geocodit.ini')) {
        $_ENV['BOTK_CONFIGDIR'] = realpath(__DIR__ . '/../../config');
    } elseif (is_dir('/etc/geocodit')) {
        $_ENV['BOTK_CONFIGDIR'] = '/etc/geocodit';
    }
}
// Enable Universal Analytics code
$UA = Context::factory()->ns('geocodit')->getValue('UA', CX::NULL_AS_DEFAULT);
GoogleAnalyticsEnabledRenderer::$UniversalAnalyticsId = $UA;
// Enable the catching of PHP errors
$errorManager = ErrorManager::getInstance()->registerErrorHandler();
try {
    $endpoint = EndPointFactory::make('Geocodit\\ApiEndpoint');
    $result = $endpoint->run();
} catch (Exception $e) {
    $result = ErrorManager::getInstance()->render($e);
}
echo $result;
示例#3
0
/**
 * This example shows how to use content management policies for a RDF source.
 * It reads sample.ttl turtle file and renders it in all RDF serialization + html.
 */
require '../vendor/autoload.php';
use BOTK\Core\EndPoint, BOTK\Core\Controller, BOTK\Core\EndPointFactory, BOTK\Core\ErrorManager;
use BOTK\RDF\Representations\RDF;
use EasyRdf_Graph as Graph;
class Router extends EndPoint
{
    protected function setRoutes()
    {
        $this->get('/', 'sampleManager')->accept(RDF::renderers());
    }
}
class sampleManager extends Controller
{
    public function get()
    {
        $graph = new Graph();
        $graph->parseFile('sample.ttl');
        return $graph;
    }
}
$errorManager = ErrorManager::getInstance()->registerErrorHandler();
try {
    echo EndPointFactory::make('Router')->run();
} catch (Exception $e) {
    echo $errorManager->render($e);
}
示例#4
0
 * 
 */
require '../../vendor/autoload.php';
use BOTK\Core\EndPointFactory, BOTK\Core\ErrorManager;
// Control errors
use BOTK\Core\Representations\Standard;
// for CSS
// search configs files in  in config and /etc/geocodit directories
if (!isset($_ENV['BOTK_CONFIGDIR'])) {
    if (file_exists(__DIR__ . '/../../config/geocodit.ini')) {
        $_ENV['BOTK_CONFIGDIR'] = realpath(__DIR__ . '/../../config');
    } elseif (is_dir('/etc/geocodit')) {
        $_ENV['BOTK_CONFIGDIR'] = '/etc/geocodit';
    }
}
// Enable the catching of PHP errors
$errorManager = ErrorManager::getInstance()->registerErrorHandler();
try {
    $endpoint = EndPointFactory::make('Geocodit\\GatewayEndpoint');
    $result = $endpoint->run();
} catch (Exception $e) {
    $result = ErrorManager::getInstance()->render($e);
}
//optimized ouput file resources
if (is_resource($result)) {
    while (!eof($result)) {
        echo fread($result, 1048576);
    }
} else {
    echo $result;
}
示例#5
0
}
/**
 * Full hypermedia RESTful state transfer controller
 */
class SparqlController extends Controller
{
    public function get()
    {
        // sanitize request input
        $username = filter_input(INPUT_GET, 'username', FILTER_SANITIZE_STRING);
        $password = filter_input(INPUT_GET, 'password', FILTER_SANITIZE_STRING);
        $endpoint = filter_input(INPUT_GET, 'endpoint', FILTER_SANITIZE_URL);
        $query = filter_input(INPUT_GET, 'query', FILTER_UNSAFE_RAW);
        // prepare request content model
        if ($endpoint && $query) {
            HttpClient::useIdentity($username, $password);
            $sparql = new SparqlClient($endpoint);
            $result = $sparql->query($query);
        } else {
            $result = new Graph($_SERVER['REQUEST_URI']);
        }
        return self::stateTransfer($result, WebLink::factory('sparqlForm.php?' . http_build_query($_GET))->rel('edit'));
    }
}
$errorManager = ErrorManager::getInstance()->registerErrorHandler();
try {
    echo EndPointFactory::make('SparqlAgentRouter')->run();
} catch (Exception $e) {
    echo $errorManager->render($e);
}
//echo memory_get_usage ();
<?php

/**
 * see sample doc in index.html
 */
$loader = (require '../vendor/autoload.php');
$loader->add('mylibrary\\', __DIR__);
// local end-points inclusion by composer autoloder
define('_BOTK', true);
// extra security in includes
use BOTK\Core\EndPointFactory;
use BOTK\Core\EndPoint;
use BOTK\Core\ErrorManager;
class Helloworld extends EndPoint
{
    protected function setRoutes()
    {
        $this->get('/', 'Try /hi and /hello resources.');
    }
}
$errorManager = ErrorManager::getInstance()->registerErrorHandler();
try {
    echo EndPointFactory::make('Helloworld')->mountEndPoint('hi', '\\mylibrary\\SimpleHelloEndPoint')->mountEndPoint('hello', '\\mylibrary\\HelloEndPoint\\Router')->run();
} catch (Exception $e) {
    echo $errorManager->render($e);
}
<?php

/**
 * see sample doc in index.html
 */
require '../vendor/autoload.php';
use BOTK\Core\EndPoint, BOTK\Core\EndPointFactory, BOTK\Core\ErrorManager, BOTK\Core\Representations\Standard;
class MyEndPoint extends EndPoint
{
    protected function setRoutes()
    {
        $this->get('/', 'Hello world')->accept(Standard::renderers());
    }
}
try {
    echo EndPointFactory::make('MyEndPoint')->run();
} catch (Exception $e) {
    echo ErrorManager::getInstance()->render($e);
}