/**
  * Handle a call to the app
  * 
  * @param  string $method  GET/POST
  * @param  string $path    URI
  * @param  array  $options
  */
 public function request($method, $path, $options = [])
 {
     ob_start();
     $settings = (require __DIR__ . '/../../lib/settings.php');
     $container = new \Slim\Container($settings);
     require __DIR__ . '/../../lib/containers.php';
     $container->get('environment')['REQUEST_URI'] = $path;
     $container->get('environment')['REQUEST_METHOD'] = $method;
     // Set up custom 404 so that we can easilly check if the page wasn't found
     $container['notFoundHandler'] = function ($container) {
         return function ($request, $response) use($container) {
             return $container['response']->withStatus(404)->withHeader('Content-Type', 'text/plain')->write('Page not found');
         };
     };
     $sentinel = m::mock('sentinel');
     $container['sentinel'] = function ($container) use($sentinel) {
         return $sentinel;
     };
     $app = new \Slim\App($container);
     // Set up dependencies
     require __DIR__ . '/../../lib/dependencies.php';
     // Register middleware
     require __DIR__ . '/../../lib/middleware.php';
     // Register routes
     require __DIR__ . '/../../lib/routes.php';
     $app->run();
     $this->app = $app;
     $this->request = $app->getContainer()->request;
     $this->response = $app->getContainer()->response;
     $this->page = ob_get_clean();
 }
예제 #2
0
 public function call($method, $path, $params = array(), $body = '')
 {
     $app = new \Slim\App(array('settings' => array('determineRouteBeforeAppMiddleware' => true)));
     $settings = array('disableSites' => false, 'routes' => array('admin' => '/{site}/admin', 'account' => '/{site}', 'default' => '/{site}', 'confirm' => '/{site}', 'update' => '/{site}'));
     $boot = new \Aimeos\Slim\Bootstrap($app, $settings);
     $boot->setup(dirname(__DIR__) . '/ext')->routes(dirname(__DIR__) . '/src/aimeos-routes.php');
     $c = $app->getContainer();
     $env = \Slim\Http\Environment::mock(array('REQUEST_METHOD' => $method, 'REQUEST_URI' => $path, 'QUERY_STRING' => http_build_query($params)));
     $c['request'] = \Slim\Http\Request::createFromEnvironment($env);
     $c['request']->getBody()->write($body);
     $c['response'] = new \Slim\Http\Response();
     $twigconf = array('cache' => sys_get_temp_dir() . '/aimeos-slim-twig-cache');
     $c['view'] = new \Slim\Views\Twig(dirname(__DIR__) . '/templates', $twigconf);
     $c['view']->addExtension(new \Slim\Views\TwigExtension($c['router'], $c['request']->getUri()));
     return $app->run(true);
 }
예제 #3
0
$container['db'] = function ($c) {
    $dsn = 'mysql:dbname=' . $_ENV['DB_NAME'] . ';host=' . $_ENV['DB_HOST'];
    return new \PDO($dsn, $_ENV['DB_USER'], $_ENV['DB_PASS']);
};
$container['flash'] = function () {
    return new \Slim\Flash\Messages();
};
// Make the session instance
$container['session'] = function () {
    $data = array();
    $sessionFactory = new \Aura\Session\SessionFactory();
    return $sessionFactory->newInstance($data);
};
$container['errorHandler'] = function ($c) {
    return function ($request, $response, $ex) use($c) {
        echo $c['view']->render($response, 'error/index.twig', ['message' => $ex->getMessage()]);
        return $c['response'];
    };
};
//----------------------
$app = new \Slim\App($container);
$app->add(new \Conftrack\Middleware\Auth($container));
// Load the controllers
$dir = new DirectoryIterator(APP_PATH . '/' . APP_NAMESPACE . '/Controller');
foreach ($dir as $fileinfo) {
    if (!$fileinfo->isDot()) {
        require_once $fileinfo->getPathname();
    }
}
$app->run();
예제 #4
0
require __DIR__ . '/../../vendor/autoload.php';
/**
 * API config
 */
require __DIR__ . '/../../config/api.php';
/**
 * Database config
 */
require __DIR__ . '/../../config/database.php';
/**
 * Configure a new instance of our api
 */
$settings = [];
$api = new \Slim\App($settings);
/**
 * Set up dependencies
 */
// require __DIR__ . '/../../src/dependencies.php';
/**
 * Register middleware
 */
// require __DIR__ . '/../../src/middleware.php';
/**
 * Register routes
 */
require __DIR__ . '/../../src/routes.php';
/**
 * Run das app!
 */
$api->run();
예제 #5
0
파일: Wow.php 프로젝트: dudusouza/wowadmin
 /**
  * Executa o sistema
  */
 public static function run()
 {
     self::$slimObj->run();
 }
예제 #6
0
 protected function getSlimTest(string $method, string $url, array $headers = []) : ResponseInterface
 {
     $slim = new \Slim\App(['settings' => ['displayErrorDetails' => true]]);
     // add the CORs middleware
     $cors = $this->getCors($slim->getContainer());
     $slim->add($cors);
     // finish adding the CORs middleware
     // add our own error handler.
     $errorHandler = function (ContainerInterface $container) : callable {
         $handler = function (ServerRequestInterface $request, ResponseInterface $response, \Exception $e) : ResponseInterface {
             $body = new Body(fopen('php://temp', 'r+'));
             $body->write('Error Handler caught exception type ' . get_class($e) . ': ' . $e->getMessage());
             $return = $response->withStatus(500)->withBody($body);
             return $return;
         };
         return $handler;
     };
     // add the error handler.
     $slim->getContainer()['errorHandler'] = $errorHandler;
     // add dummy routes
     $slim->get('/foo', function (Request $req, Response $res) {
         $res->write('getted hi');
         return $res;
     });
     $slim->post('/foo', function (Request $req, Response $res) {
         $res->write('postted hi');
         return $res;
     });
     // Prepare request and response objects
     $uri = Uri::createFromString($url);
     $slimHeaders = new Headers($headers);
     $body = new RequestBody();
     $request = new Request($method, $uri, $slimHeaders, [], [], $body);
     $response = new Response();
     // override the Slim request and responses with our dummies
     $slim->getContainer()['request'] = $request;
     $slim->getContainer()['response'] = $response;
     // invoke Slim
     /* @var \Slim\Http\Response $result */
     $result = $slim->run(true);
     // check we got back what we expected
     $this->assertInstanceOf('\\Psr\\Http\\Message\\ResponseInterface', $result);
     $this->assertInstanceOf('\\Slim\\Http\\Response', $result);
     return $result;
 }
예제 #7
0
    exit;
}
// Set the name of the association
$templacat->set_variable('ASSOCIATION_NAME', $config['association']);
// Try to connect to the database
try {
    $slim->pdo = new PDO('mysql:host=' . $config['db_host'] . ';dbname=' . $config['db_name'], $config['db_user'], $config['db_pass'], array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
} catch (PDOException $e) {
    die('<h1>Unable to connect to the database</h1>');
}
// Check if the user is connected, or if he tries to access a login page
if ((!isset($_SESSION['connection_state']['connected']) || $_SESSION['connection_state']['connected'] !== true) && substr($_SERVER['REQUEST_URI'], 0, 10) !== '/connexion') {
    header('Location: connexion');
}
// Then redirect to the login page
// If the user has a name, then we set it
if (isset($_SESSION['connection_state']['name'])) {
    $templacat->set_variable('USER_NAME', $_SESSION['connection_state']['name']);
}
// Then include the router file
include 'router.php';
// Start buffering the output
ob_start();
// Render the view from Slim
$slim->run();
// And save the output to a Templacat variable
$templacat->set_variable('PAGE_CONTENT', ob_get_contents());
// Delete the buffer, without outputing the content
ob_end_clean();
// And finally render the template
echo $templacat->render();
예제 #8
0
        $galleryPassword = $this->get('UseCaseFactory')->getGalleryPassword($arguments['slug'])->execute();
    } catch (UseCaseException $ex) {
        throw new NotFoundException($request, $response);
    }
    return $this->get('Twig')->render($response, 'gallery/password.html', $galleryPassword);
})->setName('GalleryPassword');
$gallery->post('/gallery/{slug}/password', function ($request, $response, $arguments) {
    try {
        $galleryPassword = $this->get('UseCaseFactory')->getGalleryPassword($arguments['slug'])->execute();
    } catch (UseCaseException $ex) {
        throw new NotFoundException($request, $response);
    }
    $postParams = $request->getParsedBody();
    $destinationUrl = '/gallery/' . $arguments['slug'];
    if (isset($postParams['password']) && $galleryPassword['gallery']->isPasswordCorrect($postParams['password'])) {
        $this->get('PasswordStorage')->setForGallerySlug($arguments['slug'], $postParams['password']);
    } else {
        $destinationUrl .= '/password';
    }
    return $response->withStatus(302)->withHeader('Location', $destinationUrl);
});
$gallery->get('/image/{hash}', function ($request, $response, $arguments) {
    try {
        $imageShow = $this->get('UseCaseFactory')->getImageShow($arguments['hash'])->execute();
    } catch (UseCaseException $ex) {
        throw new NotFoundException($request, $response);
    }
    return $this->get('Twig')->render($response, 'image/show.html', $imageShow);
})->setName('ImageShow');
$gallery->run();
예제 #9
0
 public function run()
 {
     $configuration = ['settings' => ['displayErrorDetails' => false]];
     $c = new \Slim\Container($configuration);
     $c['notFoundHandler'] = function ($c) {
         return function ($request, $response) use($c) {
             return $c['response']->withStatus(404)->withHeader('Content-type', 'application/json')->write(json_encode(array('status' => 404, 'error' => 'not_found', 'pretty_error' => 'Could not find the specified endpoint.'), JSON_PRETTY_PRINT));
         };
     };
     $c['errorHandler'] = function ($c) {
         return function ($request, $response) use($c) {
             return $c['response']->withStatus(500)->withHeader('Content-type', 'application/json')->write(json_encode(array('status' => 404, 'error' => 'internal_error', 'pretty_error' => 'An internal error has occured, please contact the site administrator.'), JSON_PRETTY_PRINT));
         };
     };
     $app = new \Slim\App($c);
     $app->add(new AuthenticationMiddleware());
     $app->get('/oauth/v2/authorize', 'PleioRest\\Controllers\\Authentication::authorize');
     $app->post('/oauth/v2/token', 'PleioRest\\Controllers\\Authentication::getToken');
     $app->get('/api/users/me', 'PleioRest\\Controllers\\User:me');
     $app->post('/api/users/me/register_push', 'PleioRest\\Controllers\\User:registerPush');
     $app->post('/api/users/me/deregister_push', 'PleioRest\\Controllers\\User:deregisterPush');
     $app->post('/api/users/me/generate_token', 'PleioRest\\Controllers\\User:generateToken');
     $app->get('/api/users/me/login_token', 'PleioRest\\Controllers\\User:loginToken');
     $app->get('/api', 'PleioRest\\Controllers\\Version:getVersion');
     $app->get('/api/doc', 'PleioRest\\Controllers\\Documentation:getDocumentation');
     $app->get('/api/doc/swagger', 'PleioRest\\Controllers\\Documentation:getSwagger');
     $app->get('/api/sites', 'PleioRest\\Controllers\\Sites:getAll');
     $app->get('/api/sites/mine', 'PleioRest\\Controllers\\Sites:getMine');
     $app->get('/api/groups', 'PleioRest\\Controllers\\Groups:getAll');
     $app->get('/api/groups/mine', 'PleioRest\\Controllers\\Groups:getMine');
     $app->get('/api/groups/{guid}/activities', 'PleioRest\\Controllers\\Activities:getGroup');
     $app->post('/api/groups/{guid}/activities/mark_read', 'PleioRest\\Controllers\\Activities:markRead');
     $app->get('/api/groups/{guid}/events', 'PleioRest\\Controllers\\Events:getGroup');
     $app->get('/api/groups/{guid}/members', 'PleioRest\\Controllers\\Members:getGroup');
     $app->get('/api/groups/{guid}/files', 'PleioRest\\Controllers\\Files:getGroup');
     $app->run();
 }
예제 #10
0
파일: api.php 프로젝트: braren/AFS
<?php

/**
 * Clase de inicio del proyecto
 * Created by: braren
 * Date: 03/02/16
 * Time: 22:55
 */
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/../src/httpClient.class.php';
$appAPI = new \Slim\App();
date_default_timezone_set('America/Bogota');
$appAPI->get('/actor/{id_actor}', function (Request $request, Response $response) {
    $httpClient = new httpClient();
    $idActor = $request->getAttribute('id_actor');
    $response->getBody()->write($httpClient->getFullActorInfo($idActor));
    $response = $response->withHeader('Content-type', 'application/json');
    return $response;
});
$appAPI->get('/suggestion/{query}', function (Request $request, Response $response) {
    $httpClient = new httpClient();
    $query = $request->getAttribute('query');
    $response->getBody()->write($httpClient->getSuggestions($query));
    $response = $response->withHeader('Content-type', 'application/json');
    return $response;
});
$appAPI->run();