Example #1
0
function main()
{
    $app = new App();
    $app->bootstrap();
    $app->setupErrorHandling();
    $app->dispatch();
}
class App
{
    protected $routes = array();
    protected $responseStatus = '200 OK';
    protected $responseContentType = 'text/html';
    protected $responseBody = 'Hello world';
    public function addRoute($routePath, $routeCallback)
    {
        $this->routes[$routePath] = $routeCallback->bindTo($this, __CLASS__);
    }
    public function dispatch($currentPath)
    {
        foreach ($this->routes as $routePath => $callback) {
            if ($routePath === $currentPath) {
                $callback();
            }
        }
        header('HTTP/1.1 ' . $this->responseStatus);
        header('Content-type: ' . $this->responseContentType);
        header('Content-length: ' . mb_strlen($this->responseBody));
        echo $this->responseBody;
    }
}
$app = new App();
$app->addRoute('/users/josh', function () {
    $this->responseContentType = 'application/json;charset=utf8';
    $this->responseBody = '{"name": "Josh"}';
});
$app->dispatch('/users/josh');
Example #3
0
File: index.php Project: akvlko/api
 * controller name from the URL
 * @var string
 */
$controller = $_GET['controller'];
/**
 * action name from the URL
 * @var string
 */
$action = $_GET['action'];
/**
 * application object
 * @var object
 */
$app = new App();
/**
 * setting up headers to application/json for json reponse
 */
header('Content-Type: application/json');
/**
 * parsing JSON post/put request data
 * @var json
 */
$postData = json_decode(file_get_contents("php://input"), TRUE);
/**
 * bootstraping application to its URL with controller, action and if any post data
 * echo the response
 */
echo $app->dispatch($controller, $action, $postData)->toJSON();
?>

Example #4
0
include CORE_ROOT . '/view.php';
include CORE_ROOT . '/jsonresponse.php';
include CORE_ROOT . '/appcontroller.php';
// Include libraries
include LIBRARY_ROOT . '/config.php';
include LIBRARY_ROOT . '/routing.php';
include LIBRARY_ROOT . '/debug.php';
include LIBRARY_ROOT . '/datetime.php';
include LIBRARY_ROOT . '/database.php';
include LIBRARY_ROOT . '/cache.php';
include LIBRARY_ROOT . '/string.php';
include LIBRARY_ROOT . '/array.php';
include LIBRARY_ROOT . '/validation.php';
// Include models as they are required
function __autoload($className)
{
    $className = strtolower($className);
    $modelPath = MODEL_ROOT . '/' . $className . '.php';
    $libPath = LIBRARY_ROOT . '/' . $className . '.php';
    if (Config::get('library_auto_discovery') && file_exists($libPath)) {
        include $libPath;
    } elseif (Config::get('model_auto_discovery') && file_exists($modelPath)) {
        include $modelPath;
    }
}
/**
 * Bootstrap the App and dispatch the request.
 */
$APP = new App();
$APP->dispatch();
*
*	- POST params
*/
/*
$_POST = array(
	'action' => 'install',
	'application_code' => '21e6f0c7c42542af3bbf267cfde9763a',
	'application_version' => '4',
	'auth_code' => 'fc9ada2c29cfe4e10f89500b0219f128',
	'shop' => '2f7fea8b3e9231a80d5bbea019643a9bf656c63d',
	'shop_url' => 'https://devshop-63421.shoparena.pl',
	'timestamp' => '2015-06-25 10:14:16',
	'hash' => '065f07fd45d5c3332ab6adf2d6b4f7c352baa00c558c364df65bc4fe64c5d3284acf28de25d457d241b88c791f0cf90b2c8ae8c725e3f5edee7bd9ab86a097d4'
);
*/
/*
$f = file_get_contents('log.txt');
$f .= '--- '.date('d-m-Y')." ---\n\n".print_r($_POST, true)."\n\n\n";
file_put_contents('log.txt', $f);
*/
// check if valid request
if (empty($_POST['shop_url']) || empty($_POST['action'])) {
    die;
}
require 'config.php';
require 'lib/BillingSystem.php';
//use Retargeting\Lib\App;
$app = new App(Config(), $_POST);
if ($app->validRequest) {
    $app->dispatch();
}
Example #6
0
 /**
  * Dispatch the application using the default controller
  *
  * @since 2.0
  */
 public function dispatch()
 {
     // delegate dispatch
     $this->app->dispatch('default');
 }
<?php

/**
* Configuration Ajax Route
*
* - route for configuration changes in the App's Administration section
*/
if (empty($_POST['shopId']) || empty($_POST['shopEmail']) || empty($_POST['shopContext'])) {
    die('<p>unauthorized request!</p>');
}
if ((!isset($_POST['domainApiKey']) || !isset($_POST['discountsApiKey'])) && empty($_POST['disableInit'])) {
    die('<p>Invalid request!</p>');
}
require 'config.php';
require 'lib/Ajax.php';
$app = new App(Config());
if ($app->validRequest) {
    die($app->dispatch());
}
Example #8
0
<?php

/**
*	JS API Index
*
*	- POST params
*/
// check if valid request
if (empty($_GET['shop'])) {
    die('/*' . json_encode(array("Error" => "Invalid Request!")) . '*/');
}
require 'config.php';
require 'lib/Api.php';
//use Retargeting\Lib\App;
$app = new App(Config());
if ($app->validRequest) {
    echo $app->dispatch();
}
class App
{
    protected $routes = array();
    protected $responseStatus = '200 OK';
    protected $responseContentType = 'text/html';
    protected $responseBody = 'Hello world';
    public function addRoute($routePath, $routeCallback)
    {
        $this->routes[$routePath] = $routeCallback->bindTo($this, __CLASS__);
    }
    public function dispatch($currentPath)
    {
        foreach ($this->routes as $routePath => $callback) {
            if ($routePath === $currentPath) {
                $callback();
            }
        }
        header('HTTP/1.1 ' . $this->responseStatus);
        header('Content-type: ' . $this->responseContentType);
        header('Content-length: ' . mb_strlen($this->responseBody));
        echo $this->responseBody;
    }
}
$app = new App();
$app->addRoute('/users/thiengo', function () {
    $this->responseContentType = 'application/json;charset=utf8';
    $this->responseBody = '{"name", "Thiengo"}';
});
$app->dispatch('/users/thiengo');