本文整理汇总了PHP中Slim\Slim::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Slim::add方法的具体用法?PHP Slim::add怎么用?PHP Slim::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Slim
的用法示例。
在下文中一共展示了Slim::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getConfig
function __construct()
{
static::$instance = $this;
$env = getConfig('Enviroments/enviroment.config.php');
$config = getConfig("Enviroments/{$env}.config.php");
$config['enviroment'] = $env;
//debug mode
$debug = isset($_GET['debug']) ? 10 : $config['debugMode'];
if ($debug) {
ini_set('display_errors', 1);
error_reporting(E_ALL);
} else {
ini_set('display_errors', 0);
error_reporting(0);
}
//read rewritebase
$htaccess = file_get_contents(BASE_DIR . '/Docroot/.htaccess');
preg_match('@RewriteBase\\s*(.*)$@m', $htaccess, $matches);
$this->rewriteBase = $matches[1];
//create slim instance
\Slim\Slim::registerAutoloader();
$this->slim = new \Slim\Slim(array('cookies.encrypt' => true, 'cookies.lifetime' => 20 * 365 * 24 * 60 . ' minutes', 'cookies.path' => $this->rewriteBase, 'cookies.secure' => false, 'cookies.secret_key' => $config['cryptSecrect']));
//config session
$this->slim->add(new \Slim\Middleware\SessionCookie(array('expires' => 20 * 365 * 24 * 60 . ' minutes', 'path' => $this->rewriteBase, 'domain' => null, 'secure' => false, 'name' => 'slim_session', 'secret' => $config['cryptSecrect'])));
//routing
require_once BASE_DIR . '/routes.php';
$this->appendRoute($routes);
//database
DB::config($config['db']['type'], $config['db']['host'], $config['db']['user'], $config['db']['pass'], $config['db']['name'], $debug);
//run slim application
$this->slim->run();
}
示例2: __construct
private function __construct()
{
// Prepare app
$this->slim = new \Slim\Slim(array('templates.path' => self::$templatePath));
// Prepare view
$this->slim->view(new \Slim\Views\Twig());
$this->slim->view->parserOptions = array('charset' => 'utf-8', 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true);
$this->slim->view->parserExtensions = array(new \Slim\Views\TwigExtension());
if (self::$debug) {
$this->slim->view->parserExtensions[] = new \Twig_Extension_Debug();
}
$this->slim->add(new \Slim\Middleware\SessionCookie());
}
示例3: enable
public function enable(Slim $app)
{
$this->app = $app;
$this->config = $this->app->config('api');
$this->factory = new Factory($this->config['resources']);
// Middleware
$this->app->add(new Database());
$this->app->add(new ApiMiddleware($this->config));
// Routes
$this->app->get($this->config['prefix'] . '/:resource/:id', [$this, 'getAction'])->conditions(['id' => '\\d+'])->name('resource_get');
$this->app->get($this->config['prefix'] . '/:resource', [$this, 'listAction'])->name('resource_get_list');
$this->app->put($this->config['prefix'] . '/:resource/:id', [$this, 'putAction'])->conditions(['id' => '\\d+'])->name('resource_put');
$this->app->post($this->config['prefix'] . '/:resource', [$this, 'postAction'])->name('resource_post');
$this->app->delete($this->config['prefix'] . '/:resource/:id', [$this, 'deleteAction'])->conditions(['id' => '\\d+'])->name('resource_delete');
}
示例4: configure
/**
* Configure the middleware layers for your application
*
* @param Slim $app
*/
public function configure(Slim $app)
{
$this->init($app->container);
/** @var MiddlewareProvider $middleware */
foreach ($this->middleware as $middleware) {
$app->add($middleware);
}
}
示例5: configureApp
protected function configureApp(Slim $app, Container $c)
{
// Add Middleware
$app->add($c['profileMiddleware']);
$app->add($c['navigationMiddleware']);
$app->add($c['authenticationMiddleware']);
$app->add($c['sessionCookieMiddleware']);
// Prepare view
$app->view($c['twig']);
$app->view->parserOptions = $this['config']['twig'];
$app->view->parserExtensions = array($c['slimTwigExtension'], $c['twigExtensionDebug']);
$config = $this['config'];
// Dev mode settings
$app->configureMode('development', function () use($app, $config) {
$app->config(array('log.enabled' => true, 'log.level' => Log::DEBUG));
$config['twig']['debug'] = true;
});
}
示例6: factory
static function factory($filePath)
{
$storage = new YamlStorage($filePath);
$slimApp = new Slim();
$slimApp->add(new ContentTypes());
$slimApp->config('debug', false);
$instance = new static($slimApp, $storage);
$slimApp->error(array($instance, 'error'));
return $instance;
}
示例7: _slimApp
protected function _slimApp()
{
$this['view'] = function () {
// Configure Twig view for slim
$view = new Twig();
$view->parserOptions = array('charset' => 'utf-8', 'cache' => XHGUI_ROOT_DIR . '/cache', 'auto_reload' => true, 'strict_variables' => false, 'autoescape' => true);
return $view;
};
$this['app'] = $this->share(function ($c) {
$app = new Slim($c['config']);
// Enable cookie based sessions
$app->add(new SessionCookie(array('httponly' => true)));
// Add renderer.
$app->add(new Xhgui_Middleware_Render());
$view = $c['view'];
$view->parserExtensions = array(new Xhgui_Twig_Extension($app));
$app->view($view);
return $app;
});
}
示例8: registration
/**
* 渡されたslimインスタンスにルートを登録
* @param \Slim\Slim $app
*/
public static function registration(\Slim\Slim $app)
{
// SlimのCSRF対策プラグインを有効化
$app->add(new \Slim\Extras\Middleware\CsrfGuard());
// トップページ
$app->get('/', '\\Tinitter\\Controller\\TimeLine:show');
// 投稿一覧
$app->get('/page/:page_num', '\\Tinitter\\Controller\\TimeLine:show');
// 新規投稿系、保存
$app->post('/post/commit', '\\Tinitter\\Controller\\Post:commit');
}
示例9: registration
public static function registration(\Slim\Slim $app)
{
// Slim縺ョCSRF蟇セ遲悶��繝ゥ繧ー繧、繝ウ繧呈怏蜉ケ蛹�
$app->add(new \Slim\Extras\Middleware\CsrfGuard());
// 繝医ャ繝励��繝シ繧ク
$app->get('/', '\\Tinitter\\Controller\\TimeLine:show');
// 謚慕ィソ荳�隕ァ
$app->get('/page/:page_num', '\\Tinitter\\Controller\\TimeLine:show');
// 譁ー隕乗兜遞ソ邉サ縲∽ソ晏ュ�
$app->post('/post/commit', '\\Tinitter\\Controller\\Post:commit');
}
示例10: middleware
/**
* Add all middleware
* @param Slim $application
*/
public static function middleware(Slim $application)
{
if (sizeof(Config::get('app.middleware'))) {
foreach (Config::get('app.middleware') as $middleware) {
$middleware = explode('@', $middleware);
$classMiddleware = $middleware[0];
$add = isset($middleware[1]) ? new $classMiddleware(Config::get($middleware[1])) : new $classMiddleware();
$application->add($add);
}
}
}
示例11: getSlimInstance
/**
* @inheritdoc
*/
public function getSlimInstance()
{
$app = new Slim(array('debug' => false));
$app->add(new JsonRequestMiddleware(['json_as_object' => true]));
$app->post('/messages', function () use($app) {
$json = $app->json_body;
if (empty($json)) {
$app->response->setBody('empty json');
} else {
$app->response->setBody('message:' . $json->message);
}
});
$app->error(function (InvalidJsonFormatException $e) use($app) {
$app->response->setBody('error:' . $e->getMessage());
});
return $app;
}
示例12: EventPublisher
/** @test */
function it_should_persist_an_event_published_inside_an_slim_route()
{
/** @var \Hexagonal\Bridges\Doctrine2\DomainEvents\EventStoreRepository $store */
$store = $this->entityManager->getRepository(StoredEvent::class);
$publisher = new EventPublisher();
$middleware = new StoreEventsMiddleware(new PersistEventsSubscriber($store, new StoredEventFactory(new JsonSerializer())), $publisher);
$app = new Slim();
$app->get('/', function () use($publisher) {
$events = new SplObjectStorage();
$events->attach(A::transferWasMadeEvent()->build());
$publisher->publish($events);
});
$app->add($middleware);
Environment::mock(['REQUEST_METHOD' => 'GET']);
$app->run();
$this->assertCount(1, $store->allEvents());
}
示例13: registration
public static function registration(\Slim\Slim $app)
{
$app->add(new \Slim\Extras\Middleware\CsrfGuard());
//top
$app->get('/', '\\Quiz\\Controller\\Top:show');
//question
$app->get('/questions', '\\Quiz\\Controller\\Question:show');
$app->get('/questions/new', '\\Quiz\\Controller\\Question:createShow');
$app->post('/questions/new', '\\Quiz\\Controller\\Question:createQuestion');
$app->get('/questions/update', '\\Quiz\\Controller\\Question:updateShow');
$app->post('/questions/update', '\\Quiz\\Controller\\Question:updateQuestion');
//quiz
$app->get('/quizzes', '\\Quiz\\Controller\\Quiz:show');
$app->get('/quizzes/new', '\\Quiz\\Controller\\Quiz:createShow');
$app->post('/quizzes/new', '\\Quiz\\Controller\\Quiz:createQuiz');
//answer
$app->post('/answer/start', '\\Quiz\\Controller\\Answer:answerStart');
$app->post('/answer/end', '\\Quiz\\Controller\\Answer:answerEnd');
//comment
$app->post('/comment/create', '\\Quiz\\Controller\\Comment:createComment');
}
示例14: Slim
use Slim\Middleware\ContentTypes as ContentTypesMiddleware;
use NwWebsite\Controllers\Auth\Twitter as AuthTwitterController;
use NwWebsite\Controllers\Home as HomeController;
use NwWebsite\Controllers\Auth\Authentifier as AuthentifierController;
use NwWebsite\Controllers\Articles as ArticlesController;
$di = Di::getInstance();
if ($di->env === ENV_DEVELOPMENT) {
$slimMode = 'development';
$debug = true;
} else {
$slimMode = 'production';
$debug = true;
}
$app = new Slim(['mode' => $slimMode, 'debug' => $debug, 'view' => $di->layoutHtml]);
// Allow to decode json request body
$app->add(new ContentTypesMiddleware());
$app->get('/auth/login', function () use($app) {
$app->render('auth/login');
});
$app->get('/auth/twitter/login', function () {
AuthTwitterController::getInstance()->login();
});
$app->get('/auth/twitter/callback', function () {
AuthTwitterController::getInstance()->callback();
});
$app->get('/auth/logout', function () {
AuthentifierController::getInstance()->logout();
});
$app->get('/home', function () {
HomeController::getInstance()->home();
});
示例15: Slim
// Controllers
require_once "app/controller.php";
require_once "app/controllers/login.controller.php";
require_once "app/controllers/ideas.controller.php";
define('APPLICATION', 'Share My Ideas');
define('VERSION', '1.0.0');
define('EXT', '.twig');
use Slim\Slim;
use Slim\Extras\Views\Twig as TwigView;
use Strong\Strong;
use Slim\Extras\Middleware\StrongAuth;
$app = new Slim(array('view' => new TwigView()));
$dsn = sprintf('mysql:host=%s;dbname=%s', $db[$activeGroup]['hostname'], $db[$activeGroup]['database']);
// Authentication
$config = array('provider' => 'PDO', 'pdo' => new PDO($dsn, $db[$activeGroup]['username'], $db[$activeGroup]['password']), 'auth.type' => 'form', 'login.url' => '/login', 'security.urls' => array(array('path' => '/comment/'), array('path' => '/api/.+'), array('path' => '/account/')));
$app->add(new StrongAuth($config, new Strong($config)));
// Asset Management
TwigView::$twigExtensions = array('Twig_Extensions_Slim');
$c = new Application($app);
$loginController = new LoginController();
$ideasController = new IdeasController();
// routes
$c->app->get('/', array($ideasController, 'index'))->name('home');
$c->app->map('/login/', array($loginController, 'index'))->via('GET', 'POST')->name('login');
$c->app->map('/register/', array($loginController, 'signup'))->via('GET', 'POST')->name('signup');
$c->app->map('/account/', array($loginController, 'profile'))->via('GET', 'POST')->name('profile');
$c->app->map('/account/settings/', array($loginController, 'settings'))->via('GET', 'POST')->name('settings');
$c->app->map('/forgot/', array($loginController, 'forgot'))->via('GET', 'POST')->name('forgot_password');
$c->app->get('/logout/', array($loginController, 'logout'))->name('logout');
$c->app->get('/idea(/:id)', array($ideasController, 'idea'))->name('idea');
$c->app->post('/idea/save', array($ideasController, 'save'))->name('idea_save');