Esempio n. 1
0
<?php

require '../vendor/autoload.php';
// Constants
define('base_path', dirname(__DIR__));
define('app_path', base_path . DIRECTORY_SEPARATOR . 'app');
define('content_path', base_path . DIRECTORY_SEPARATOR . 'content');
define('layouts_path', base_path . DIRECTORY_SEPARATOR . 'layouts');
// We start Slim and create a new PagesCollection
$app = new \Slim\Slim(['debug' => true]);
$pages = new \App\PagesCollection();
// Let's load all the helpers funtions
require app_path . DIRECTORY_SEPARATOR . 'helpers.php';
// Let's create a route for every YAML file in the content directory
foreach ($pages as $page) {
    // We use any cause we may need to access some page using POST to create forms for instance
    $app->any($page->getUrl(), function () use($page, $app) {
        echo $page->render();
    })->name($page->getName());
}
// Let's run our awesome app
$app->run();
Esempio n. 2
0
 public function testAnyRoute()
 {
     $mw1 = function () {
         echo "foo";
     };
     $mw2 = function () {
         echo "bar";
     };
     $callable = function () {
         echo "xyz";
     };
     $methods = array('GET', 'POST', 'PUT', 'DELETE', 'OPTIONS');
     foreach ($methods as $i => $method) {
         \Slim\Environment::mock(array('REQUEST_METHOD' => $method, 'SCRIPT_NAME' => '/foo', 'PATH_INFO' => '/bar'));
         $s = new \Slim\Slim();
         $route = $s->any('/bar', $mw1, $mw2, $callable);
         $s->call();
         $this->assertEquals('foobarxyz', $s->response()->body());
         $this->assertEquals('/bar', $route->getPattern());
         $this->assertSame($callable, $route->getCallable());
     }
 }
Esempio n. 3
0
/**
 * SocialConnect project
 * @author: Patsura Dmitry https://github.com/ovr <*****@*****.**>
 */
error_reporting(-1);
ini_set('display_errors', 1);
include_once __DIR__ . '/../vendor/autoload.php';
include_once __DIR__ . '/vendor/autoload.php';
$configureProviders = (include_once 'config.php');
$service = new \SocialConnect\Auth\Service($configureProviders, new \SocialConnect\Auth\Provider\CollectionFactory());
$service->setHttpClient(new \SocialConnect\Common\Http\Client\Curl());
$app = new \Slim\Slim();
$app->any('/dump:params', function () {
    var_dump($_POST);
    var_dump($_GET);
    var_dump($_SERVER);
});
$app->get('/auth/cb/:provider/:params', function ($provider) use(&$configureProviders, $service) {
    $provider = strtolower($provider);
    if (!$service->getFactory()->has($provider)) {
        throw new \Exception('Wrong $provider passed in url : ' . $provider);
    }
    $provider = $service->getProvider($provider);
    $accessToken = $provider->getAccessTokenByRequestParameters($_GET);
    var_dump($accessToken);
    $user = $provider->getIdentity($accessToken);
    var_dump($user);
});
$app->get('/', function () {
    include_once 'page.php';
Esempio n. 4
0
 * GET /atendimento/1
 */
$app->get('/atendimento/:id', function ($id) use($app, $api, $server) {
    $server->checkAccess();
    echo json_encode($api->atendimento($id));
});
/*
 * Visualiza um atendimento que ainda não foi arquivado
 */
$app->get('/atendimento/:id/info', function ($id) use($app, $api, $server) {
    $server->checkAccess();
    echo json_encode($api->atendimentoInfo($id));
});
/*
 * Check extra route from configuration file
 */
$config = new Novosga\Config\ApiConfig();
foreach ($config->routes() as $pattern => $callable) {
    if (substr($pattern, 0, 1) !== '/') {
        $pattern = "/{$pattern}";
    }
    $app->any("/extra{$pattern}", $callable);
}
// response
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: origin, x-requested-with, content-type');
$app->contentType('application/json');
$app->run();
<?php

require '../vendor/autoload.php';
//__ gestion des erreurs
ini_set('display_errors', 'on');
error_reporting(E_ALL);
// Constants
define('base_path', dirname(__DIR__));
define('app_path', base_path . DIRECTORY_SEPARATOR . 'app');
define('content_path', base_path . DIRECTORY_SEPARATOR . 'content');
define('layouts_path', base_path . DIRECTORY_SEPARATOR . 'views');
// We start Slim and create a new PagesCollection
$app = new \Slim\Slim(['debug' => true]);
$pages = new \App\PagesCollection();
// Let's create a route for every YAML file in the content directory
foreach ($pages as $page) {
    // We use any cause we may need to access some page using POST to create forms for instance
    $app->any($page->getUrl(), function () use($page, $app) {
        require app_path . '/helpers.php';
        echo $page->render();
    })->name($page->getName());
}
// Let's run our awesome app
$app->run();
Esempio n. 6
0
<?php

require 'vendor/autoload.php';
define('content_path', getcwd() . DIRECTORY_SEPARATOR . 'content');
define('layout_path', getcwd() . DIRECTORY_SEPARATOR . 'layout');
$app = new \Slim\Slim(['debug' => true]);
$files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(content_path));
$files = new RegexIterator($files, '/^.+\\.(markdown|html)/i', RecursiveRegexIterator::GET_MATCH);
$lang = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
foreach ($files as $file) {
    $file = $file[0];
    $page = new \App\Page($file);
    if ($page->lang === $lang) {
        $app->any($page->path, function () use($page, $app) {
            $pathHelper = getcwd() . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'helpers.php';
            require $pathHelper;
            echo $page->render();
        });
    }
}
$app->run();
Esempio n. 7
0
});
$app->get('/logout', function () use($app, $auth) {
    $auth->destroy();
    $app->redirect($app->request()->getRootUri() . "/login");
});
// controllers
$app->any('/:controller(/)(:action(/)(:params+))', function ($controller, $action = 'index', $params = array()) use($app) {
    $class = "{$app->controllerNamespace}\\" . ucfirst($controller) . "Controller";
    try {
        if (!class_exists($class)) {
            throw new \Exception('Controller not found');
        }
        $ctrl = new $class($app);
        $methodName = preg_replace('/[^A-z0-9]/', '_', $action);
        $ref = new \ReflectionMethod($class, $methodName);
        if (!$ref->isPublic()) {
            throw new \Exception('Controller method is not public.');
        }
        $view = $methodName;
        $rs = $ref->invokeArgs($ctrl, $params);
        if ($rs) {
            $view = $rs;
        }
        $app->render("{$controller}/{$view}.html.twig");
    } catch (\Exception $e) {
        //        echo $e->getMessage();
        $app->notFound();
    }
});
// Run app
$app->run();