本文整理汇总了PHP中Response::make方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::make方法的具体用法?PHP Response::make怎么用?PHP Response::make使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response::make方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* @return \Illuminate\Http\Response
*/
public function index()
{
// Use content negotiation to determine the correct format to return
$negotiator = new \Negotiation\FormatNegotiator();
$acceptHeader = Request::header('accept');
// Set priorities to json (if the app requests json provide it in favor of html)
$priorities = array('application/json', 'text/html', '*/*');
// Get the best appropriate content type
$result = $negotiator->getBest($acceptHeader, $priorities);
// Default to html if $result is not set
$val = "text/html";
if (isset($result)) {
$val = $result->getValue();
}
// See what kind of content we should return
switch ($val) {
case "text/html":
// In case we want to return html, just let
// Laravel render the view and send the headers
return Response::view('route.planner')->header('Content-Type', "text/html")->header('Vary', 'accept');
break;
case "application/json":
default:
// In case we want to return JSON(LD) or something else, generate
// our JSON by calling our static function 'getJSON()'
return Response::make($this::getJSON())->header('Content-Type', "application/json")->header('Vary', 'accept');
break;
}
}
示例2: update
public function update(Request $request, $id)
{
try {
$params = $request->all();
$reportId = $id;
$report = CrimeReportsModel::find($id);
if (isset($params['delete_flag'])) {
$report->delete_flag = 'y';
$report->save();
return response()->json(['message' => 'deleted'], 200);
} else {
$newStatus = '';
switch ($params['status']) {
case 'o':
$newStatus = 'p';
break;
case 'p':
$newStatus = 'r';
break;
case 'r':
$newStatus = 'r';
break;
default:
$newStatus = 'd';
break;
}
$report->status = $newStatus;
$report->save();
return response()->json(['message' => 'success'], 200);
}
} catch (ModelNotFoundException $e) {
return Response::make('Not Found', 404);
}
}
示例3: getExport
public function getExport($statistic)
{
$title = $statistic->name;
$type = \Input::get('type');
$arrColumnName = $statistic->getColumnNameArray();
$table = $statistic->getResult();
switch ($type) {
case 'csv':
$output = '';
$output .= implode(",", $arrColumnName) . "\r\n";
foreach ($table as $row) {
$output .= implode(",", $row) . "\r\n";
}
$headers = array('Content-Type' => 'text/csv', 'Content-Disposition' => 'attachment; filename="' . $statistic->name . '_' . date('Y_m_d_His') . '.csv"');
return \Response::make(rtrim($output, "\r\n"), 200, $headers);
case 'excel':
$output = '<table><thead><tr>';
foreach ($arrColumnName as $columnName) {
$output = $output . '<th>' . $columnName . '</th>';
}
$output = $output . '</tr></thead><tbody>';
foreach ($table as $result) {
$output = $output . '<tr>';
foreach ($result as $res) {
$output = $output . '<td>' . $res . '</td>';
}
$output = $output . '</tr>';
}
$output = $output . '<tfoot><tr><td colspan="' . count($arrColumnName) . '">' . $statistic->name . '</td></tr></tfoot></table>';
$headers = array('Pragma' => 'public', 'Expires' => 'public', 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Cache-Control' => 'private', 'Content-Type' => 'application/vnd.ms-excel', 'Content-Disposition' => 'attachment; filename=' . $statistic->name . '_' . date('Y_m_d_His') . '.xls', 'Content-Transfer-Encoding' => ' binary');
return \Response::make($output, 200, $headers);
}
return \View::make(\Config::get('app.admin_template') . '/statistics/result', compact('title', 'statistic'));
}
示例4: getJavascript
public function getJavascript()
{
$contents = View::make('translations');
$response = Response::make($contents);
$response->header('Content-Type', 'application/javascript');
return $response;
}
示例5: create
public function create($type = 'csv')
{
try {
$export = static::getExportForType($type);
} catch (Exception $e) {
App::abort(404);
}
$export->user_id = Auth::user()->id;
$export->filename = $export->generateFilename();
$export->path = $export->folderPath();
$export->setLogbooks(Input::get('logbooks'));
$save = Input::has('save') ? (bool) Input::get('save') : true;
if ($export->run($save)) {
if ($save == false) {
$res = Response::make($export->content);
$res->header('Content-type', $export->getContentType());
return $res;
} else {
$export->save();
return Response::download($export->fullPath(), $export->filename, ['Content-type' => $export->getContentType()]);
}
} else {
return Redirect::to(action('ExportsController@index'))->with('message', ['content' => 'Er is iets mis gegaan met exporteren.', 'class' => 'danger']);
}
}
示例6: index
/**
* Gets an array of statements.
* https://github.com/adlnet/xAPI-Spec/blob/master/xAPI.md#723-getstatements
* @param [String => mixed] $options
* @return Response
*/
public function index($options)
{
// Gets the acceptable languages.
$langs = LockerRequest::header('Accept-Language', []);
$langs = is_array($langs) ? $langs : explode(',', $langs);
$langs = array_map(function ($lang) {
return explode(';', $lang)[0];
}, $langs);
// Gets the params.
$params = LockerRequest::all();
if (isset($params['agent'])) {
$decoded_agent = json_decode($params['agent']);
if ($decoded_agent !== null) {
$params['agent'] = $decoded_agent;
}
}
// Gets an index of the statements with the given options.
list($statements, $count, $opts) = $this->statements->index(array_merge(['langs' => $langs], $params, $options));
// Defines the content type and body of the response.
if ($opts['attachments'] === true) {
$content_type = 'multipart/mixed; boundary=' . static::BOUNDARY;
$body = $this->makeAttachmentsResult($statements, $count, $opts);
} else {
$content_type = 'application/json;';
$body = $this->makeStatementsResult($statements, $count, $opts);
}
// Creates the response.
return \Response::make($body, 200, ['Content-Type' => $content_type, 'X-Experience-API-Consistent-Through' => Helpers::getCurrentDate()]);
}
示例7: subscribe
public function subscribe()
{
$rules = ['email' => 'required|email'];
$validator = Validator::make(Input::all(), $rules);
$contents = json_encode(['message' => 'Your subscription was unsuccessful.']);
$failure = Response::make($contents, 200);
$failure->header('Content-Type', 'text/json');
if ($validator->fails()) {
return $failure;
}
$subscription = new Subscription();
$subscription->email = Input::get('email');
$subscription->active = 1;
$subscription->save();
$email = Input::get('email');
$subject = "Subscribe {$email} to Newsletter";
#Shoot email to subscription service
Mail::send('emails.subscription', array('email' => $email), function ($message) use($subject) {
$message->to('newsletter@chenenetworks.com')->subject($subject);
});
$contents = json_encode(['message' => 'Your subscription was successful.']);
$success = Response::make($contents, 200);
$success->header('Content-Type', 'text/json');
return $success;
}
示例8: view
/**
* Emulate a call to index.php?p=$vanilla_module_path
* Much of this ripped out of Vanilla's index.php
*/
public function view($segments)
{
// if a static asset, return it outright
$asset = $this->is_static_asset($segments);
if ($asset) {
return \Response::make(\File::get($asset))->header('Content-Type', $this->get_content_type($asset));
}
// otherwise, dispatch into vanilla
$user = $this->user;
$bootstrap = new VanillaBootstrap();
$bootstrap->call(function () use($user, $segments) {
// Create the session and stuff the user in
\Gdn::Authenticator()->SetIdentity($user->getKey(), false);
\Gdn::Session()->Start(false, false);
\Gdn::Session()->SetPreference('Authenticator', 'Gdn_Authenticator');
// Create and configure the dispatcher.
$Dispatcher = \Gdn::Dispatcher();
$EnabledApplications = \Gdn::ApplicationManager()->EnabledApplicationFolders();
$Dispatcher->EnabledApplicationFolders($EnabledApplications);
$Dispatcher->PassProperty('EnabledApplications', $EnabledApplications);
// Process the request.
$Dispatcher->Start();
$Dispatcher->Dispatch(implode('/', $segments));
});
}
示例9: receive
public function receive()
{
$request = \Request::instance();
if (!$this->goCardless->validateWebhook($request->getContent())) {
return \Response::make('', 403);
}
$parser = new \BB\Services\Payment\GoCardlessWebhookParser();
$parser->parseResponse($request->getContent());
switch ($parser->getResourceType()) {
case 'bill':
switch ($parser->getAction()) {
case 'created':
$this->processNewBills($parser->getBills());
break;
case 'paid':
$this->processPaidBills($parser->getBills());
break;
default:
$this->processBills($parser->getAction(), $parser->getBills());
}
break;
case 'pre_authorization':
$this->processPreAuths($parser->getAction(), $parser->getPreAuthList());
break;
case 'subscription':
$this->processSubscriptions($parser->getSubscriptions());
break;
}
return \Response::make('Success', 200);
}
示例10: register
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
// Add the namespace to config
$this->app['config']->package('onigoetz/imagecache', __DIR__ . '/../../config');
$config = $this->app['config']->get('imagecache::imagecache');
//TODO :: externalize that
$toolkit = 'gd';
// Stopwatch - must be registered so the application doesn't fail if the profiler is disabled
$this->app['imagecache'] = $this->app->share(function () use($config, $toolkit) {
return new Manager($config, $toolkit);
});
//PHP 5.3 compatibility
$app = $this->app;
$url = "{$config['path_images']}/{$config['path_cache']}/{preset}/{file}";
$this->app['router']->get($url, function ($preset, $file) use($app) {
try {
$final_file = $app['imagecache']->handleRequest($preset, $file);
} catch (InvalidPresetException $e) {
return \Response::make('Invalid preset', 404);
} catch (NotFoundException $e) {
return \Response::make('File not found', 404);
}
if (!$final_file) {
return \Response::make('Dunno what happened', 500);
}
//TODO :: be more "symfony reponse" friendly
$transfer = new Transfer();
$transfer->transfer($final_file);
exit;
})->where('file', '.*');
}
示例11: boot
/**
* Bootstrap the application events.
*
* @return void
*/
public function boot()
{
$app = $this->app;
$app['config']->package('barryvdh/laravel-debugbar', $this->guessPackagePath() . '/config');
if (!$this->shouldUseMiddleware()) {
$app->after(function ($request, $response) use($app) {
$debugbar = $app['debugbar'];
$debugbar->modifyResponse($request, $response);
});
}
$this->app['router']->get('_debugbar/open', array('as' => 'debugbar.openhandler', function () use($app) {
$debugbar = $app['debugbar'];
if (!$debugbar->isEnabled()) {
$app->abort('500', 'Debugbar is not enabled');
}
$openHandler = new \DebugBar\OpenHandler($debugbar);
$data = $openHandler->handle(null, false, false);
return \Response::make($data, 200, array('Content-Type' => 'application/json'));
}));
if ($this->app['config']->get('laravel-debugbar::config.enabled')) {
/** @var LaravelDebugbar $debugbar */
$debugbar = $this->app['debugbar'];
$debugbar->boot();
}
}
示例12: image
public function image()
{
$key = strip_tags(\Route::input('key'));
$key = str_replace('.png', '', $key);
if (empty($key)) {
return redirect('/');
} else {
$result = \DB::table('post')->where('post_key', $key)->first();
if ($result->post_type == 3) {
$text = $result->post_message;
$text = $this->handleText($text);
$image = $this->warpTextImage($text);
ob_start();
imagepng($image, null, 9, null);
$image = ob_get_contents();
ob_end_clean();
@imagedestroy($image);
$response = \Response::make($image);
$response->header('Content-Type', 'image/png');
return $response;
} else {
return redirect('/');
}
}
}
示例13: handle
public function handle($request, \Closure $next)
{
$auth0 = \App::make('auth0');
// Get the encrypted user JWT
$authorizationHeader = $request->header("Authorization");
$encUser = str_replace('Bearer ', '', $authorizationHeader);
if (trim($encUser) == '') {
return \Response::make("Unauthorized user", 401);
}
try {
$jwtUser = $auth0->decodeJWT($encUser);
} catch (CoreException $e) {
return \Response::make("Unauthorized user", 401);
} catch (Exception $e) {
echo $e;
exit;
}
// if it does not represent a valid user, return a HTTP 401
$user = $this->userRepository->getUserByDecodedJWT($jwtUser);
if (!$user) {
return \Response::make("Unauthorized user", 401);
}
// lets log the user in so it is accessible
\Auth::login($user);
// continue the execution
return $next($request);
}
示例14: metadata
/**
* Generate local sp metadata.
*
* @return \Illuminate\Http\Response
*/
public function metadata()
{
$metadata = $this->saml2Auth->getMetadata();
$response = Response::make($metadata, 200);
$response->header('Content-Type', 'text/xml');
return $response;
}
示例15: image
public function image()
{
if (!Auth::check()) {
Session::flash('redirect', URL::current());
return Redirect::route('login');
}
$relativePath = Input::get('path');
$filePath = Input::get('file');
$path = Path::fromRelative($relativePath);
if (!$path->exists()) {
App::abort(404, 'Archive not found');
}
$archive = Archive\Factory::open($path);
$imageStream = $archive->getEntryStream($filePath);
$imageData = stream_get_contents($imageStream);
$response = Response::make($imageData);
$ext = pathinfo($filePath, PATHINFO_EXTENSION);
switch ($ext) {
case 'jpg':
case 'jpeg':
$response->header('Content-Type', 'image/jpeg');
break;
case 'png':
$response->header('Content-Type', 'image/png');
break;
}
$response->header('Last-Modified', gmdate('D, d M Y H:i:s', $path->getMTime()) . ' GMT');
$response->header('Expires', gmdate('D, d M Y H:i:s', strtotime('+1 year')) . ' GMT');
$response->header('Cache-Control', 'public');
return $response;
}