|
| 1 | +<?php |
| 2 | +/* |
| 3 | + * Copyright 2021 Cloud Creativity Limited |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +declare(strict_types=1); |
| 19 | + |
| 20 | +namespace LaravelJsonApi\Laravel\Console; |
| 21 | + |
| 22 | +use Illuminate\Console\GeneratorCommand as BaseGeneratorCommand; |
| 23 | +use Symfony\Component\Console\Input\InputOption; |
| 24 | + |
| 25 | +class MakeSortField extends BaseGeneratorCommand |
| 26 | +{ |
| 27 | + |
| 28 | + use Concerns\ResolvesStub; |
| 29 | + |
| 30 | + /** |
| 31 | + * @var string |
| 32 | + */ |
| 33 | + protected $name = 'jsonapi:sort-field'; |
| 34 | + |
| 35 | + /** |
| 36 | + * @var string |
| 37 | + */ |
| 38 | + protected $description = 'Create a new JSON:API sort field.'; |
| 39 | + |
| 40 | + /** |
| 41 | + * @var string |
| 42 | + */ |
| 43 | + protected $type = 'JSON:API sort field'; |
| 44 | + |
| 45 | + /** |
| 46 | + * @inheritDoc |
| 47 | + */ |
| 48 | + protected function getStub() |
| 49 | + { |
| 50 | + return $this->resolveStubPath('sort-field.stub'); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @inheritDoc |
| 55 | + */ |
| 56 | + protected function getDefaultNamespace($rootNamespace) |
| 57 | + { |
| 58 | + $jsonApi = trim(config('jsonapi.namespace') ?: 'JsonApi', '\\'); |
| 59 | + |
| 60 | + return $rootNamespace . '\\' . $jsonApi . '\\' . 'Sorting'; |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * Get the console command options. |
| 65 | + * |
| 66 | + * @return array |
| 67 | + */ |
| 68 | + protected function getOptions() |
| 69 | + { |
| 70 | + return [ |
| 71 | + ['force', null, InputOption::VALUE_NONE, 'Create the class even if the sort field already exists'], |
| 72 | + ]; |
| 73 | + } |
| 74 | + |
| 75 | +} |
0 commit comments