@@ -60,7 +60,7 @@ |
||
| 60 | 60 | /** |
| 61 | 61 | * Constructor. |
| 62 | 62 | * |
| 63 | - * @param \Illuminate\Contracts\Routing\ResponseFactory|\Laravel\Lumen\Http\ResponseFactory $responseFactory |
|
| 63 | + * @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory |
|
| 64 | 64 | * @param \Symfony\Component\Translation\TranslatorInterface $translator |
| 65 | 65 | */ |
| 66 | 66 | public function __construct($responseFactory, TranslatorInterface $translator) |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @var array |
| 22 | 22 | */ |
| 23 | - protected $data = []; |
|
| 23 | + protected $data = [ ]; |
|
| 24 | 24 | |
| 25 | 25 | /** |
| 26 | 26 | * The error code used to identify the error. |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * |
| 42 | 42 | * @var array |
| 43 | 43 | */ |
| 44 | - protected $parameters = []; |
|
| 44 | + protected $parameters = [ ]; |
|
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | 47 | * The HTTP status code for the response. |
@@ -63,11 +63,11 @@ discard block |
||
| 63 | 63 | * @param \Illuminate\Contracts\Routing\ResponseFactory|\Laravel\Lumen\Http\ResponseFactory $responseFactory |
| 64 | 64 | * @param \Symfony\Component\Translation\TranslatorInterface $translator |
| 65 | 65 | */ |
| 66 | - public function __construct($responseFactory, TranslatorInterface $translator) |
|
| 66 | + public function __construct( $responseFactory, TranslatorInterface $translator ) |
|
| 67 | 67 | { |
| 68 | 68 | $this->translator = $translator; |
| 69 | 69 | |
| 70 | - parent::__construct($responseFactory); |
|
| 70 | + parent::__construct( $responseFactory ); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -76,9 +76,9 @@ discard block |
||
| 76 | 76 | * @param array $data |
| 77 | 77 | * @return self |
| 78 | 78 | */ |
| 79 | - public function addData(array $data):ErrorResponseBuilder |
|
| 79 | + public function addData( array $data ):ErrorResponseBuilder |
|
| 80 | 80 | { |
| 81 | - $this->data = array_merge($this->data, $data); |
|
| 81 | + $this->data = array_merge( $this->data, $data ); |
|
| 82 | 82 | |
| 83 | 83 | return $this; |
| 84 | 84 | } |
@@ -90,11 +90,11 @@ discard block |
||
| 90 | 90 | * @param string|array|null $message |
| 91 | 91 | * @return self |
| 92 | 92 | */ |
| 93 | - public function setError(string $errorCode = null, $message = null):ErrorResponseBuilder |
|
| 93 | + public function setError( string $errorCode = null, $message = null ):ErrorResponseBuilder |
|
| 94 | 94 | { |
| 95 | 95 | $this->errorCode = $errorCode; |
| 96 | 96 | |
| 97 | - if (is_array($message)) { |
|
| 97 | + if ( is_array( $message ) ) { |
|
| 98 | 98 | $this->parameters = $message; |
| 99 | 99 | } else { |
| 100 | 100 | $this->message = $message; |
@@ -110,13 +110,13 @@ discard block |
||
| 110 | 110 | * @return self |
| 111 | 111 | * @throws \InvalidArgumentException |
| 112 | 112 | */ |
| 113 | - public function setStatus(int $statusCode):ResponseBuilder |
|
| 113 | + public function setStatus( int $statusCode ):ResponseBuilder |
|
| 114 | 114 | { |
| 115 | - if ($statusCode < 400 || $statusCode >= 600) { |
|
| 116 | - throw new InvalidArgumentException("{$statusCode} is not a valid error HTTP status code."); |
|
| 115 | + if ( $statusCode < 400 || $statusCode >= 600 ) { |
|
| 116 | + throw new InvalidArgumentException( "{$statusCode} is not a valid error HTTP status code." ); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | - return parent::setStatus($statusCode); |
|
| 119 | + return parent::setStatus( $statusCode ); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | protected function buildErrorData() |
| 141 | 141 | { |
| 142 | - if (is_null($this->errorCode)) { |
|
| 142 | + if ( is_null( $this->errorCode ) ) { |
|
| 143 | 143 | return null; |
| 144 | 144 | } |
| 145 | 145 | |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | 'message' => $this->message ?: $this->resolveMessage() |
| 149 | 149 | ]; |
| 150 | 150 | |
| 151 | - return array_merge($data, $this->data); |
|
| 151 | + return array_merge( $data, $this->data ); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -158,10 +158,10 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | protected function resolveMessage() |
| 160 | 160 | { |
| 161 | - if (! $this->translator->has($code = "errors.$this->errorCode")) { |
|
| 161 | + if ( ! $this->translator->has( $code = "errors.$this->errorCode" ) ) { |
|
| 162 | 162 | return null; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - return $this->translator->trans($code, $this->parameters); |
|
| 165 | + return $this->translator->trans( $code, $this->parameters ); |
|
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | \ No newline at end of file |
@@ -70,7 +70,7 @@ |
||
| 70 | 70 | /** |
| 71 | 71 | * SuccessResponseBuilder constructor. |
| 72 | 72 | * |
| 73 | - * @param \Illuminate\Contracts\Routing\ResponseFactory|\Laravel\Lumen\Http\ResponseFactory $responseFactory |
|
| 73 | + * @param \Illuminate\Contracts\Routing\ResponseFactory $responseFactory |
|
| 74 | 74 | * @param \Flugg\Responder\ResourceFactory $resourceFactory |
| 75 | 75 | * @param \League\Fractal\Manager $manager |
| 76 | 76 | */ |
@@ -37,14 +37,14 @@ discard block |
||
| 37 | 37 | * |
| 38 | 38 | * @var array |
| 39 | 39 | */ |
| 40 | - protected $meta = []; |
|
| 40 | + protected $meta = [ ]; |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * The included relations. |
| 44 | 44 | * |
| 45 | 45 | * @var array |
| 46 | 46 | */ |
| 47 | - protected $relations = []; |
|
| 47 | + protected $relations = [ ]; |
|
| 48 | 48 | |
| 49 | 49 | /** |
| 50 | 50 | * The Fractal resource instance containing the data and transformer. |
@@ -74,13 +74,13 @@ discard block |
||
| 74 | 74 | * @param \Flugg\Responder\ResourceFactory $resourceFactory |
| 75 | 75 | * @param \League\Fractal\Manager $manager |
| 76 | 76 | */ |
| 77 | - public function __construct($responseFactory, ResourceFactory $resourceFactory, Manager $manager) |
|
| 77 | + public function __construct( $responseFactory, ResourceFactory $resourceFactory, Manager $manager ) |
|
| 78 | 78 | { |
| 79 | 79 | $this->resourceFactory = $resourceFactory; |
| 80 | 80 | $this->manager = $manager; |
| 81 | 81 | $this->resource = $this->resourceFactory->make(); |
| 82 | 82 | |
| 83 | - parent::__construct($responseFactory); |
|
| 83 | + parent::__construct( $responseFactory ); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -89,9 +89,9 @@ discard block |
||
| 89 | 89 | * @param array $data |
| 90 | 90 | * @return self |
| 91 | 91 | */ |
| 92 | - public function addMeta(array $data):SuccessResponseBuilder |
|
| 92 | + public function addMeta( array $data ):SuccessResponseBuilder |
|
| 93 | 93 | { |
| 94 | - $this->meta = array_merge($this->meta, $data); |
|
| 94 | + $this->meta = array_merge( $this->meta, $data ); |
|
| 95 | 95 | |
| 96 | 96 | return $this; |
| 97 | 97 | } |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | public function include($relations):SuccessResponseBuilder |
| 106 | 106 | { |
| 107 | - $this->relations = array_merge($this->relations, $relations); |
|
| 107 | + $this->relations = array_merge( $this->relations, $relations ); |
|
| 108 | 108 | |
| 109 | 109 | return $this; |
| 110 | 110 | } |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | * @param \League\Fractal\Serializer\SerializerAbstract|string $serializer |
| 116 | 116 | * @return self |
| 117 | 117 | */ |
| 118 | - public function serializer($serializer):SuccessResponseBuilder |
|
| 118 | + public function serializer( $serializer ):SuccessResponseBuilder |
|
| 119 | 119 | { |
| 120 | - $this->manager->setSerializer($this->resolveSerializer($serializer)); |
|
| 120 | + $this->manager->setSerializer( $this->resolveSerializer( $serializer ) ); |
|
| 121 | 121 | |
| 122 | 122 | return $this; |
| 123 | 123 | } |
@@ -129,13 +129,13 @@ discard block |
||
| 129 | 129 | * @return self |
| 130 | 130 | * @throws \InvalidArgumentException |
| 131 | 131 | */ |
| 132 | - public function setStatus(int $statusCode):ResponseBuilder |
|
| 132 | + public function setStatus( int $statusCode ):ResponseBuilder |
|
| 133 | 133 | { |
| 134 | - if ($statusCode < 100 || $statusCode >= 400) { |
|
| 135 | - throw new InvalidArgumentException("{$statusCode} is not a valid success HTTP status code."); |
|
| 134 | + if ( $statusCode < 100 || $statusCode >= 400 ) { |
|
| 135 | + throw new InvalidArgumentException( "{$statusCode} is not a valid success HTTP status code." ); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - return parent::setStatus($statusCode); |
|
| 138 | + return parent::setStatus( $statusCode ); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -147,25 +147,25 @@ discard block |
||
| 147 | 147 | * @param string|null $resourceKey |
| 148 | 148 | * @return self |
| 149 | 149 | */ |
| 150 | - public function transform($data = null, $transformer = null, string $resourceKey = null):SuccessResponseBuilder |
|
| 150 | + public function transform( $data = null, $transformer = null, string $resourceKey = null ):SuccessResponseBuilder |
|
| 151 | 151 | { |
| 152 | - $resource = $this->resourceFactory->make($data); |
|
| 152 | + $resource = $this->resourceFactory->make( $data ); |
|
| 153 | 153 | |
| 154 | - if (! is_null($resource->getData())) { |
|
| 155 | - $model = $this->resolveModel($resource->getData()); |
|
| 156 | - $transformer = $this->resolveTransformer($model, $transformer); |
|
| 157 | - $resourceKey = $this->resolveResourceKey($model, $resourceKey); |
|
| 154 | + if ( ! is_null( $resource->getData() ) ) { |
|
| 155 | + $model = $this->resolveModel( $resource->getData() ); |
|
| 156 | + $transformer = $this->resolveTransformer( $model, $transformer ); |
|
| 157 | + $resourceKey = $this->resolveResourceKey( $model, $resourceKey ); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - if ($transformer instanceof Transformer) { |
|
| 161 | - $this->include($relations = $this->resolveNestedRelations($resource->getData())); |
|
| 160 | + if ( $transformer instanceof Transformer ) { |
|
| 161 | + $this->include( $relations = $this->resolveNestedRelations( $resource->getData() ) ); |
|
| 162 | 162 | |
| 163 | - if ($transformer->allRelationsAllowed()) { |
|
| 164 | - $transformer->setRelations($relations); |
|
| 163 | + if ( $transformer->allRelationsAllowed() ) { |
|
| 164 | + $transformer->setRelations( $relations ); |
|
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - $this->resource = $resource->setTransformer($transformer)->setResourceKey($resourceKey); |
|
| 168 | + $this->resource = $resource->setTransformer( $transformer )->setResourceKey( $resourceKey ); |
|
| 169 | 169 | |
| 170 | 170 | return $this; |
| 171 | 171 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | */ |
| 178 | 178 | public function toArray():array |
| 179 | 179 | { |
| 180 | - return $this->serialize($this->getResource()); |
|
| 180 | + return $this->serialize( $this->getResource() ); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -187,14 +187,14 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | public function getResource():ResourceInterface |
| 189 | 189 | { |
| 190 | - $this->manager->parseIncludes($this->relations); |
|
| 190 | + $this->manager->parseIncludes( $this->relations ); |
|
| 191 | 191 | $transformer = $this->resource->getTransformer(); |
| 192 | 192 | |
| 193 | - if ($transformer instanceof Transformer && $transformer->allRelationsAllowed()) { |
|
| 194 | - $this->resource->setTransformer($transformer->setRelations($this->manager->getRequestedIncludes())); |
|
| 193 | + if ( $transformer instanceof Transformer && $transformer->allRelationsAllowed() ) { |
|
| 194 | + $this->resource->setTransformer( $transformer->setRelations( $this->manager->getRequestedIncludes() ) ); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - return $this->resource->setMeta($this->meta); |
|
| 197 | + return $this->resource->setMeta( $this->meta ); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -214,13 +214,13 @@ discard block |
||
| 214 | 214 | * @return \League\Fractal\Serializer\SerializerAbstract |
| 215 | 215 | * @throws \Flugg\Responder\Exceptions\InvalidSerializerException |
| 216 | 216 | */ |
| 217 | - protected function resolveSerializer($serializer):SerializerAbstract |
|
| 217 | + protected function resolveSerializer( $serializer ):SerializerAbstract |
|
| 218 | 218 | { |
| 219 | - if (is_string($serializer)) { |
|
| 219 | + if ( is_string( $serializer ) ) { |
|
| 220 | 220 | $serializer = new $serializer; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if (! $serializer instanceof SerializerAbstract) { |
|
| 223 | + if ( ! $serializer instanceof SerializerAbstract ) { |
|
| 224 | 224 | throw new InvalidSerializerException(); |
| 225 | 225 | } |
| 226 | 226 | |
@@ -234,15 +234,15 @@ discard block |
||
| 234 | 234 | * @return \Illuminate\Database\Eloquent\Model |
| 235 | 235 | * @throws \InvalidArgumentException |
| 236 | 236 | */ |
| 237 | - protected function resolveModel($data):Model |
|
| 237 | + protected function resolveModel( $data ):Model |
|
| 238 | 238 | { |
| 239 | - if ($data instanceof Model) { |
|
| 239 | + if ( $data instanceof Model ) { |
|
| 240 | 240 | return $data; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - $model = array_values($data)[0]; |
|
| 244 | - if (! $model instanceof Model) { |
|
| 245 | - throw new InvalidArgumentException('You can only transform data containing Eloquent models.'); |
|
| 243 | + $model = array_values( $data )[ 0 ]; |
|
| 244 | + if ( ! $model instanceof Model ) { |
|
| 245 | + throw new InvalidArgumentException( 'You can only transform data containing Eloquent models.' ); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | return $model; |
@@ -255,15 +255,15 @@ discard block |
||
| 255 | 255 | * @param \Flugg\Responder\Transformer|callable|null $transformer |
| 256 | 256 | * @return \Flugg\Responder\Transformer|callable |
| 257 | 257 | */ |
| 258 | - protected function resolveTransformer(Model $model, $transformer = null) |
|
| 258 | + protected function resolveTransformer( Model $model, $transformer = null ) |
|
| 259 | 259 | { |
| 260 | - $transformer = $transformer ?: $this->resolveTransformerFromModel($model); |
|
| 260 | + $transformer = $transformer ?: $this->resolveTransformerFromModel( $model ); |
|
| 261 | 261 | |
| 262 | - if (is_string($transformer)) { |
|
| 262 | + if ( is_string( $transformer ) ) { |
|
| 263 | 263 | $transformer = new $transformer; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - return $this->parseTransformer($transformer, $model); |
|
| 266 | + return $this->parseTransformer( $transformer, $model ); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | /** |
@@ -273,10 +273,10 @@ discard block |
||
| 273 | 273 | * @param \Illuminate\Database\ELoquent\Model $model |
| 274 | 274 | * @return \Flugg\Responder\Transformer|callable |
| 275 | 275 | */ |
| 276 | - protected function resolveTransformerFromModel(Model $model) |
|
| 276 | + protected function resolveTransformerFromModel( Model $model ) |
|
| 277 | 277 | { |
| 278 | - if (! $model instanceof Transformable) { |
|
| 279 | - return function ($model) { |
|
| 278 | + if ( ! $model instanceof Transformable ) { |
|
| 279 | + return function ( $model ) { |
|
| 280 | 280 | return $model->toArray(); |
| 281 | 281 | }; |
| 282 | 282 | } |
@@ -292,14 +292,14 @@ discard block |
||
| 292 | 292 | * @return \Flugg\Responder\Transformer|callable |
| 293 | 293 | * @throws \InvalidTransformerException |
| 294 | 294 | */ |
| 295 | - protected function parseTransformer($transformer, Model $model) |
|
| 295 | + protected function parseTransformer( $transformer, Model $model ) |
|
| 296 | 296 | { |
| 297 | - if ($transformer instanceof Transformer) { |
|
| 298 | - $relations = $transformer->allRelationsAllowed() ? $this->resolveRelations($model) : $transformer->getRelations(); |
|
| 299 | - $transformer = $transformer->setRelations($relations); |
|
| 297 | + if ( $transformer instanceof Transformer ) { |
|
| 298 | + $relations = $transformer->allRelationsAllowed() ? $this->resolveRelations( $model ) : $transformer->getRelations(); |
|
| 299 | + $transformer = $transformer->setRelations( $relations ); |
|
| 300 | 300 | |
| 301 | - } elseif (! is_callable($transformer)) { |
|
| 302 | - throw new InvalidTransformerException($model); |
|
| 301 | + } elseif ( ! is_callable( $transformer ) ) { |
|
| 302 | + throw new InvalidTransformerException( $model ); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | return $transformer; |
@@ -311,9 +311,9 @@ discard block |
||
| 311 | 311 | * @param \Illuminate\Database\Eloquent\Model $model |
| 312 | 312 | * @return array |
| 313 | 313 | */ |
| 314 | - protected function resolveRelations(Model $model):array |
|
| 314 | + protected function resolveRelations( Model $model ):array |
|
| 315 | 315 | { |
| 316 | - return array_keys($model->getRelations()); |
|
| 316 | + return array_keys( $model->getRelations() ); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | /** |
@@ -322,22 +322,22 @@ discard block |
||
| 322 | 322 | * @param \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model $data |
| 323 | 323 | * @return array |
| 324 | 324 | */ |
| 325 | - protected function resolveNestedRelations($data):array |
|
| 325 | + protected function resolveNestedRelations( $data ):array |
|
| 326 | 326 | { |
| 327 | - if (is_null($data)) { |
|
| 328 | - return []; |
|
| 327 | + if ( is_null( $data ) ) { |
|
| 328 | + return [ ]; |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - $data = $data instanceof Model ? [$data] : $data; |
|
| 331 | + $data = $data instanceof Model ? [ $data ] : $data; |
|
| 332 | 332 | |
| 333 | - return collect($data)->flatMap(function ($model) { |
|
| 334 | - $relations = collect($model->getRelations()); |
|
| 333 | + return collect( $data )->flatMap( function ( $model ) { |
|
| 334 | + $relations = collect( $model->getRelations() ); |
|
| 335 | 335 | |
| 336 | - return $relations->keys()->merge($relations->flatMap(function ($relation, $key) { |
|
| 337 | - return collect($this->resolveNestedRelations($relation))->map(function ($nestedRelation) use ($key) { |
|
| 336 | + return $relations->keys()->merge( $relations->flatMap( function ( $relation, $key ) { |
|
| 337 | + return collect( $this->resolveNestedRelations( $relation ) )->map( function ( $nestedRelation ) use ($key) { |
|
| 338 | 338 | return $key . '.' . $nestedRelation; |
| 339 | 339 | }); |
| 340 | - })); |
|
| 340 | + }) ); |
|
| 341 | 341 | })->toArray(); |
| 342 | 342 | } |
| 343 | 343 | |
@@ -348,13 +348,13 @@ discard block |
||
| 348 | 348 | * @param string|null $resourceKey |
| 349 | 349 | * @return string |
| 350 | 350 | */ |
| 351 | - protected function resolveResourceKey(Model $model, string $resourceKey = null):string |
|
| 351 | + protected function resolveResourceKey( Model $model, string $resourceKey = null ):string |
|
| 352 | 352 | { |
| 353 | - if (! is_null($resourceKey)) { |
|
| 353 | + if ( ! is_null( $resourceKey ) ) { |
|
| 354 | 354 | return $resourceKey; |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - if (method_exists($model, 'getResourceKey')) { |
|
| 357 | + if ( method_exists( $model, 'getResourceKey' ) ) { |
|
| 358 | 358 | return $model->getResourceKey(); |
| 359 | 359 | } |
| 360 | 360 | |
@@ -367,8 +367,8 @@ discard block |
||
| 367 | 367 | * @param ResourceInterface $resource |
| 368 | 368 | * @return array |
| 369 | 369 | */ |
| 370 | - protected function serialize(ResourceInterface $resource):array |
|
| 370 | + protected function serialize( ResourceInterface $resource ):array |
|
| 371 | 371 | { |
| 372 | - return $this->manager->createData($resource)->toArray(); |
|
| 372 | + return $this->manager->createData( $resource )->toArray(); |
|
| 373 | 373 | } |
| 374 | 374 | } |
| 375 | 375 | \ No newline at end of file |
@@ -43,18 +43,18 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function boot() |
| 45 | 45 | { |
| 46 | - if ($this->app instanceof Laravel && $this->app->runningInConsole()) { |
|
| 46 | + if ( $this->app instanceof Laravel && $this->app->runningInConsole() ) { |
|
| 47 | 47 | $this->bootLaravelApplication(); |
| 48 | 48 | |
| 49 | - } elseif ($this->app instanceof Lumen) { |
|
| 49 | + } elseif ( $this->app instanceof Lumen ) { |
|
| 50 | 50 | $this->bootLumenApplication(); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - $this->mergeConfigFrom(__DIR__ . '/../resources/config/responder.php', 'responder'); |
|
| 53 | + $this->mergeConfigFrom( __DIR__ . '/../resources/config/responder.php', 'responder' ); |
|
| 54 | 54 | |
| 55 | - $this->commands([ |
|
| 55 | + $this->commands( [ |
|
| 56 | 56 | MakeTransformer::class |
| 57 | - ]); |
|
| 57 | + ] ); |
|
| 58 | 58 | |
| 59 | 59 | include __DIR__ . '/helpers.php'; |
| 60 | 60 | } |
@@ -69,8 +69,8 @@ discard block |
||
| 69 | 69 | $this->registerFractal(); |
| 70 | 70 | $this->registerResponseBuilders(); |
| 71 | 71 | |
| 72 | - $this->app->bind(Responder::class, function ($app) { |
|
| 73 | - return new Responder($app[SuccessResponseBuilder::class], $app[ErrorResponseBuilder::class]); |
|
| 72 | + $this->app->bind( Responder::class, function ( $app ) { |
|
| 73 | + return new Responder( $app[ SuccessResponseBuilder::class ], $app[ ErrorResponseBuilder::class ] ); |
|
| 74 | 74 | }); |
| 75 | 75 | |
| 76 | 76 | $this->registerAliases(); |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function provides() |
| 85 | 85 | { |
| 86 | - return ['responder', 'responder.success', 'responder.error', 'responder.manager', 'responder.serializer']; |
|
| 86 | + return [ 'responder', 'responder.success', 'responder.error', 'responder.manager', 'responder.serializer' ]; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -94,17 +94,17 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | protected function registerFractal() |
| 96 | 96 | { |
| 97 | - $this->app->bind(SerializerAbstract::class, function ($app) { |
|
| 98 | - $serializer = $app->config->get('responder.serializer'); |
|
| 97 | + $this->app->bind( SerializerAbstract::class, function ( $app ) { |
|
| 98 | + $serializer = $app->config->get( 'responder.serializer' ); |
|
| 99 | 99 | |
| 100 | 100 | return new $serializer; |
| 101 | 101 | }); |
| 102 | 102 | |
| 103 | - $this->app->bind(Manager::class, function ($app) { |
|
| 104 | - return (new Manager())->setSerializer($app[SerializerAbstract::class]); |
|
| 103 | + $this->app->bind( Manager::class, function ( $app ) { |
|
| 104 | + return (new Manager())->setSerializer( $app[ SerializerAbstract::class ] ); |
|
| 105 | 105 | }); |
| 106 | 106 | |
| 107 | - $this->app->bind(ResourceFactory::class, function () { |
|
| 107 | + $this->app->bind( ResourceFactory::class, function () { |
|
| 108 | 108 | return new ResourceFactory(); |
| 109 | 109 | }); |
| 110 | 110 | } |
@@ -116,20 +116,20 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | protected function registerResponseBuilders() |
| 118 | 118 | { |
| 119 | - $this->app->bind(SuccessResponseBuilder::class, function ($app) { |
|
| 120 | - $builder = new SuccessResponseBuilder(response(), $app[ResourceFactory::class], $app[Manager::class]); |
|
| 119 | + $this->app->bind( SuccessResponseBuilder::class, function ( $app ) { |
|
| 120 | + $builder = new SuccessResponseBuilder( response(), $app[ ResourceFactory::class ], $app[ Manager::class ] ); |
|
| 121 | 121 | |
| 122 | - if ($parameter = $this->app->config->get('responder.includeFromParameter')) { |
|
| 123 | - $builder->include($this->app[Request::class]->input($parameter, [])); |
|
| 122 | + if ( $parameter = $this->app->config->get( 'responder.includeFromParameter' ) ) { |
|
| 123 | + $builder->include( $this->app[ Request::class ]->input( $parameter, [ ] ) ); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - return $builder->setIncludeStatusCode($app->config->get('responder.include_status_code')); |
|
| 126 | + return $builder->setIncludeStatusCode( $app->config->get( 'responder.include_status_code' ) ); |
|
| 127 | 127 | }); |
| 128 | 128 | |
| 129 | - $this->app->bind(ErrorResponseBuilder::class, function ($app) { |
|
| 130 | - $builder = new ErrorResponseBuilder(response(), $app['translator']); |
|
| 129 | + $this->app->bind( ErrorResponseBuilder::class, function ( $app ) { |
|
| 130 | + $builder = new ErrorResponseBuilder( response(), $app[ 'translator' ] ); |
|
| 131 | 131 | |
| 132 | - return $builder->setIncludeStatusCode($app->config->get('responder.include_status_code')); |
|
| 132 | + return $builder->setIncludeStatusCode( $app->config->get( 'responder.include_status_code' ) ); |
|
| 133 | 133 | }); |
| 134 | 134 | } |
| 135 | 135 | |
@@ -140,11 +140,11 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | protected function registerAliases() |
| 142 | 142 | { |
| 143 | - $this->app->alias(Responder::class, 'responder'); |
|
| 144 | - $this->app->alias(SuccessResponseBuilder::class, 'responder.success'); |
|
| 145 | - $this->app->alias(ErrorResponseBuilder::class, 'responder.error'); |
|
| 146 | - $this->app->alias(Manager::class, 'responder.manager'); |
|
| 147 | - $this->app->alias(Manager::class, 'responder.serializer'); |
|
| 143 | + $this->app->alias( Responder::class, 'responder' ); |
|
| 144 | + $this->app->alias( SuccessResponseBuilder::class, 'responder.success' ); |
|
| 145 | + $this->app->alias( ErrorResponseBuilder::class, 'responder.error' ); |
|
| 146 | + $this->app->alias( Manager::class, 'responder.manager' ); |
|
| 147 | + $this->app->alias( Manager::class, 'responder.serializer' ); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | protected function bootLaravelApplication() |
| 156 | 156 | { |
| 157 | - $this->publishes([ |
|
| 158 | - __DIR__ . '/../resources/config/responder.php' => config_path('responder.php') |
|
| 159 | - ], 'config'); |
|
| 157 | + $this->publishes( [ |
|
| 158 | + __DIR__ . '/../resources/config/responder.php' => config_path( 'responder.php' ) |
|
| 159 | + ], 'config' ); |
|
| 160 | 160 | |
| 161 | - $this->publishes([ |
|
| 162 | - __DIR__ . '/../resources/lang/en/errors.php' => resource_path('lang/en/errors.php') |
|
| 163 | - ], 'lang'); |
|
| 161 | + $this->publishes( [ |
|
| 162 | + __DIR__ . '/../resources/lang/en/errors.php' => resource_path( 'lang/en/errors.php' ) |
|
| 163 | + ], 'lang' ); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -170,6 +170,6 @@ discard block |
||
| 170 | 170 | */ |
| 171 | 171 | protected function bootLumenApplication() |
| 172 | 172 | { |
| 173 | - $this->app->configure('responder'); |
|
| 173 | + $this->app->configure( 'responder' ); |
|
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | \ No newline at end of file |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | * |
| 45 | 45 | * @param \Illuminate\Contracts\Routing\ResponseFactory|\Laravel\Lumen\Http\ResponseFactory $responseFactory |
| 46 | 46 | */ |
| 47 | - public function __construct($responseFactory) |
|
| 47 | + public function __construct( $responseFactory ) |
|
| 48 | 48 | { |
| 49 | 49 | $this->responseFactory = $responseFactory; |
| 50 | 50 | } |
@@ -56,15 +56,15 @@ discard block |
||
| 56 | 56 | * @param array $headers |
| 57 | 57 | * @return \Illuminate\Http\JsonResponse |
| 58 | 58 | */ |
| 59 | - public function respond(int $statusCode = null, array $headers = []):JsonResponse |
|
| 59 | + public function respond( int $statusCode = null, array $headers = [ ] ):JsonResponse |
|
| 60 | 60 | { |
| 61 | - if (! is_null($statusCode)) { |
|
| 62 | - $this->setStatus($statusCode); |
|
| 61 | + if ( ! is_null( $statusCode ) ) { |
|
| 62 | + $this->setStatus( $statusCode ); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | - $data = $this->includeStatusCode($this->toArray()); |
|
| 65 | + $data = $this->includeStatusCode( $this->toArray() ); |
|
| 66 | 66 | |
| 67 | - return $this->responseFactory->json($data, $this->statusCode, $headers); |
|
| 67 | + return $this->responseFactory->json( $data, $this->statusCode, $headers ); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | * @param int $statusCode |
| 74 | 74 | * @return self |
| 75 | 75 | */ |
| 76 | - public function setStatus(int $statusCode):ResponseBuilder |
|
| 76 | + public function setStatus( int $statusCode ):ResponseBuilder |
|
| 77 | 77 | { |
| 78 | 78 | $this->statusCode = $statusCode; |
| 79 | 79 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @param bool $includeStatusCode |
| 87 | 87 | * @return self |
| 88 | 88 | */ |
| 89 | - public function setIncludeStatusCode(bool $includeStatusCode):ResponseBuilder |
|
| 89 | + public function setIncludeStatusCode( bool $includeStatusCode ):ResponseBuilder |
|
| 90 | 90 | { |
| 91 | 91 | $this->includeStatusCode = $includeStatusCode; |
| 92 | 92 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | public function toCollection():Collection |
| 102 | 102 | { |
| 103 | - return new Collection($this->toArray()); |
|
| 103 | + return new Collection( $this->toArray() ); |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | /** |
@@ -109,9 +109,9 @@ discard block |
||
| 109 | 109 | * @param int $options |
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | - public function toJson($options = 0) |
|
| 112 | + public function toJson( $options = 0 ) |
|
| 113 | 113 | { |
| 114 | - return json_encode($this->jsonSerialize(), $options); |
|
| 114 | + return json_encode( $this->jsonSerialize(), $options ); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -137,12 +137,12 @@ discard block |
||
| 137 | 137 | * @param array $data |
| 138 | 138 | * @return array |
| 139 | 139 | */ |
| 140 | - protected function includeStatusCode(array $data):array |
|
| 140 | + protected function includeStatusCode( array $data ):array |
|
| 141 | 141 | { |
| 142 | - if (! $this->includeStatusCode) { |
|
| 142 | + if ( ! $this->includeStatusCode ) { |
|
| 143 | 143 | return $data; |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - return array_merge(['status' => $this->statusCode], $data); |
|
| 146 | + return array_merge( [ 'status' => $this->statusCode ], $data ); |
|
| 147 | 147 | } |
| 148 | 148 | } |
| 149 | 149 | \ No newline at end of file |