-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add resource not found exception #222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 5 commits
9b3ef0d
360ec8b
f246aa0
e2bd53a
015df73
3137a00
76dd206
c6caf86
f6533e4
1112e91
03dba02
f0faf0e
aba9541
54209c1
318cd18
a85e956
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?php | ||
|
|
||
| namespace RonasIT\Support\Exceptions; | ||
|
|
||
| use Exception; | ||
| use Illuminate\Support\Str; | ||
|
|
||
| abstract class AbstractResourceException extends Exception | ||
| { | ||
| protected function getEntity(string $filePath): string | ||
| { | ||
| $fileName = Str::afterLast($filePath, '/'); | ||
|
|
||
| return Str::before($fileName, '.php'); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?php | ||
|
|
||
| namespace RonasIT\Support\Exceptions; | ||
|
|
||
| class ResourceNotExistsException extends AbstractResourceException | ||
| { | ||
| public function __construct( | ||
| string $entity, | ||
artengin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| string $filePath, | ||
artengin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) { | ||
| $resource = $this->getEntity($filePath); | ||
|
|
||
| parent::__construct("Cannot create {$entity} cause {$resource} does not exist. Create {$filePath} and run command again."); | ||
| } | ||
| } | ||
artengin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |
| use RonasIT\Support\Events\WarningEvent; | ||
| use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
| use RonasIT\Support\Exceptions\ClassNotExistsException; | ||
|
||
| use RonasIT\Support\Exceptions\ResourceNotExistsException; | ||
| use RonasIT\Support\Exceptions\IncorrectClassPathException; | ||
| use RonasIT\Support\Exceptions\ResourceAlreadyExistsException; | ||
|
|
||
|
|
@@ -328,4 +329,13 @@ protected function checkResourceExists(string $path, string $resourceName, ?stri | |
| throw new ResourceAlreadyExistsException($filePath); | ||
| } | ||
| } | ||
|
|
||
| protected function checkResourceNotExists(string $path, string $entity, string $resourceName, ?string $subFolder = null): void | ||
artengin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| if (!$this->classExists($path, $resourceName, $subFolder)) { | ||
| $filePath = $this->getClassPath($path, $resourceName, $subFolder); | ||
|
|
||
| throw new ResourceNotExistsException($entity, $filePath); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.