-
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.
- Loading branch information
1 parent
3cae73c
commit f59ec60
Showing
2 changed files
with
64 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Blumilk\BLT\Helpers; | ||
|
||
use Illuminate\Support\Str; | ||
|
||
class RecognizeClassHelper | ||
{ | ||
public static function recognizeObjectClass(string $objectName): string | ||
{ | ||
if (strpos($objectName, "\\")) { | ||
return $objectName; | ||
} | ||
|
||
$objectName = Str::ucfirst(Str::singular($objectName)); | ||
|
||
return self::getObjectNamespace($objectName) . $objectName; | ||
} | ||
|
||
public static function getObjectNamespace(string $objectName): string | ||
{ | ||
$type = Str::plural(self::guessType($objectName)); | ||
|
||
return "App\\$type\\"; | ||
} | ||
|
||
public static function guessType(string $objectName): string | ||
{ | ||
foreach (TypesEnum::cases() as $objectType) { | ||
$slug = Str::slug($objectName); | ||
$objectTypeName = $objectType->value; | ||
|
||
if (Str::contains($slug, $objectTypeName)) { | ||
return Str::ucfirst(Str::singular($objectTypeName)); | ||
} | ||
} | ||
|
||
return $objectName; | ||
} | ||
} |
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Blumilk\BLT\Helpers; | ||
|
||
enum TypesEnum: string | ||
{ | ||
case MODEL = "model"; | ||
case JOB = "job"; | ||
case POLICY = "policy"; | ||
case REQUEST = "request"; | ||
case RESOURCE = "resource"; | ||
case SEEDER = "seeder"; | ||
case ENUM = "enum"; | ||
case EVENT = "event"; | ||
case LISTENER = "listener"; | ||
case MIDDLEWARE = "middleware"; | ||
case NOTIFICATION = "notification"; | ||
case PROVIDER = "provider"; | ||
case SERVICE = "service"; | ||
} |