当前位置: 首页>>代码示例>>PHP>>正文


PHP App::get方法代码示例

本文整理汇总了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);
 }
开发者ID:JohnUiterwyk,项目名称:journey-planner,代码行数:10,代码来源:JourneyPlanner.php

示例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);
 }
开发者ID:lacteosdelcesar,项目名称:s3-untitledApi-K,代码行数:11,代码来源:Routes.php

示例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');
 }
开发者ID:onigoetz,项目名称:imagecache,代码行数:7,代码来源:ImagecacheRegister.php

示例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');
     });
 }
开发者ID:mroswald,项目名称:invme,代码行数:10,代码来源:Version.php

示例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);
 }
开发者ID:php-middleware,项目名称:phpdebugbar,代码行数:14,代码来源:Slim3Test.php

示例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);
     }
 }
开发者ID:tarienna,项目名称:easy-rest,代码行数:24,代码来源:EasyRest.php

示例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));
 }
开发者ID:BenHicksy,项目名称:dietddocs,代码行数:18,代码来源:SlimWhoopsTest.php

示例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();
         }
     }
 }
开发者ID:bobvdvalk,项目名称:scaling-happiness,代码行数:44,代码来源:Security.php

示例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
     // ...
 }
开发者ID:elegos,项目名称:PHPTest,代码行数:28,代码来源:ProductController.php

示例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
开发者ID:andela-gjames,项目名称:Emoji-API,代码行数:31,代码来源:route.php

示例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();
开发者ID:jlaso,项目名称:notify,代码行数:23,代码来源:index.php

示例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.*/');
 }
开发者ID:hidayat365,项目名称:phpindonesia.or.id-membership2,代码行数:28,代码来源:AppTest.php

示例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();
开发者ID:randerson12,项目名称:mercury,代码行数:16,代码来源:index.php

示例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']]));
    }
开发者ID:OSMIHelp,项目名称:osmihelp.org,代码行数:32,代码来源:index.php

示例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();
开发者ID:MichaelLeah,项目名称:GalacticBank,代码行数:16,代码来源:index.php


注:本文中的Slim\App::get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。