当前位置: 首页>>代码示例>>PHP>>正文


PHP Response::macro方法代码示例

本文整理汇总了PHP中Illuminate\Support\Facades\Response::macro方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::macro方法的具体用法?PHP Response::macro怎么用?PHP Response::macro使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Support\Facades\Response的用法示例。


在下文中一共展示了Response::macro方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: boot

 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     Response::macro('success', function ($data) {
         return Response::json(['errors' => false, 'data' => $data]);
     });
     Response::macro('error', function ($message, $status = 400) {
         return Response::json(['message' => $status . ' error', 'errors' => ['message' => [$message]], 'status_code' => $status], $status);
     });
 }
开发者ID:jadjoubran,项目名称:laravel5-angular-material-starter,代码行数:14,代码来源:ResponseMacroServiceProvider.php

示例2: buildResponseMacro

 /**
  * Build the response macro.
  *
  * @param  string $name
  * @param  string|null $method
  * @return void
  */
 protected function buildResponseMacro($name, $method = null)
 {
     $method = $method ?: $name;
     $app = $this->app;
     Response::macro($name, function ($value, TransformerAbstract $transformer, $keys = [], SerializerAbstract $serializer = null) use($app, $method) {
         $response = $app[ResponseFactory::class];
         $method = $value instanceof LengthAwarePaginator ? 'paginator' : $method;
         $serializer = $serializer ?: new JsonNormalizeSerializer();
         return $response->{$method}($value, $transformer, $keys, function ($resource, $fractal) use($app, $method, $serializer) {
             if ($method != 'paginator') {
                 $fractal->setSerializer($serializer);
             }
             $with = $app['config']->get('apihelper.prefix', '');
             $with .= 'with';
             if ($includes = $app['request']->input($with)) {
                 $fractal->parseIncludes($includes);
             }
         });
     });
 }
开发者ID:jenky,项目名称:laravel-api-starter,代码行数:27,代码来源:ResponseMacroServiceProvider.php

示例3: defineMacros

 /**
  * Define Larave Response Macros
  *
  * @return void
  */
 private function defineMacros()
 {
     # Resources
     Response::macro('collection', function ($collection, $callback) {
         return Facades\Restful::collection($collection, $callback);
     });
     Response::macro('single', function ($model, $callback) {
         return Facades\Restful::single($model, $callback);
     });
     Response::macro('created', function ($model, $callback) {
         return Facades\Restful::created($model, $callback);
     });
     Response::macro('updated', function ($model, $callback) {
         return Facades\Restful::updated($model, $callback);
     });
     Response::macro('deleted', function ($message) {
         return Facades\Restful::deleted($message);
     });
     Response::macro('success', function ($message) {
         return Facades\Restful::success($message);
     });
     # Errors
     Response::macro('validationFailed', function (array $errors = [], $message = 'Validation Failed') {
         return Facades\Restful::validationFailed($errors, $message);
     });
     Response::macro('unprocessable', function ($message) {
         return Facades\Restful::unprocessable($message);
     });
     Response::macro('forbidden', function ($message) {
         return Facades\Restful::forbidden($message);
     });
     Response::macro('unauthorized', function ($message) {
         return Facades\Restful::unauthorized($message);
     });
     Response::macro('notFound', function ($message = 'Resource Not Found') {
         return Facades\Restful::notFound($message);
     });
 }
开发者ID:alioygur,项目名称:restful,代码行数:43,代码来源:RestfulServiceProvider.php

示例4: bootResponseMacro

 /**
  * Boot the response facade macro.
  * 
  * @return void
  */
 protected function bootResponseMacro()
 {
     Response::macro('api', function () {
         return $this->app['dingo.api.response'];
     });
 }
开发者ID:woolo,项目名称:laravel-restful-api,代码行数:11,代码来源:ApiServiceProvider.php

示例5: boot

 /**
  * Bootstrap the application events.
  *
  * @return void
  */
 public function boot()
 {
     $this->package('vena/jsend4laravel', 'jsend4laravel');
     /**
      * Wrapper for sending a JSON response with automatic JSONP support
      * @param  string        $message  (required) Message describing the error.
      * @param  string|array  $data     (optional) Data to include in the response.
      * @param  int           $status   (optional) HTTP status code of the return response.
      * @param  array         $headers  (optional) Request headers to include in the response.
      * @return Response
      */
     Response::macro('jsend', function ($data = NULL, $httpStatus = 200, array $headers = array()) {
         $response = Response::json($data, $httpStatus, $headers);
         if (Input::has('callback')) {
             $response->setCallback(Input::get('callback'));
         }
         return $response;
     });
     /**
      * Return a JSend success response
      * 
      * @param  string        $message  (required) Message describing the error.
      * @param  string|array  $data     (optional) Data to include in the response.
      * @param  int           $status   (optional) HTTP status code of the return response.
      * @param  array         $headers  (optional) Request headers to include in the response.
      * @return Response
      */
     Response::macro('jsendSuccess', function ($data = NULL, $httpStatus = 200, array $headers = array()) {
         return Response::jsend((object) array('status' => 'success', 'data' => $data), $httpStatus, $headers);
     });
     /**
      * Return a JSend fail response
      *
      * @param  string        $message  (required) Message describing the error.
      * @param  string|array  $data     (optional) Data to include in the response.
      * @param  int           $status   (optional) HTTP status code of the return response.
      * @param  array         $headers  (optional) Request headers to include in the response.
      * @return Response
      */
     Response::macro('jsendFail', function ($data, $httpStatus = 400, array $headers = array()) {
         $responseData = (object) array('status' => 'fail', 'data' => $data);
         return Response::jsend($responseData, $httpStatus, $headers);
     });
     /**
      * Return a JSend error response
      *
      * @param  string        $message  (required) Message describing the error.
      * @param  int           $code     (optional) An internal error code, if applicable
      * @param  string|array  $data     (optional) Data to include in the response.
      * @param  int           $status   (optional) HTTP status code of the return response.
      * @param  array         $headers  (optional) Request headers to include in the response.
      * @return Response
      */
     Response::macro('jsendError', function ($message = NULL, $code = NULL, $data = NULL, $httpStatus = 400, array $headers = array()) {
         if (is_null($message)) {
             throw new \BadMethodCallException($this->app['translator']->get('jsend4laravel::messages.jsend_errors_must_have_messages'));
         }
         $responseData = (object) array('status' => 'error', 'message' => $message);
         if (!is_null($code)) {
             $responseData->code = $code;
         }
         if (!is_null($data)) {
             $responseData->data = $data;
         }
         return Response::jsend($responseData, $httpStatus, $headers);
     });
 }
开发者ID:vena,项目名称:jsend4laravel,代码行数:72,代码来源:JSend4LaravelServiceProvider.php


注:本文中的Illuminate\Support\Facades\Response::macro方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。