-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(matches): improved match object
- Loading branch information
1 parent
35d8020
commit 64f25c2
Showing
27 changed files
with
461 additions
and
120 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,24 +1,25 @@ | ||
<?php | ||
|
||
use Ninja\Censor\Checkers\Contracts\ProfanityChecker; | ||
use Ninja\Censor\Actions\CheckAction; | ||
use Ninja\Censor\Actions\CleanAction; | ||
use Ninja\Censor\Result\Contracts\Result; | ||
|
||
if (! function_exists('is_offensive')) { | ||
function is_offensive(string $text): bool | ||
{ | ||
/** @var ProfanityChecker $service */ | ||
$service = app(ProfanityChecker::class); | ||
/** @var Result $result */ | ||
$result = CheckAction::run($text); | ||
|
||
return $service->check($text)->offensive(); | ||
return $result->offensive(); | ||
} | ||
} | ||
|
||
if (! function_exists('clean')) { | ||
function clean(string $text): string | ||
{ | ||
/** @var ProfanityChecker $service */ | ||
$service = app(ProfanityChecker::class); | ||
|
||
return $service->check($text)->replaced(); | ||
/** @var string $result */ | ||
$result = CleanAction::run($text); | ||
|
||
return $result; | ||
} | ||
} |
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,7 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Route; | ||
use Ninja\Censor\Actions\CheckAction; | ||
|
||
Route::post('censor/check', CheckAction::class) | ||
->name('censor.check'); |
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,38 @@ | ||
<?php | ||
|
||
namespace Ninja\Censor\Actions; | ||
|
||
use Illuminate\Http\Request; | ||
use Lorisleiva\Actions\Concerns\AsAction; | ||
use Ninja\Censor\Checkers\Contracts\ProfanityChecker; | ||
use Ninja\Censor\Http\Resources\CensorResultResource; | ||
use Ninja\Censor\Result\Contracts\Result; | ||
|
||
final readonly class CheckAction | ||
{ | ||
use AsAction; | ||
|
||
public function __construct(private ProfanityChecker $checker) {} | ||
|
||
public function handle(string $text): Result | ||
{ | ||
return $this->checker->check($text); | ||
} | ||
|
||
public function asController(Request $request): Result | ||
{ | ||
if (! $request->has('text')) { | ||
abort(400, 'Missing text parameter'); | ||
} | ||
|
||
/** @var string $text */ | ||
$text = $request->input('text'); | ||
|
||
return $this->handle($text); | ||
} | ||
|
||
public function jsonResponse(Result $result): CensorResultResource | ||
{ | ||
return new CensorResultResource($result); | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace Ninja\Censor\Actions; | ||
|
||
use Lorisleiva\Actions\Concerns\AsAction; | ||
use Ninja\Censor\Checkers\Contracts\ProfanityChecker; | ||
|
||
final readonly class CleanAction | ||
{ | ||
use AsAction; | ||
|
||
public function __construct(private ProfanityChecker $checker) {} | ||
|
||
public function handle(string $text): string | ||
{ | ||
return $this->checker->check($text)->replaced(); | ||
} | ||
} |
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,7 @@ | ||
<?php | ||
|
||
namespace Ninja\Censor\Detection\Strategy; | ||
|
||
use Ninja\Censor\Detection\Contracts\DetectionStrategy; | ||
|
||
abstract class AbstractStrategy implements DetectionStrategy {} |
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
Oops, something went wrong.