-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Return repository key on filters. * Apply fixes from StyleCI (#307) * Adding filter definition. * Apply fixes from StyleCI (#308) * docs * Map into qualified classes. * Apply fixes from StyleCI (#309) * wip
- Loading branch information
Showing
16 changed files
with
509 additions
and
185 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Binaryk\LaravelRestify\Commands; | ||
|
||
use Illuminate\Console\ConfirmableTrait; | ||
use Illuminate\Console\GeneratorCommand; | ||
use Illuminate\Support\Str; | ||
|
||
class FilterCommand extends GeneratorCommand | ||
{ | ||
use ConfirmableTrait; | ||
|
||
protected $name = 'restify:filter'; | ||
|
||
protected $description = 'Create a new filter class'; | ||
|
||
protected $type = 'Filter'; | ||
|
||
public function handle() | ||
{ | ||
if (parent::handle() === false && ! $this->option('force')) { | ||
return false; | ||
} | ||
} | ||
|
||
/** | ||
* Build the class with the given name. | ||
* This method should return the file class content. | ||
* | ||
* @param string $name | ||
* @return string | ||
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException | ||
*/ | ||
protected function buildClass($name) | ||
{ | ||
if (false === Str::endsWith($name, 'Filter')) { | ||
$name .= 'Filter'; | ||
} | ||
|
||
return tap(parent::buildClass($name), function ($stub) use ($name) { | ||
return str_replace(['{{ attribute }}', '{{ query }}'], Str::snake( | ||
Str::beforeLast(class_basename($name), 'Filter') | ||
), $stub); | ||
}); | ||
} | ||
|
||
protected function getStub() | ||
{ | ||
return __DIR__.'/stubs/filter.stub'; | ||
} | ||
|
||
protected function getPath($name) | ||
{ | ||
if (false === Str::endsWith($name, 'Filter')) { | ||
$name .= 'Filter'; | ||
} | ||
|
||
return parent::getPath($name); | ||
} | ||
|
||
protected function getDefaultNamespace($rootNamespace) | ||
{ | ||
return $rootNamespace.'\Restify\Matchers'; | ||
} | ||
} |
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,14 @@ | ||
<?php | ||
|
||
namespace DummyNamespace; | ||
|
||
use Binaryk\LaravelRestify\Filter; | ||
use Binaryk\LaravelRestify\Http\Requests\RestifyRequest; | ||
|
||
class DummyClass extends Filter | ||
{ | ||
public function filter(RestifyRequest $request, $query, $value) | ||
{ | ||
// $query->where('{{ attribute }}', $request->input('{{ query }}')); | ||
} | ||
} |
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,49 @@ | ||
<?php | ||
|
||
namespace Binaryk\LaravelRestify\Filters; | ||
|
||
use Binaryk\LaravelRestify\Repositories\Repository; | ||
use Binaryk\LaravelRestify\Restify; | ||
use JsonSerializable; | ||
|
||
abstract class FilterDefinition implements JsonSerializable | ||
{ | ||
public static string $type = 'string'; | ||
|
||
public static string $relatedRepositoryKey; | ||
|
||
public function getType(): string | ||
{ | ||
return static::$type; | ||
} | ||
|
||
public function getRelatedRepositoryKey(): ?string | ||
{ | ||
return static::$relatedRepositoryKey; | ||
} | ||
|
||
public function getRelatedRepositoryUrl(): ?string | ||
{ | ||
return ($key = $this->getRelatedRepositoryKey()) | ||
? with(Restify::repositoryForKey($key), function ($repository = null) { | ||
if (is_subclass_of($repository, Repository::class)) { | ||
return Restify::path($repository::uriKey()); | ||
} | ||
}) | ||
: null; | ||
} | ||
|
||
public function jsonSerialize() | ||
{ | ||
return with([ | ||
'type' => $this->getType(), | ||
], function (array $initial) { | ||
return static::$relatedRepositoryKey | ||
? array_merge($initial, [ | ||
'related_repository_key' => $this->getRelatedRepositoryKey(), | ||
'related_repository_url' => $this->getRelatedRepositoryUrl(), | ||
]) | ||
: $initial; | ||
}); | ||
} | ||
} |
Oops, something went wrong.