当前位置: 首页>>代码示例>>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;未经允许,请勿转载。