本文整理汇总了PHP中Slim\App::get方法的典型用法代码示例。如果您正苦于以下问题:PHP App::get方法的具体用法?PHP App::get怎么用?PHP App::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\App
的用法示例。
在下文中一共展示了App::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUpRoutes
public function setUpRoutes()
{
$this->app->get('/', function (Request $request, Response $response, array $args) {
$response->getBody()->write(file_get_contents(AppConfig::getPathToPublic() . '/app.html'));
});
$this->app->any('/api/users/[{id}]', Controller\UsersController::class);
$this->app->any('/api/sessions/[{api_key}]', Controller\SessionsController::class);
$this->app->any('/api/trips/[{id}]', Controller\TripsController::class);
$this->app->any('/api/trips/user/[{user_id}]', Controller\TripsController::class);
}
示例2: __construct
public function __construct(App $app)
{
$app->group('/empleados/{e_id}/solicitudes_pqr', function () {
$this->get('', RetriveLastSolicitudPQRAction::class);
$this->post('', CreateNewSolicitudPQRAction::class);
$this->delete('/{pqr_id}', DeleteSolicitudPQRAction::class);
$this->post('/{pqr_id}/respuesta', ResponderSolicitudPQRAction::class);
});
$app->get('/solicitudes_pqr', RetriveSolicitudesPQRAction::class);
$app->get('/solicitudes_pqr/{pqr_id}', RetriveOneSolicitudPQRAction::class);
}
示例3: register
public static function register(App $app, $config)
{
$app->getContainer()['imagecache'] = function () use($config) {
return new Manager($config);
};
$app->get("/{$config['path_web']}/{$config['path_cache']}/{preset}/{file:.*}", (new ImagecacheRegister())->request())->setName('onigoetz.imagecache');
}
示例4: register
public function register(App &$app)
{
$app->get('/version', function (Request $request, Response $response) {
$response->getBody()->write(json_encode("v1.0.0"));
return $response->withHeader('Access-Control-Allow-Origin', '*');
});
$app->options('/version', function (Request $request, Response $response, $args) use(&$self) {
return $response->withHeader('Access-Control-Allow-Origin', '*')->withHeader('Access-Control-Allow-Headers', 'Content-Type');
});
}
示例5: dispatchApplication
protected function dispatchApplication(array $server, array $pipe = [])
{
$app = new App();
$app->getContainer()['environment'] = function () use($server) {
return new Environment($server);
};
$middlewareFactory = new PhpDebugBarMiddlewareFactory();
$middleware = $middlewareFactory();
$app->add($middleware);
foreach ($pipe as $pattern => $middleware) {
$app->get($pattern, $middleware);
}
return $app->run(true);
}
示例6: setRoute
/**
* @param string $method
* @param string $route
* @param object $routerClass
* @param string $callback
* @param Secured $secured
* @throws \Exception
*/
private function setRoute($method, $route, $routerClass, $callback, $secured)
{
$method = strtoupper($method);
$easyRoute = new Route($route, $routerClass, $callback, $secured, $this);
if ($method === 'GET') {
$this->app->get($route, array($easyRoute, 'call'));
} elseif ($method === 'PUT') {
$this->app->put($route, array($easyRoute, 'call'));
} elseif ($method === 'POST') {
$this->app->post($route, array($easyRoute, 'call'));
} elseif ($method === 'DELETE') {
$this->app->delete($route, array($easyRoute, 'call'));
} else {
throw new \Exception('Unsupported HTTP method ' . $method);
}
}
示例7: testMiddlewareIsWorkingAndEditorIsSet
public function testMiddlewareIsWorkingAndEditorIsSet()
{
$app = new App(['settings' => ['debug' => true, 'whoops.editor' => 'sublime']]);
$container = $app->getContainer();
$container['environment'] = function () {
return Environment::mock(['SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => '/foo', 'REQUEST_METHOD' => 'GET']);
};
$app->get('/foo', function ($req, $res, $args) {
return $res;
});
$app->add(new WhoopsMiddleware());
// Invoke app
$response = $app->run();
// Get added whoops handlers
$handlers = $container['whoops']->getHandlers();
$this->assertEquals(2, count($handlers));
$this->assertEquals('subl://open?url=file://test_path&line=169', $handlers[0]->getEditorHref('test_path', 169));
}
示例8: run
/**
*
* @param App $slim
*/
public function run(App $slim)
{
if (!isset($_SERVER['PHP_AUTH_USER'])) {
$this->response_401();
} else {
if ($_SERVER['PHP_AUTH_USER'] == $this->user && sha1($_SERVER['PHP_AUTH_PW']) == $this->pass) {
// Start session just in case
if (!isset($_SESSION)) {
session_start();
}
$token = $this->TokenGenerator->Generate(session_id());
$validation = $this->TokenHandler->GetToken($token, $_SERVER['REMOTE_ADDR']);
if ($validation == false) {
if ($this->whitelistRetriever->check_whitelist($_SERVER['REMOTE_ADDR'])) {
$validation = $this->TokenHandler->SaveCurrentToken($token, $_SERVER['REMOTE_ADDR'], date('Y-m-d H:i'));
} else {
$this->response_401();
}
}
if (!$this->whitelistRetriever->check_whitelist($_SERVER['REMOTE_ADDR'])) {
$this->response_401();
}
$slim->add(function (Request $request, Response $response, $next) use($token) {
if (!$this->whitelistRetriever->check_whitelist($_SERVER['REMOTE_ADDR'])) {
$this->response_401();
}
// TODO: find a way to give a token.
});
// TODO: add around every request and check if the tokens match
$slim->get('/security', function () use($token) {
header("Security token: " . $token);
echo $token;
return;
});
return;
} else {
$this->response_401();
}
}
}
示例9: createRoutes
/**
* Add the controller's routes and relative methods.
* Request and response are PSR-7 compliant
* @param App $application the Slim application to be configured
* @return null
*/
public static function createRoutes(App $application)
{
// Note: in the SlimFramework's routing function closures, $this equals to the App's Container.
$base = static::$baseUri;
// Routes that need the user to be admin
if (Utils::isAdmin()) {
// Product creation (view)
$application->map(['GET', 'POST'], "{$base}/create[/]", function (Request $request, Response $response) {
return (new self($this))->handleCreate($request, $response);
})->setName('productCreate');
// Products list (view)
$application->get("{$base}/list[/]", function (Request $request, Response $response) {
return (new self($this))->handleReadList($request, $response);
})->setName('productList');
// Product edit (view)
$application->map(['GET', 'POST'], "{$base}/{product}/edit[/]", function (Request $request, Response $response, $args) {
return (new self($this))->handleEdit($request, $response, intval($args['product']));
})->setName('productEdit');
}
// Routes that can be seen by anyone
// ...
}
示例10: function
return function ($request, $response, $exception) use($container) {
//Format of exception to return
$data = ['message' => $exception->getMessage()];
return $container->get('response')->withStatus(500)->withHeader('Content-Type', 'application/json')->write(json_encode($data));
};
};
//Register authentication container Dependency
$container['auth'] = function ($container) {
return new BB8\Emoji\Auth($container);
};
//Initialize the slim app
$app = new App($container);
//Add middleware at app level
$app->add('BB8\\Emoji\\Middleware:init');
//Index page
$app->get('/', 'BB8\\Emoji\\Controllers\\UserController:index');
//Create new user
$app->post('/signup', 'BB8\\Emoji\\Controllers\\UserController:create');
//Login Route
$app->post('/auth/login', 'BB8\\Emoji\\Controllers\\UserController:login');
//Logout Route
$app->get('/auth/logout', 'BB8\\Emoji\\Controllers\\UserController:logout')->add('BB8\\Emoji\\Middleware:authorize');
//List all emojis Route
$app->get('/emojis', 'BB8\\Emoji\\Controllers\\EmojiController:index');
//Gets an emoji
$app->get('/emojis/{id}', 'BB8\\Emoji\\Controllers\\EmojiController:show');
//Adds a new Emoji
$app->post('/emojis', 'BB8\\Emoji\\Controllers\\EmojiController:create')->add('BB8\\Emoji\\Middleware:authorize');
//Updates an Emoji
$app->put('/emojis/{id}', 'BB8\\Emoji\\Controllers\\EmojiController:update')->add('BB8\\Emoji\\Middleware:authorize');
//Updates an Emoji Keyword
示例11: Container
<?php
require_once __DIR__ . "/../vendor/autoload.php";
use Slim\App;
use Slim\Container;
use Slim\Views\TwigExtension;
$configuration = ['settings' => ['displayErrorDetails' => true]];
$container = new Container($configuration);
// Register component on container
$container['view'] = function ($c) {
$view = new \Slim\Views\Twig(__DIR__ . '/../src/Application/Templating', ['cache' => __DIR__ . '/../cache']);
$view->addExtension(new TwigExtension($c['router'], $c['request']->getUri()));
return $view;
};
$container['debug'] = true;
// Create app
$app = new App($container);
// Render Twig template in route
$app->get('/', function ($request, $response, $args) {
return $this->view->render($response, 'home/index.html.twig');
})->setName('profile');
// Run app
$app->run();
示例12: testExceptionErrorHandlerDisplaysErrorDetails
/**
* @runInSeparateProcess
*/
public function testExceptionErrorHandlerDisplaysErrorDetails()
{
$app = new App(['settings' => ['displayErrorDetails' => true]]);
// Prepare request and response objects
$env = Environment::mock(['SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => '/foo', 'REQUEST_METHOD' => 'GET']);
$uri = Uri::createFromEnvironment($env);
$headers = Headers::createFromEnvironment($env);
$cookies = [];
$serverParams = $env->all();
$body = new Body(fopen('php://temp', 'r+'));
$req = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
$res = new Response();
$app->getContainer()['request'] = $req;
$app->getContainer()['response'] = $res;
$mw = function ($req, $res, $next) {
throw new \Exception('middleware exception');
};
$app->add($mw);
$app->get('/foo', function ($req, $res) {
return $res;
});
$resOut = $app->run();
$this->assertEquals(500, $resOut->getStatusCode());
$this->expectOutputRegex('/.*middleware exception.*/');
}
示例13: App
<?php
use Slim\App;
use Slim\Views\Twig;
require '../vendor/autoload.php';
$app = new App();
$view = new Twig('../resources/views');
$env = $view->getEnvironment();
$env->addGlobal('year', date('Y'));
$container = $app->getContainer();
$container->register($view);
// Routes
$app->get('/', function ($request, $response, $args) {
return $this->view->render($response, 'index.html.twig', ['page_title' => 'Project Mercury']);
})->setName('index');
$app->run();
示例14: function
return $view;
};
// Register provider
$container['flash'] = function () {
return new \Slim\Flash\Messages();
};
$container['pdo'] = function ($c) {
$pdo = new ExtendedPdo($c->get('settings')['db']['connection'], $c->get('settings')['db']['username'], $c->get('settings')['db']['password']);
return $pdo;
};
$app->get('/', function (\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) {
$getParams = $request->getQueryParams();
/** @var ExtendedPdo $pdo */
$pdo = $this->get('pdo');
$stm = "SELECT * FROM indiegogo WHERE Email = :email";
$bind = ['email' => $getParams['email']];
$sth = $pdo->perform($stm, $bind);
$result = $sth->fetch(PDO::FETCH_ASSOC);
/** @var \Slim\Flash\Messages $flash */
$flash = $this->get('flash');
$this->view->render($response, 'pages/osmirewards2016/index.twig', $getParams + ['result' => $result, 'formAction' => $this->router->pathFor('postForm'), 'flash' => $flash->getMessages()]);
})->setName('getForm');
$app->post('/', function (\Slim\Http\Request $request, \Slim\Http\Response $response, array $args) {
$postParams = $request->getParsedBody();
/** @var \Slim\Flash\Messages $flash */
$flash = $this->get('flash');
try {
\Assert\lazy()->that($postParams['email'], 'email')->notEmpty('Email must be provided')->email('Email must be valid')->verifyNow();
} catch (Assert\LazyAssertionException $e) {
$flash->addMessage('error', $e->getMessage());
return $response->withStatus(302)->withHeader('Location', $this->router->pathFor('getForm') . '?' . http_build_query(['email' => $postParams['email']]));
}
示例15: dirname
<?php
require_once dirname(dirname(__FILE__)) . '/vendor/autoload.php';
use Slim\App;
use Zeuxisoo\Whoops\Provider\Slim\WhoopsMiddleware;
$app = new App(['settings' => ['debug' => true, 'whoops.editor' => 'sublime']]);
$app->add(new WhoopsMiddleware());
// Throw exception, Named route does not exist for name: hello
$app->get('/', function ($request, $response, $args) {
return $this->router->pathFor('hello');
});
// $app->get('/hello', function($request, $response, $args) {
// $response->write("Hello Slim");
// return $response;
// })->setName('hello');
$app->run();