-
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.
Showing
24 changed files
with
200 additions
and
64 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
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,3 +1,3 @@ | ||
<?php | ||
|
||
(require __DIR__ . '/../config/bootstrap.php')->run(); | ||
(require __DIR__ . '/../config/bootstrap.php')->run(); |
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
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,26 @@ | ||
<?php | ||
|
||
namespace App\Service\Rice; | ||
|
||
use App\Repository\Example\RiceRespository; | ||
use App\Service\Service; | ||
use Illuminate\Database\Eloquent\Collection; | ||
|
||
class RiceService extends Service | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
#[\Override] protected function getRepositoryClass(): string | ||
{ | ||
return RiceRespository::class; | ||
} | ||
|
||
/** | ||
* @return Collection|array | ||
*/ | ||
public function all(): Collection|array | ||
{ | ||
return $this->getRepository()->all(); | ||
} | ||
} |
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,97 @@ | ||
<?php | ||
|
||
namespace App\Service; | ||
|
||
use App\App; | ||
use App\Slim\Repository\Repository; | ||
use App\Slim\Repository\RepositoryManager; | ||
use DI\DependencyException; | ||
use DI\NotFoundException; | ||
use DomainException; | ||
use Illuminate\Database\ConnectionInterface; | ||
use Psr\Container\ContainerExceptionInterface; | ||
use Psr\Container\NotFoundExceptionInterface; | ||
use Throwable; | ||
|
||
|
||
abstract class Service | ||
{ | ||
/** | ||
* @var RepositoryManager | ||
*/ | ||
private RepositoryManager $repositoryManager; | ||
|
||
/** | ||
* @throws DependencyException | ||
* @throws NotFoundException | ||
* @throws ContainerExceptionInterface | ||
* @throws NotFoundExceptionInterface | ||
*/ | ||
public function __construct() | ||
{ | ||
$this->repositoryManager = App::container()->get(RepositoryManager::class); | ||
} | ||
|
||
/** | ||
* @param string|null $repositoryClass | ||
* @return Repository | ||
*/ | ||
final public function getRepository(string $repositoryClass = null): Repository | ||
{ | ||
if (!$repositoryClass) { | ||
$repositoryClass = $this->getRepositoryClass(); | ||
} | ||
|
||
return $this->repositoryManager->get($repositoryClass); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function getRepositoryClass(): string | ||
{ | ||
throw new DomainException( | ||
"Override the method 'getRepositoryClass' providing the corresponding class!" | ||
); | ||
} | ||
|
||
/** | ||
* @throws Throwable | ||
*/ | ||
final protected function beginTransaction(): void | ||
{ | ||
$this->getConnection()->beginTransaction(); | ||
} | ||
|
||
/** | ||
* @return ConnectionInterface | ||
*/ | ||
final protected function getConnection(): ConnectionInterface | ||
{ | ||
return $this->repositoryManager->getConnection(); | ||
} | ||
|
||
/** | ||
* @throws Throwable | ||
*/ | ||
final protected function rollBack(): void | ||
{ | ||
$this->getConnection()->rollBack(); | ||
} | ||
|
||
/** | ||
* @throws Throwable | ||
*/ | ||
final protected function commit(): void | ||
{ | ||
$this->getConnection()->commit(); | ||
} | ||
|
||
/** | ||
* @return RepositoryManager | ||
*/ | ||
final protected function getRepositoryManager(): RepositoryManager | ||
{ | ||
return $this->repositoryManager; | ||
} | ||
} |
Oops, something went wrong.