Skip to content

Commit

Permalink
:feature:
Browse files Browse the repository at this point in the history
- Completly removing of Business concept
  • Loading branch information
gabrielpcruz committed Feb 14, 2024
1 parent bbf2084 commit c525445
Show file tree
Hide file tree
Showing 24 changed files with 200 additions and 64 deletions.
4 changes: 2 additions & 2 deletions config/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
$rootPath = $settings->get('view.path');
$templates = $settings->get('view.templates');
$viewSettings = $settings->get('view.settings');
$twigExtensionsPath = $settings->get('path.twig');
$twigExtensionsPath = $settings->get('path.slim.twig');

$loader = new FilesystemLoader([], $rootPath);

Expand All @@ -75,7 +75,7 @@

$extensions = \App\Slim\Directory\Directory::turnNameSpacePathIntoArray(
$twigExtensionsPath,
"App\Twig\\"
"\\App\\Slim\\Twig\\"
);

$twig->addExtension(new DebugExtension());
Expand Down
6 changes: 3 additions & 3 deletions config/database/connections/default.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

return [
'driver' => 'mysql',
'host' => '192.168.1.11:9905',
'database' => 'slim',
'driver' => 'sqlite',
'host' => 'localhost',
'database' => STORAGE_PATH . '/database/db.sqlite',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
Expand Down
4 changes: 2 additions & 2 deletions config/enviroment/settings_default.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@
],
'migration' => ROOT_PATH . '/src/Slim/Migration',
'seeder' => ROOT_PATH . '/src/Slim/Seeder',
'twig' => ROOT_PATH . '/src/Slim/Twig',
],
'provider' => ROOT_PATH . '/src/Slim/Provider',
'repository' => ROOT_PATH . '/src/Repository',
'entity' => ROOT_PATH . '/src/Entity',
'twig' => ROOT_PATH . '/src/Twig',
'files' => [
'images' => ROOT_PATH . '/storage/images'
],
Expand Down Expand Up @@ -92,7 +92,7 @@
];

$settings['error'] = [
'slashtrace' => 0, // Exibir erros na tela
'slashtrace' => 1, // Exibir erros na tela
'error_reporting' => 1,
'display_errors' => 1,
'display_startup_errors' => 1,
Expand Down
6 changes: 3 additions & 3 deletions config/enviroment/settings_development.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

$developmentSettings['error'] = [
'slashtrace' => 0,
'error_reporting' => 0,
'display_errors' => 0,
'display_startup_errors' => 0,
'error_reporting' => 1,
'display_errors' => 1,
'display_startup_errors' => 1,
];

$developmentSettings['view'] = [
Expand Down
10 changes: 5 additions & 5 deletions config/enviroment/settings_homologation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
$homologationSettings = [];

$homologationSettings['error'] = [
'slashtrace' => 0,
'error_reporting' => 0,
'display_errors' => 0,
'display_startup_errors' => 0,
'slashtrace' => 1,
'error_reporting' => 1,
'display_errors' => 1,
'display_startup_errors' => 1,
];

$homologationSettings['view'] = [
Expand All @@ -18,4 +18,4 @@
],
];

return $homologationSettings;
return $homologationSettings;
2 changes: 1 addition & 1 deletion public/index.php
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();
1 change: 0 additions & 1 deletion resources/helpers/slim.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ function slugify($text, string $divider = '-'): string
if (!function_exists('dd')) {
#[NoReturn] function dd($expression): void
{

var_dump($expression);
die;
}
Expand Down
9 changes: 8 additions & 1 deletion resources/views/error/500/index.twig
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@
<div class="row mt-4">
<div class="col">
<div class="alert alert-danger text-center">
<h2><i class="fa-solid fa-triangle-exclamation"></i> Sorry, our servers presenting some errors.</h2>
<h2>
<i class="fa-solid fa-triangle-exclamation"></i>
Sorry, our servers presenting some errors.
</h2>
</div>
</div>

<div class="col">
{{ message }}
</div>
</div>

{% endblock %}
12 changes: 12 additions & 0 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public static function bootstrap(): SlimApp
$settings = self::settings();

self::defineConstants($settings);
self::cacheRoutes($app);

self::provide($container, $settings);

$errorMiddleware = $app->addErrorMiddleware(true, true, true);
Expand All @@ -213,6 +215,16 @@ private static function getContainer(): Container
return self::$container;
}

/**
* @param mixed $app
* @return void
*/
public static function cacheRoutes(mixed $app): void
{
$routeCollector = $app->getRouteCollector();
$routeCollector->setCacheFile(STORAGE_PATH . '/cache/slim/routes.slim');
}

/**
* @param Container $container
* @param Dot $settings
Expand Down
3 changes: 2 additions & 1 deletion src/Http/Api/Home/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Api\Home;

use App\Repository\Example\RiceRespository;
use App\Service\Rice\RiceService;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use App\Slim\Http\Api\ApiController;
Expand All @@ -16,7 +17,7 @@ class Home extends ApiController
*/
public function index(Request $request, Response $response): Response
{
$riceRepository = new RiceRespository();
$riceRepository = new RiceService();

$this->payloadResponse()->data = $riceRepository->all()->toArray();

Expand Down
3 changes: 2 additions & 1 deletion src/Http/Site/Auth/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ public function index(Request $request, Response $response): Response
* @param Response $response
* @return Response
* @throws ContainerExceptionInterface
* @throws DependencyException
* @throws NotFoundException
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/
public function login(Request $request, Response $response): Response
{
Expand Down
10 changes: 5 additions & 5 deletions src/Http/Site/Home/Home.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Http\Site\Home;

use App\Repository\Example\RiceRespository;
use App\Service\Rice\RiceService;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use App\Slim\Http\Site\SiteController;
Expand All @@ -22,9 +22,9 @@ class Home extends SiteController
*/
public function index(Request $request, Response $response): Response
{
$riceRepository = new RiceRespository();
$riceService = new RiceService();

$rices = $riceRepository->all($request)->toArray();
$rices = $riceService->all($request)->toArray();

return $this->view(
$response,
Expand All @@ -43,9 +43,9 @@ public function index(Request $request, Response $response): Response
*/
public function logged(Request $request, Response $response): Response
{
$riceRepository = new RiceRespository();
$riceService = new RiceService();

$rices = $riceRepository->all($request)->toArray();
$rices = $riceService->all()->toArray();

return $this->view(
$response,
Expand Down
3 changes: 1 addition & 2 deletions src/Repository/User/ClientRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public function validateClient($clientIdentifier, $clientSecret, $grantType): bo

/**
* @param array $data
*
* @return null|false|mixed|UserEntityInterface
* @return mixed
*/
public function getClientEntityByCredentials(array $data): mixed
{
Expand Down
26 changes: 26 additions & 0 deletions src/Service/Rice/RiceService.php
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();
}
}
97 changes: 97 additions & 0 deletions src/Service/Service.php
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;
}
}
Loading

0 comments on commit c525445

Please sign in to comment.