-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from teamq-ec/add-scribe-docs
Add scribe docs
- Loading branch information
Showing
33 changed files
with
1,039 additions
and
45 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,40 @@ | ||
<?php | ||
|
||
namespace TeamQ\Datatables\Scribe\Strategies\Documentations; | ||
|
||
use Illuminate\Support\Collection; | ||
use Knuckles\Scribe\Attributes\QueryParam; | ||
use ReflectionClass; | ||
use ReflectionException; | ||
use Spatie\QueryBuilder\Filters\Filter; | ||
use Spatie\QueryBuilder\Sorts\Sort; | ||
|
||
class Documentation | ||
{ | ||
/** | ||
* Gets the documentation for the query params of the Spatie QueryBuilder package. | ||
* | ||
* | ||
* @return array|string[] | ||
* | ||
* @throws ReflectionException | ||
*/ | ||
public function __invoke(Filter|Sort|Collection|string $param, mixed $value = null, ?string $name = null): array | ||
{ | ||
$reflectionClass = new ReflectionClass($param); | ||
|
||
$documentation = $reflectionClass->getAttributes(QueryParam::class); | ||
|
||
if (! empty($documentation)) { | ||
$documentation = $documentation[0]->newInstance(); | ||
|
||
return $documentation->toArray(); | ||
} | ||
|
||
if (method_exists($param, 'docs')) { | ||
return $param::docs()->toArray(); | ||
} | ||
|
||
return []; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Scribe/Strategies/Documentations/Filters/BeginsWithStrictFilter.php
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,25 @@ | ||
<?php | ||
|
||
namespace TeamQ\Datatables\Scribe\Strategies\Documentations\Filters; | ||
|
||
use Illuminate\Support\Collection; | ||
use Spatie\QueryBuilder\Filters\Filter; | ||
use Spatie\QueryBuilder\Sorts\Sort; | ||
use TeamQ\Datatables\Scribe\Strategies\Documentations\Documentation; | ||
|
||
class BeginsWithStrictFilter extends Documentation | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __invoke(Filter|Sort|Collection|string $param, mixed $value = null, ?string $name = null): array | ||
{ | ||
return [ | ||
'name' => $name, | ||
'type' => 'string', | ||
'required' => false, | ||
'description' => 'Begin Partial Filter. It is evaluated as: The field starts with this value.', | ||
// 'example' => str($value)->substr(0, 3) ?: 'https://', | ||
]; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Scribe/Strategies/Documentations/Filters/DateFilter.php
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,40 @@ | ||
<?php | ||
|
||
namespace TeamQ\Datatables\Scribe\Strategies\Documentations\Filters; | ||
|
||
use Illuminate\Support\Collection; | ||
use Spatie\QueryBuilder\Filters\Filter; | ||
use Spatie\QueryBuilder\Sorts\Sort; | ||
use TeamQ\Datatables\Enums\Comparators\Number; | ||
use TeamQ\Datatables\Scribe\Strategies\Documentations\Documentation; | ||
|
||
class DateFilter extends Documentation | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __invoke(Filter|Sort|Collection|string $param, mixed $value = null, ?string $name = null): array | ||
{ | ||
$operators = collect(Number::cases()) | ||
->map(fn (Number $operator) => "<li>{$operator->value} - {$operator->name}</li>") | ||
->join(''); | ||
|
||
return [ | ||
'name' => $name, | ||
'type' => 'string', | ||
'required' => false, | ||
'description' => "<div>Date Filter. It belongs to a type of advanced filter, it allows filtering according to operators. Can receive different payload: | ||
<ul> | ||
<li><b>{$name}=2023-04-01</b><br>It is evaluated by equals.</li> | ||
<li><b>{$name}[value]=2023-04-01</b><br>It is evaluated by equals.</li> | ||
<li><b>{$name}[value]=2023-04-01&{$name}[operator]=5</b><br>It is evaluated by operator 5 (LessThan).</li> | ||
<li><b>{$name}[value][0]=2023-04-01&{$name}[value][1]=2023-07-30&{$name}[operator]=7</b><br>It is evaluated by operator 7 (Between). This operator will only take the first two 'values' however operators like 'In' will take the entire array of 'values'</li> | ||
</ul> | ||
Valid comparison operators are: | ||
<ul> | ||
$operators | ||
</ul> | ||
</div>", | ||
]; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Scribe/Strategies/Documentations/Filters/EndsWithStrictFilter.php
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,25 @@ | ||
<?php | ||
|
||
namespace TeamQ\Datatables\Scribe\Strategies\Documentations\Filters; | ||
|
||
use Illuminate\Support\Collection; | ||
use Spatie\QueryBuilder\Filters\Filter; | ||
use Spatie\QueryBuilder\Sorts\Sort; | ||
use TeamQ\Datatables\Scribe\Strategies\Documentations\Documentation; | ||
|
||
class EndsWithStrictFilter extends Documentation | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __invoke(Filter|Sort|Collection|string $param, mixed $value = null, ?string $name = null): array | ||
{ | ||
return [ | ||
'name' => $name, | ||
'type' => 'string', | ||
'required' => false, | ||
'description' => 'End Partial Filter. It is evaluated as: The field ends with this value.', | ||
// 'example' => str($value)->substr(0, 3) ?: '@gmail.com', | ||
]; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Scribe/Strategies/Documentations/Filters/ExactFilter.php
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,25 @@ | ||
<?php | ||
|
||
namespace TeamQ\Datatables\Scribe\Strategies\Documentations\Filters; | ||
|
||
use Illuminate\Support\Collection; | ||
use Spatie\QueryBuilder\Filters\Filter; | ||
use Spatie\QueryBuilder\Sorts\Sort; | ||
use TeamQ\Datatables\Scribe\Strategies\Documentations\Documentation; | ||
|
||
class ExactFilter extends Documentation | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __invoke(Filter|Sort|Collection|string $param, mixed $value = null, ?string $name = null): array | ||
{ | ||
return [ | ||
'name' => $name, | ||
'type' => 'string', | ||
'required' => false, | ||
'description' => 'Exact Filter. It is evaluated as: The field is exactly equal to this value.', | ||
// 'example' => $value ?: '[email protected]', | ||
]; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Scribe/Strategies/Documentations/Filters/GlobalFilter.php
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,24 @@ | ||
<?php | ||
|
||
namespace TeamQ\Datatables\Scribe\Strategies\Documentations\Filters; | ||
|
||
use Illuminate\Support\Collection; | ||
use Spatie\QueryBuilder\Filters\Filter; | ||
use Spatie\QueryBuilder\Sorts\Sort; | ||
use TeamQ\Datatables\Scribe\Strategies\Documentations\Documentation; | ||
|
||
class GlobalFilter extends Documentation | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __invoke(Filter|Sort|Collection|string $param, mixed $value = null, ?string $name = null): array | ||
{ | ||
return [ | ||
'name' => $name, | ||
'type' => 'string', | ||
'required' => false, | ||
'description' => 'This will search for the given value among the following fields: <ul>'.array_reduce(invade($param)->fields, static fn ($carry, $value) => $carry."<li>{$value}</li>", '').'</ul>', | ||
]; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/Scribe/Strategies/Documentations/Filters/NumberFilter.php
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,40 @@ | ||
<?php | ||
|
||
namespace TeamQ\Datatables\Scribe\Strategies\Documentations\Filters; | ||
|
||
use Illuminate\Support\Collection; | ||
use Spatie\QueryBuilder\Filters\Filter; | ||
use Spatie\QueryBuilder\Sorts\Sort; | ||
use TeamQ\Datatables\Enums\Comparators\Number; | ||
use TeamQ\Datatables\Scribe\Strategies\Documentations\Documentation; | ||
|
||
class NumberFilter extends Documentation | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __invoke(Filter|Sort|Collection|string $param, mixed $value = null, ?string $name = null): array | ||
{ | ||
$operators = collect(Number::cases()) | ||
->map(fn (Number $operator) => "<li>{$operator->value} - {$operator->name}</li>") | ||
->join(''); | ||
|
||
return [ | ||
'name' => $name, | ||
'type' => 'string', | ||
'required' => false, | ||
'description' => "<div>Number Filter. It belongs to a type of advanced filter, it allows filtering according to operators. Can receive different payload: | ||
<ul> | ||
<li><b>{$name}=20</b><br>It is evaluated by equals.</li> | ||
<li><b>{$name}[value]=20</b><br>It is evaluated by equals.</li> | ||
<li><b>{$name}[value]=20&{$name}[operator]=5</b><br>It is evaluated by operator 5 (LessThan).</li> | ||
<li><b>{$name}[value][0]=20&{$name}[value][1]=20&{$name}[operator]=5</b><br>It is evaluated by operator 7 (Between). This operator will only take the first two 'values' however operators like 'In' will take the entire array of 'values'.</li> | ||
</ul> | ||
Valid comparison operators are: | ||
<ul> | ||
$operators | ||
</ul> | ||
</div>", | ||
]; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/Scribe/Strategies/Documentations/Filters/PartialFilter.php
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,25 @@ | ||
<?php | ||
|
||
namespace TeamQ\Datatables\Scribe\Strategies\Documentations\Filters; | ||
|
||
use Illuminate\Support\Collection; | ||
use Spatie\QueryBuilder\Filters\Filter; | ||
use Spatie\QueryBuilder\Sorts\Sort; | ||
use TeamQ\Datatables\Scribe\Strategies\Documentations\Documentation; | ||
|
||
class PartialFilter extends Documentation | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __invoke(Filter|Sort|Collection|string $param, mixed $value = null, ?string $name = null): array | ||
{ | ||
return [ | ||
'name' => $name, | ||
'type' => 'string', | ||
'required' => false, | ||
'description' => 'Partial Filter. It is evaluated as: The field contains this value.', | ||
// 'example' => str($value)->substr(2, 5) ?: str()->words(2)->lower(), | ||
]; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/Scribe/Strategies/Documentations/Filters/TextFilter.php
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,39 @@ | ||
<?php | ||
|
||
namespace TeamQ\Datatables\Scribe\Strategies\Documentations\Filters; | ||
|
||
use Illuminate\Support\Collection; | ||
use Spatie\QueryBuilder\Filters\Filter; | ||
use Spatie\QueryBuilder\Sorts\Sort; | ||
use TeamQ\Datatables\Enums\Comparators\Text; | ||
use TeamQ\Datatables\Scribe\Strategies\Documentations\Documentation; | ||
|
||
class TextFilter extends Documentation | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __invoke(Filter|Sort|Collection|string $param, mixed $value = null, ?string $name = null): array | ||
{ | ||
$operators = collect(Text::cases()) | ||
->map(fn (Text $operator) => "<li>{$operator->value} - {$operator->name}</li>") | ||
->join(''); | ||
|
||
return [ | ||
'name' => $name, | ||
'type' => 'string', | ||
'required' => false, | ||
'description' => "<div>Text Filter. It belongs to a type of advanced filter, it allows filtering according to operators. Can receive different payload: | ||
<ul> | ||
<li><b>{$name}=Luis</b> It is evaluated by equals.</li> | ||
<li><b>{$name}[value]=Luis</b> It is evaluated by equals.</li> | ||
<li><b>{$name}[value]=Luis&{$name}[operator]=5</b> It is evaluated by operator 5 (EndWith).</li> | ||
</ul> | ||
Valid comparison operators are: | ||
<ul> | ||
$operators | ||
</ul> | ||
</div>", | ||
]; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Scribe/Strategies/Documentations/Filters/TrashedFilter.php
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,30 @@ | ||
<?php | ||
|
||
namespace TeamQ\Datatables\Scribe\Strategies\Documentations\Filters; | ||
|
||
use Illuminate\Support\Collection; | ||
use Spatie\QueryBuilder\Filters\Filter; | ||
use Spatie\QueryBuilder\Sorts\Sort; | ||
use TeamQ\Datatables\Scribe\Strategies\Documentations\Documentation; | ||
|
||
class TrashedFilter extends Documentation | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function __invoke(Filter|Sort|Collection|string $param, mixed $value = null, ?string $name = null): array | ||
{ | ||
return [ | ||
'name' => $name, | ||
'type' => 'string', | ||
'required' => false, | ||
'description' => 'Trashed Filter. For soft deleted records. The accepted values are: | ||
<ul> | ||
<li><b>with:</b> With deleted records.</li> | ||
<li><b>only:</b> Only deleted records.</li> | ||
<li><b>without:</b> Without deleted records.</li> | ||
</ul>', | ||
'example' => 'only', | ||
]; | ||
} | ||
} |
Oops, something went wrong.