本文整理汇总了PHP中App::before方法的典型用法代码示例。如果您正苦于以下问题:PHP App::before方法的具体用法?PHP App::before怎么用?PHP App::before使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类App
的用法示例。
在下文中一共展示了App::before方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: routeAllToJsonrpc
public function routeAllToJsonrpc()
{
\App::before(function () {
\Route::post('{all}', function ($path) {
return \App::make('Leeb\\Jsonrpc\\Interfaces\\RouterInterface')->route();
})->where('all', '.*');
});
}
示例2:
<?php
/*
* Register System routes before all user routes.
*/
App::before(function ($request) {
/*
* Combine JavaScript and StyleSheet assets
*/
Route::any('combine/{file}', 'System\\Classes\\Controller@combine');
});
示例3: unset
/*
|--------------------------------------------------------------------------
| Application & Route Filters
|--------------------------------------------------------------------------
|
| Below you will find the "before" and "after" events for the application
| which may be used to do any work before or after a request into your
| application. Here you may also register your custom route filters.
|
*/
App::before(function ($request) {
try {
$user = DB::table('users')->first();
unset($user);
} catch (\PDOException $e) {
if (!in_array($request->path(), array('install', 'install/db', 'install/api', 'install/user', 'install/complete'))) {
return Redirect::to('/install', 302);
}
}
});
App::after(function ($request, $response) {
if (get_class($response) != 'Symfony\\Component\\HttpFoundation\\BinaryFileResponse') {
$response->header('Cache-Control', 'no-cache, must-revalidate');
$response->header('P3P', 'CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
}
});
App::missing(function ($exception) {
Log::error('URL : ' . URL::current());
$error = new Andriynto\Ebri\Controllers\Error();
return $error->_404();
});
示例4: function
<?php
/*
|--------------------------------------------------------------------------
| Application & Route Filters
|--------------------------------------------------------------------------
|
| Below you will find the "before" and "after" events for the application
| which may be used to do any work before or after a request into your
| application. Here you may also register your custom route filters.
|
*/
App::before(function ($request) {
if (Config::get('lanager/config.installed') !== true) {
return 'Run <pre>php artisan lanager:install</pre> from the lanager/ directory before continuing';
}
});
App::after(function ($request, $response) {
//
});
/*
|--------------------------------------------------------------------------
| CSRF Protection Filter
|--------------------------------------------------------------------------
|
| The CSRF filter is responsible for protecting your application against
| cross-site request forgery attacks. If this special token in a user
| session does not match the one given in this request, we'll bail.
|
*/
Route::filter('csrf', function () {
示例5: trans
<?php
App::before(function ($request) {
if (Session::has('client_ip')) {
//check ip_address in blocking table
$blocking = Blocking::where('ip_address', Session::get('client_ip'))->first();
if (!empty($blocking)) {
if ($blocking->should_block_web_access) {
return trans('msgs.you_dont_have_website_access');
}
$path = $request->path();
if ($path == "login" && $blocking->should_block_login) {
return trans('msgs.you_dont_have_login_access');
}
if ($path == "customer/tickets" && $blocking->should_block_tickets) {
return trans('msgs.you_dont_have_tickets_access');
}
}
}
});
Route::filter('has_permission', function ($route, $request, $permission) {
if (Auth::check()) {
if (!\KodeInfo\Utilities\Utils::canViewBackend(Auth::user()->id)) {
Auth::logout();
Session::flush();
Session::flash('error_msg', trans('msgs.access_denied_escalate_rights'));
return Redirect::to('/login');
}
if (!Permissions::hasPermission($permission)) {
$permission_obj = Permissions::where('key', $permission)->pluck('text');
Session::flash('error_msg', trans('msgs.access_denied_escalate_rights', ['permission_obj' => $permission_obj]));
示例6: header
<?php
/*
|--------------------------------------------------------------------------
| Application & Route Filters
|--------------------------------------------------------------------------
|
| Below you will find the "before" and "after" events for the application
| which may be used to do any work before or after a request into your
| application. Here you may also register your custom route filters.
|
*/
App::before(function ($request) {
//
header("Access-Control-Allow-Origin: *");
});
App::after(function ($request, $response) {
});
/*
|--------------------------------------------------------------------------
| Authentication Filters
|--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
|
*/
Route::filter('www', function ($route, $request) {
$host = $request->getHost();
$parts = explode('.', $host);
示例7: function
<?php
/*
|--------------------------------------------------------------------------
| Application & Route Filters
|--------------------------------------------------------------------------
|
| Below you will find the "before" and "after" events for the application
| which may be used to do any work before or after a request into your
| application. Here you may also register your custom route filters.
|
*/
App::before(function ($request) {
View::share('isAjax', Request::Ajax());
});
App::after(function ($request, $response) {
//
});
/*
|--------------------------------------------------------------------------
| Authentication Filters
|--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
|
*/
Route::filter('auth', function () {
if (Auth::guest()) {
if (Request::ajax()) {
示例8: function
<?php
/**
* Register Backend routes before all user routes.
*/
App::before(function ($request) {
/*
* Extensibility
*/
Event::fire('backend.beforeRoute');
/*
* Other pages
*/
Route::group(['prefix' => Config::get('cms.backendUri', 'backend')], function () {
Route::any('{slug}', 'Backend\\Classes\\BackendController@run')->where('slug', '(.*)?');
});
/*
* Entry point
*/
Route::any(Config::get('cms.backendUri', 'backend'), 'Backend\\Classes\\BackendController@run');
/*
* Extensibility
*/
Event::fire('backend.route');
});
示例9: function
/*
|--------------------------------------------------------------------------
| Application & Route Filters
|--------------------------------------------------------------------------
|
| Below you will find the "before" and "after" events for the application
| which may be used to do any work before or after a request into your
| application. Here you may also register your custom route filters.
|
*/
App::before(function () {
if (!Request::is('api/*')) {
session_start();
if (in_array(BaseController::cookieGet('lang'), ['en', 'ru', 'by'])) {
App::setLocale(BaseController::cookieGet('lang'));
}
if (!BaseController::sessionGet('token')) {
BaseController::sessionSet('token', BaseController::randString(6));
}
}
});
App::after(function () {
});
/*
* Registration captcha check
*/
Route::filter('signup', function () {
if (!BaseController::checkCaptcha()) {
return View::make('verif.signup');
}
});
示例10:
|
*/
App::before(function ($request) {
if (Auth::check()) {
$count = Session::get(SESSION_COUNTER, 0);
Session::put(SESSION_COUNTER, ++$count);
}
if (App::environment() == ENV_PRODUCTION) {
if (!Request::secure()) {
return Redirect::secure(Request::getRequestUri());
}
}
if (Input::has('lang')) {
$locale = Input::get('lang');
App::setLocale($locale);
Session::set(SESSION_LOCALE, $locale);
if (Auth::check()) {
if ($language = Language::whereLocale($locale)->first()) {
$account = Auth::user()->account;
$account->language_id = $language->id;
$account->save();
}
}
} else {
if (Auth::check()) {
$locale = Session::get(SESSION_LOCALE, DEFAULT_LOCALE);
App::setLocale($locale);
}
}
});
App::after(function ($request, $response) {
//
示例11: function
<?php
/*
|--------------------------------------------------------------------------
| Application & Route Filters
|--------------------------------------------------------------------------
|
| Below you will find the "before" and "after" events for the application
| which may be used to do any work before or after a request into your
| application. Here you may also register your custom route filters.
|
*/
App::before(function ($request) {
//SiteHelpers::globalXssClean();
});
App::after(function ($request, $response) {
//
});
/*
|--------------------------------------------------------------------------
| Authentication Filters
|--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
|
*/
Route::filter('auth', function () {
if (Auth::guest()) {
return Redirect::guest('user/login');
示例12: setlocale
/*
|--------------------------------------------------------------------------
| Application & Route Filters
|--------------------------------------------------------------------------
|
| Below you will find the "before" and "after" events for the application
| which may be used to do any work before or after a request into your
| application. Here you may also register your custom route filters.
|
*/
App::before(function ($request) {
// Get default PHP locale
$phpLocale = Config::get('app.phplocale');
// Check for session override
if (Session::has('lang')) {
App::setLocale(Session::get('lang'));
$phpLocale = Session::get('locale');
}
setlocale(LC_TIME, $phpLocale);
});
App::after(function ($request, $response) {
//
});
/*
|--------------------------------------------------------------------------
| Authentication Filters
|--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
示例13: function
<?php
/*
|--------------------------------------------------------------------------
| Application & Route Filters
|--------------------------------------------------------------------------
|
| Below you will find the "before" and "after" events for the application
| which may be used to do any work before or after a request into your
| application. Here you may also register your custom route filters.
|
*/
App::before(function ($request) {
date_default_timezone_set('PRC');
});
App::after(function ($request, $response) {
//
});
/*
|--------------------------------------------------------------------------
| Authentication Filters
|--------------------------------------------------------------------------
|
| The following filters are used to verify that the user of the current
| session is logged into this application. The "basic" filter easily
| integrates HTTP Basic authentication for quick, simple checking.
|
*/
Route::filter('auth', function () {
if (Auth::guest()) {
if (Request::ajax()) {
示例14: function
| Language
|--------------------------------------------------------------------------
|
| Detect the browser language.
|
*/
Route::filter('detectLang', function ($route, $request, $lang = 'auto') {
if ($lang != "auto" && in_array($lang, Config::get('app.available_language'))) {
Config::set('app.locale', $lang);
} else {
$browser_lang = !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? strtok(strip_tags($_SERVER['HTTP_ACCEPT_LANGUAGE']), ',') : '';
$browser_lang = substr($browser_lang, 0, 2);
$userLang = in_array($browser_lang, Config::get('app.available_language')) ? $browser_lang : Config::get('app.locale');
Config::set('app.locale', $userLang);
App::setLocale($userLang);
}
});
/**
* Enforce https.
*/
App::before(function ($request) {
$settings = Config::get('app');
if ($settings['app_environment'] == 'production') {
if (!Request::secure()) {
return Redirect::secure(Request::path());
}
}
});
App::error(function (\Illuminate\Session\TokenMismatchException $exception) {
return Redirect::route('login')->with('message', 'Your session has expired. Please try logging in again.');
});
示例15: array
App::before(function ($request) {
Commoner::observe();
//change the hash so no malware uses it
Config::set('cms.installation_hash', '');
$addonsNotInstalled = $addonsInstalled = $themesNotInstalled = $themesInstalled = array();
$addons = Addons::all();
$themes = Themes::all();
foreach ($addons as $addon) {
if ($addon->installed == 1) {
ClassLoader::addDirectories(array(public_path() . "/addons/{$addon->addon_name}/controllers", public_path() . "/addons/{$addon->addon_name}/models", public_path() . "/addons/{$addon->addon_name}/helpers"));
}
}
foreach ($themes as $theme) {
if ($theme->installed == 1) {
$themesInstalled[] = $theme->theme_name;
if ($theme->active == 1) {
Config::set('cms.theme', $theme->theme_name);
//include the functions file
include_once public_path() . "/layouts/frontend/{$theme->theme_name}/func.php";
}
} else {
$themesNotInstalled[] = $theme->theme_name;
}
}
$settings = Settings::whereRaw("autoload=1")->get();
$auto_settings = array();
foreach ($settings as $setting) {
$auto_settings[$setting->area][$setting->section][$setting->setting_name] = $setting->setting_value;
}
Config::set("cms.auto_settings", $auto_settings);
Config::set("cms.themes.data", $themes);
Config::set("cms.themes.installed", $themesInstalled);
Config::set("cms.themes.not_installed", $themesNotInstalled);
foreach ($addons as $addon) {
if ($addon->installed == 1) {
$addonsInstalled[] = $addon->addon_name;
if (file_exists(public_path() . "/addons/{$addon->addon_name}/routes.php")) {
require public_path() . "/addons/{$addon->addon_name}/routes.php";
}
if (file_exists(public_path() . "/addons/{$addon->addon_name}/func.php")) {
require public_path() . "/addons/{$addon->addon_name}/func.php";
}
$namespace = $addon->addon_name;
$path = public_path() . "/addons/{$addon->addon_name}/lang";
Lang::addNamespace($namespace, $path);
} else {
$addonsNotInstalled[] = $addon->addon_name;
}
}
Config::set("cms.addons.data", $addons);
Config::set("cms.addons.installed", $addonsInstalled);
Config::set("cms.addons.not_installed", $addonsNotInstalled);
if (Session::has('currlang')) {
Config::set('cms.currlang', Session::get('currlang'));
} else {
$lang = Languages::where("code", "=", Config::get('cms.currlang'))->first();
Config::set('cms.currlang', array('code' => $lang->code, 'title' => $lang->title, 'image' => $lang->image));
}
});