-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/1.0.0-beta.3' into main
- Loading branch information
Showing
19 changed files
with
420 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
/* | ||
* Copyright 2021 Cloud Creativity Limited | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelJsonApi\Laravel\Console; | ||
|
||
use Illuminate\Console\GeneratorCommand as BaseGeneratorCommand; | ||
use Symfony\Component\Console\Input\InputOption; | ||
|
||
class MakeSortField extends BaseGeneratorCommand | ||
{ | ||
|
||
use Concerns\ResolvesStub; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $name = 'jsonapi:sort-field'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $description = 'Create a new JSON:API sort field.'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $type = 'JSON:API sort field'; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function getStub() | ||
{ | ||
return $this->resolveStubPath('sort-field.stub'); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function getDefaultNamespace($rootNamespace) | ||
{ | ||
$jsonApi = trim(config('jsonapi.namespace') ?: 'JsonApi', '\\'); | ||
|
||
return $rootNamespace . '\\' . $jsonApi . '\\' . 'Sorting'; | ||
} | ||
|
||
/** | ||
* Get the console command options. | ||
* | ||
* @return array | ||
*/ | ||
protected function getOptions() | ||
{ | ||
return [ | ||
['force', null, InputOption::VALUE_NONE, 'Create the class even if the sort field already exists'], | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
namespace {{ namespace }}; | ||
|
||
use LaravelJsonApi\Eloquent\Contracts\SortField; | ||
|
||
class {{ class }} implements SortField | ||
{ | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private string $name; | ||
|
||
/** | ||
* Create a new sort field. | ||
* | ||
* @param string $name | ||
* @param string|null $column | ||
* @return {{ class }} | ||
*/ | ||
public static function make(string $name): self | ||
{ | ||
return new static($name); | ||
} | ||
|
||
/** | ||
* {{ class }} constructor. | ||
* | ||
* @param string $name | ||
*/ | ||
public function __construct(string $name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
/** | ||
* Get the name of the sort field. | ||
* | ||
* @return string | ||
*/ | ||
public function sortField(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* Apply the sort order to the query. | ||
* | ||
* @param \Illuminate\Database\Eloquent\Builder $query | ||
* @param string $direction | ||
* @return \Illuminate\Database\Eloquent\Builder | ||
*/ | ||
public function sort($query, string $direction = 'asc') | ||
{ | ||
// @TODO | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.