本文整理汇总了PHP中Slim\App类的典型用法代码示例。如果您正苦于以下问题:PHP App类的具体用法?PHP App怎么用?PHP App使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了App类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: runApp
/**
* Process the application given a request method and URI
*
* @param string $requestMethod the request method (e.g. GET, POST, etc.)
* @param string $requestUri the request URI
* @param array|object|null $requestData the request data
* @return \Slim\Http\Response
*/
public function runApp($requestMethod, $requestUri, $requestData = null)
{
// Create a mock environment for testing with
$environment = Environment::mock(['REQUEST_METHOD' => $requestMethod, 'REQUEST_URI' => $requestUri]);
// Set up a request object based on the environment
$request = Request::createFromEnvironment($environment);
// Add request data, if it exists
if (isset($requestData)) {
$request = $request->withParsedBody($requestData);
}
// Set up a response object
$response = new Response();
// Use the application settings
$settings = (require __DIR__ . '/../../src/settings.php');
// Instantiate the application
$app = new App($settings);
// Set up dependencies
require __DIR__ . '/../../src/dependencies.php';
// Register middleware
if ($this->withMiddleware) {
require __DIR__ . '/../../src/middleware.php';
}
// Register routes
require __DIR__ . '/../../src/routes.php';
// Process the application
$response = $app->process($request, $response);
// Return the response
return $response;
}
示例2: getSlimRouteFromApplication
/**
* @param SlimApp $slimApp
* @return SlimRoute
*/
private function getSlimRouteFromApplication(SlimApp $slimApp)
{
$slimRouter = $slimApp->getContainer()->get('router');
/** @var $slimRouter SlimRouter */
$slimRoutes = $slimRouter->getRoutes();
return $slimRoutes['route0'];
}
示例3: load
public function load(array $settings = [])
{
$service = new SlimApp($settings);
$provider = new ServiceProvider();
$provider->register($service->getContainer());
$this->setService($service);
}
示例4: hasRoutesConfigured
private function hasRoutesConfigured() : bool
{
$slimContainer = $this->slimApp->getContainer();
$slimRouter = $slimContainer->get('router');
/** @var $slimRouter SlimRouter */
return (bool) count($slimRouter->getRoutes());
}
示例5: __construct
public function __construct(App $app)
{
$app->group('/periodos', function () {
$this->get('/actual', RetriveActualAction::class);
$this->get('/{anio}', RetrivePeriodosDelAnio::class);
});
}
示例6: 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');
}
示例7: initModules
/**
* Load the module. This will run for all modules, use for routes mainly
* @param string $moduleName Module name
*/
public function initModules(App $app)
{
$container = $app->getContainer();
$this->initDependencies($container);
$this->initMiddleware($app);
$this->initRoutes($app);
}
示例8: setUp
public function setUp()
{
$app = new App();
$kernel = new Kernel($app, $app->getContainer());
$kernel->registerServices();
$kernel->registerRoutes();
$this->app = $app;
}
示例9: __construct
function __construct(\Slim\App $app, RequestInterface $request, ResponseInterface $response, $args = false)
{
$this->app = $app;
$this->container = $app->getContainer();
$this->request = $request;
$this->response = $response;
$this->args = $args;
}
示例10: __construct
public function __construct(\Slim\App $app)
{
$this->app = $app;
$this->view = $app->getContainer()->get('view');
$this->pdo = $app->getContainer()->get('pdo');
if (!$this->pdo instanceof PDO) {
throw new \RuntimeException(sprintf('%s requires a PDO instance, app did not contain "PDO" key', __CLASS__));
}
}
示例11: init
public function init(\Slim\App $app)
{
$app->group('/categories', function () {
$this->get('', '\\Controllers\\Categories:index');
$this->map(['GET', 'POST'], '/created', '\\Controllers\\Categories:created');
$this->map(['GET', 'POST'], '/edit/{id}', '\\Controllers\\Categories:edit');
$this->map(['GET', 'POST'], '/delete/{id}', '\\Controllers\\Categories:delete');
});
}
示例12: Route
public static function Route()
{
$app = new App();
// Reminder: the request is processed from the bottom up,
// the response is processed from the top down.
$app->add(SlimMiddleware::class);
$app->add(Grover::class);
$app->run();
}
示例13: runApp
/**
* @param String $method
* @param Uri $uri
* @param array $post
*/
protected function runApp($method, $uri, $post = [])
{
$this->buildApp();
$this->buildRequest($method, $uri, $post);
$this->app->getContainer()['request'] = $this->request;
$this->app->getContainer()['response'] = $this->response;
$this->response = $this->app->run(true);
$this->response->getBody()->rewind();
$this->html = $this->response->getBody()->getContents();
}
示例14: 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');
});
}
示例15: newApp
public function newApp()
{
// config
$debug = false;
if (defined("DEBUG")) {
$debug = true;
}
// Make a Slim App
$app = new App(['settings' => ['debug' => $debug, 'whoops.editor' => 'sublime']]);
$app->add(new WhoopsMiddleware());
$this->app = $app;
}