Skip to content

Commit

Permalink
Merge pull request #7 from maurobonfietti/0.9.0
Browse files Browse the repository at this point in the history
Version 0.9.0
  • Loading branch information
maurobonfietti committed Apr 25, 2020
2 parents 4cc0eab + b895288 commit 677ea6e
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/Command/CrudGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class CrudGeneratorCommand extends Command
{
const COMMAND_VERSION = '0.8.0';
const COMMAND_VERSION = '0.9.0';

public function __construct($app)
{
Expand All @@ -23,7 +23,7 @@ protected function configure()
{
$this->setName('api:generate:endpoints')
->setDescription('Given an entity, auto-generate a simple CRUD endpoints.')
->setHelp('This command generate a CRUD to manage any simple entity/table, in a RESTful API. Version: ' . self::COMMAND_VERSION)
->setHelp('This command generate a CRUD services to manage any simple entity/table, in a RESTful API. Version: ' . self::COMMAND_VERSION)
->addArgument(
'entity',
InputArgument::REQUIRED,
Expand Down
4 changes: 2 additions & 2 deletions src/Command/CrudGeneratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private function updateRoutes()
private function updateRepository()
{
$repository = '
$container["'.$this->entity.'_repository"] = function ($container): App\Repository\\'.$this->entityUpper.'Repository {
$container["'.$this->entity.'_repository"] = static function ($container): App\Repository\\'.$this->entityUpper.'Repository {
return new App\Repository\\'.$this->entityUpper.'Repository($container["db"]);
};
';
Expand All @@ -142,7 +142,7 @@ private function updateRepository()
private function updateServices()
{
$service = '
$container["'.$this->entity.'_service"] = function ($container): App\Service\\'.$this->entityUpper.'Service {
$container["'.$this->entity.'_service"] = static function ($container): App\Service\\'.$this->entityUpper.'Service {
return new App\Service\\'.$this->entityUpper.'Service($container["'.$this->entity.'_repository"]);
};
';
Expand Down
7 changes: 4 additions & 3 deletions src/Command/TemplateBase/Objectbase/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
namespace App\Controller\Objectbase;

use App\Service\ObjectbaseService;
use Pimple\Psr11\Container;

abstract class Base
{
protected $container;
protected Container $container;

protected $objectbaseService;
protected ObjectbaseService $objectbaseService;

public function __construct($container)
public function __construct(Container $container)
{
$this->container = $container;
}
Expand Down
7 changes: 5 additions & 2 deletions src/Command/TemplateBase/Objectbase/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

namespace App\Controller\Objectbase;

class Create extends Base
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

final class Create extends Base
{
public function __invoke($request, $response)
public function __invoke(Request $request, Response $response): Response
{
$input = $request->getParsedBody();
$objectbase = $this->getObjectbaseService()->create($input);
Expand Down
7 changes: 5 additions & 2 deletions src/Command/TemplateBase/Objectbase/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

namespace App\Controller\Objectbase;

class Delete extends Base
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

final class Delete extends Base
{
public function __invoke($request, $response, array $args)
public function __invoke(Request $request, Response $response, array $args): Response
{
$this->getObjectbaseService()->delete((int) $args['id']);

Expand Down
7 changes: 5 additions & 2 deletions src/Command/TemplateBase/Objectbase/GetAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

namespace App\Controller\Objectbase;

class GetAll extends Base
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

final class GetAll extends Base
{
public function __invoke($request, $response)
public function __invoke(Request $request, Response $response): Response
{
$objectbases = $this->getObjectbaseService()->getAll();

Expand Down
7 changes: 5 additions & 2 deletions src/Command/TemplateBase/Objectbase/GetOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

namespace App\Controller\Objectbase;

class GetOne extends Base
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

final class GetOne extends Base
{
public function __invoke($request, $response, array $args)
public function __invoke(Request $request, Response $response, array $args): Response
{
$objectbase = $this->getObjectbaseService()->getOne((int) $args['id']);

Expand Down
7 changes: 5 additions & 2 deletions src/Command/TemplateBase/Objectbase/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@

namespace App\Controller\Objectbase;

class Update extends Base
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;

final class Update extends Base
{
public function __invoke($request, $response, array $args)
public function __invoke(Request $request, Response $response, array $args): Response
{
$input = $request->getParsedBody();
$objectbase = $this->getObjectbaseService()->update($input, (int) $args['id']);
Expand Down
2 changes: 1 addition & 1 deletion src/Command/TemplateBase/ObjectbaseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

namespace App\Exception;

class ObjectbaseException extends BaseException
final class ObjectbaseException extends BaseException
{
}
8 changes: 4 additions & 4 deletions src/Command/TemplateBase/ObjectbaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use App\Exception\ObjectbaseException;

class ObjectbaseRepository extends BaseRepository
final class ObjectbaseRepository extends BaseRepository
{
public function __construct(\PDO $database)
{
Expand Down Expand Up @@ -36,17 +36,17 @@ public function getAll(): array
return $statement->fetchAll();
}

public function create($objectbase)
public function create(object $objectbase)
{
#createFunction
}

public function update($objectbase, $data)
public function update(object $objectbase, object $data)
{
#updateFunction
}

public function delete(int $objectbaseId)
public function delete(int $objectbaseId): void
{
$query = 'DELETE FROM `objectbase` WHERE `id` = :id';
$statement = $this->getDb()->prepare($query);
Expand Down
8 changes: 4 additions & 4 deletions src/Command/TemplateBase/ObjectbaseService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use App\Exception\ObjectbaseException;
use App\Repository\ObjectbaseRepository;

class ObjectbaseService extends BaseService
final class ObjectbaseService extends BaseService
{
protected $objectbaseRepository;
protected ObjectbaseRepository $objectbaseRepository;

public function __construct(ObjectbaseRepository $objectbaseRepository)
{
Expand All @@ -31,7 +31,7 @@ public function getOne(int $objectbaseId)
return $this->checkAndGet($objectbaseId);
}

public function create($input)
public function create(array $input)
{
$objectbase = json_decode(json_encode($input), false);

Expand All @@ -46,7 +46,7 @@ public function update(array $input, int $objectbaseId)
return $this->objectbaseRepository->update($objectbase, $data);
}

public function delete(int $objectbaseId)
public function delete(int $objectbaseId): void
{
$this->checkAndGet($objectbaseId);
$this->objectbaseRepository->delete($objectbaseId);
Expand Down

0 comments on commit 677ea6e

Please sign in to comment.