當前位置: 首頁>>代碼示例>>PHP>>正文


PHP App::add方法代碼示例

本文整理匯總了PHP中Slim\App::add方法的典型用法代碼示例。如果您正苦於以下問題:PHP App::add方法的具體用法?PHP App::add怎麽用?PHP App::add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Slim\App的用法示例。


在下文中一共展示了App::add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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();
 }
開發者ID:PaulJulio,項目名稱:php-slim-echo-grover,代碼行數:9,代碼來源:Router.php

示例2: 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;
 }
開發者ID:SharkIng,項目名稱:ss-panel,代碼行數:12,代碼來源:Slim.php

示例3: 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

示例4: register

 /**
  * Register DebugBar service.
  *
  * @param  App $app
  *
  * @return void
  */
 public function register(App $app)
 {
     $container = $app->getContainer();
     $container['debugbar'] = function ($container) {
         return new SlimDebugBar($container, $this->settings);
     };
     if (!$this->settings['enabled']) {
         return;
     }
     $app->group('/_debugbar', function () {
         $this->get('/open', 'Kitchenu\\Debugbar\\Controllers\\OpenHandlerController:handle')->setName('debugbar-openhandler');
         $this->get('/assets/stylesheets', 'Kitchenu\\Debugbar\\Controllers\\AssetController:css')->setName('debugbar-assets-css');
         $this->get('/assets/javascript', 'Kitchenu\\Debugbar\\Controllers\\AssetController:js')->setName('debugbar-assets-js');
     });
     $app->add(new Debugbar($container['debugbar'], $container['errorHandler']));
 }
開發者ID:kitchenu,項目名稱:slim-debugbar,代碼行數:23,代碼來源:ServiceProvider.php

示例5: 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

示例6: 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

示例7: function

//Add container to handle all exceptions/errors, fail safe and return json
$container['errorHandler'] = function ($container) {
    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
開發者ID:andela-gjames,項目名稱:Emoji-API,代碼行數:31,代碼來源:route.php

示例8: 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

示例9: 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

示例10: setupMiddleware

 /**
  * Set up middleware
  *
  * @param ContainerInterface $container Container to prepare
  * @param SlimApp $app Application object
  * @param mixed $value Value for bootstrap
  */
 private static function setupMiddleware(ContainerInterface $container, SlimApp $app, $value)
 {
     if ($value === null) {
         return;
     }
     $app->add($value);
 }
開發者ID:canis-io,項目名稱:slim-boot,代碼行數:14,代碼來源:ApplicationEngine.php

示例11: Dotenv

<?php

require '../vendor/autoload.php';
use Slim\App;
use Dotenv\Dotenv;
$dotenv = new Dotenv(__DIR__);
$dotenv->load();
//***** REMOVE SETTINGS WHEN NOT DEBUGGING ********************
$container = new \Slim\Container(['settings' => ['displayErrorDetails' => true]]);
$app = new App($container);
require 'dependencies.php';
require 'routes.php';
$app->add($container['logger-middleware']);
$app->run();
開發者ID:ChrisBrenton,項目名稱:recipes,代碼行數:14,代碼來源:start.php

示例12: addMiddleware

 /**
  * Add a middleware to the application.
  * @param mixed $middleware
  */
 public function addMiddleware($middleware)
 {
     $this->app->add($middleware);
 }
開發者ID:tarienna,項目名稱:easy-rest,代碼行數:8,代碼來源:EasyRest.php

示例13: App

<?php

if (PHP_SAPI == 'cli-server') {
    // To help the built-in PHP dev server, check if the request was actually for
    // something which should probably be served as a static file
    $file = __DIR__ . preg_replace('#(\\?.*)$#', '', $_SERVER['REQUEST_URI']);
    if (is_file($file)) {
        return false;
    }
}
require __DIR__ . '/../vendor/autoload.php';
use Slim\App;
use App\Loader\Kernel;
use Slim\Middleware\DebugBar;
use Slim\Routes\DebugBarRoutes;
session_start();
// Instantiate the app
$settings = (require __DIR__ . '/../config/settings.php');
$app = new App($settings);
if ($app->getContainer()->get('settings')['debugbar'] === true) {
    $debugbar = new DebugBar(null, ['logger' => 'logger']);
    $app->add($debugbar);
    $routes = new DebugBarRoutes($app);
    $routes->registerRoutes();
}
$kernel = new Kernel($app, $app->getContainer());
$kernel->registerServices();
$kernel->registerRoutes();
// Run app
$app->run();
開發者ID:raistlfiren,項目名稱:slim-skeleton,代碼行數:30,代碼來源:index.php

示例14: TokenAuthentication

     */
    $token = $tokenAuth->findToken($request);
    /**
     * Call authentication logic class
     */
    $auth = new \app\Auth();
    /**
     * Verify if token is valid on database
     * If token isn't valid, must throw an UnauthorizedExceptionInterface
     */
    $auth->getUserByToken($token);
};
/**
 * Add token authentication middleware
 */
$app->add(new TokenAuthentication(['path' => '/restrict', 'authenticator' => $authenticator]));
/**
 * Public route example
 */
$app->get('/', function ($request, $response) {
    $output = ['msg' => 'It is a public area'];
    $response->withJson($output, 200, JSON_PRETTY_PRINT);
});
/**
 * Restrict route example
 * Our token is "usertokensecret"
 */
$app->get('/restrict', function ($request, $response) {
    $output = ['msg' => 'It\'s a restrict area. Token authentication works!'];
    $response->withJson($output, 200, JSON_PRETTY_PRINT);
});
開發者ID:dyorg,項目名稱:slim-token-authentication,代碼行數:31,代碼來源:index.php

示例15: getenv

require APPLICATION_PATH . "/../vendor/autoload.php";
$dotenv = new Dotenv\Dotenv(APPLICATION_PATH . '/../');
$dotenv->load();
if (!defined('SLIM_MODE')) {
    $mode = getenv('SLIM_MODE') ? getenv('SLIM_MODE') : 'production';
    define('SLIM_MODE', $mode);
}
/**
 * init a session
 */
session_start();
$config = new Config(array(APPLICATION_PATH . '/app/config/global.php', APPLICATION_PATH . '/app/config/' . SLIM_MODE . '.php'));
// Create Slim app
$app = new App(['settings' => $config->all()]);
// middleware setup
$app->add(new TrailingSlash(false));
// true adds the trailing slash (false removes it)
// Fetch DI Container
$container = $app->getContainer();
/*
 * set up Monolog
 */
$log = new Logger('GraphStoryCom');
$log->pushHandler(new ErrorLogHandler(ErrorLogHandler::OPERATING_SYSTEM, $container->get('settings')['monolog.level']));
$container['logger'] = $log;
/**
 * set Twig parser options
 *
 * @param \Interop\Container\ContainerInterface $c
 *
 * @return \Slim\Views\Twig
開發者ID:OSMIHelp,項目名稱:osmihelp.org,代碼行數:31,代碼來源:index.php


注:本文中的Slim\App::add方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。