- New code generation made for CLI
This commit is contained in:
1 parent
ae212a4377
commit
c3e3d6a73a
22 files changed
+1067
-17
No files matched your search
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace %NAMESPACE%\%API_NS%;
|
||||
|
||||
use Notes\Attribute\Ignore;
|
||||
use Notes\Route\Attribute\Method\Route;
|
||||
use Psr\Http\Message\{ ServerRequestInterface, ResponseInterface };
|
||||
|
||||
use %NAMESPACE%\{Lib, %USE_ENTITY_NS%, %USE_FORM_NS%, };
|
||||
use function %NAMESPACE%\View\{_, lang, url, route, form};
|
||||
|
||||
#[\Notes\Route\Attribute\Object\Route(base:"%API_ROUTE_BASE%/%CLASSNAME_LC%")]
|
||||
class %CLASSNAME% {
|
||||
use Lib\ApiTrait;
|
||||
|
||||
#[Route(route: "/documentation", name: "api.%CLASSNAME_LC%:docs", method: "GET")]
|
||||
public function index(ServerRequestInterface $request, array $attributes): ResponseInterface
|
||||
{
|
||||
return $this->renderMarkdown(getenv("PROJECT_PATH") . "/meta/docs/%CLASSNAME_LC%.md", [ %ENTITY_NS%\%CLASSNAME%::class, ], [ %FORM_NS%\%SAVE_FORM_CONTEXT_CLASSNAME%::class, %FORM_NS%\%DELETE_FORM_CONTEXT_CLASSNAME%::class ]);
|
||||
}
|
||||
|
||||
#[Route("/", name: "api.%CLASSNAME_LC%:list", method: "GET")]
|
||||
public function list(ServerRequestInterface $request, array $attributes) : ResponseInterface
|
||||
{
|
||||
$request = $this->searchEntitiesFromRequest($request, %ENTITY_NS%\%CLASSNAME%::class);
|
||||
$result = $request->getAttribute("lean.searchRequest")[%ENTITY_NS%\%CLASSNAME%::class];
|
||||
|
||||
return $this->outputSearchResult($result);
|
||||
}
|
||||
|
||||
#[Route("/", name: "api.%CLASSNAME_LC%:add", method: "POST")]
|
||||
public function add(ServerRequestInterface $request, array $attributes) : ResponseInterface
|
||||
{
|
||||
$entity = new %ENTITY_NS%\%CLASSNAME%();
|
||||
|
||||
form($this->formFactory->%SAVE_FORM_CLASSNAME_LC%($entity), $this->formFactory->%SAVE_FORM_CONTEXT_CLASSNAME_LC%($request));
|
||||
|
||||
return $this->output($entity, (int) $entity->isLoaded());
|
||||
}
|
||||
|
||||
#[Route("/{id:\d+}", name: "api.%CLASSNAME_LC%:single", method: "GET")]
|
||||
#[Route("/{id:\d+}", name: "api.%CLASSNAME_LC%:edit", method: "PATCH")]
|
||||
public function single(ServerRequestInterface $request, array $attributes) : ResponseInterface
|
||||
{
|
||||
$request = $this->searchEntityFromRequest($request, %ENTITY_NS%\%CLASSNAME%::class);
|
||||
$result = $request->getAttribute("lean.searchRequest")[%ENTITY_NS%\%CLASSNAME%::class];
|
||||
|
||||
form($this->formFactory->%SAVE_FORM_CLASSNAME_LC%($result->getResult()), $this->formFactory->%SAVE_FORM_CONTEXT_CLASSNAME_LC%($request));
|
||||
|
||||
return $this->outputSearchResult($result);
|
||||
}
|
||||
|
||||
#[Route("/{id:\d+}", name: "api.%CLASSNAME_LC%:delete", method: "DELETE")]
|
||||
public function delete(ServerRequestInterface $request, array $attributes) : ResponseInterface
|
||||
{
|
||||
$request = $this->searchEntityFromRequest($request, %ENTITY_NS%\%CLASSNAME%::class);
|
||||
$result = $request->getAttribute("lean.searchRequest")[%ENTITY_NS%\%CLASSNAME%::class];
|
||||
|
||||
form($this->formFactory->%DELETE_FORM_CLASSNAME_LC%($result->getResult()), $this->formFactory->%DELETE_FORM_CONTEXT_CLASSNAME_LC%($request));
|
||||
|
||||
return $this->outputSearchResult($result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace %NAMESPACE%\%WEB_NS%;
|
||||
|
||||
use Notes\Breadcrumb\Attribute\Method\Breadcrumb;
|
||||
use Notes\Route\Attribute\Method\Route;
|
||||
|
||||
use Psr\Http\Message\ServerRequestInterface,
|
||||
Psr\Http\Message\ResponseInterface;
|
||||
|
||||
use %NAMESPACE%\{Lib, %USE_ENTITY_NS%, %USE_FORM_NS%, };
|
||||
|
||||
use function %NAMESPACE%\View\{_, lang, url, route, form};
|
||||
|
||||
#[\Notes\Route\Attribute\Object\Route(base:"%WEB_ROUTE_BASE%/%CLASSNAME_LC%")]
|
||||
class %CLASSNAME% {
|
||||
use Lib\ControllerTrait;
|
||||
|
||||
#[Route("/", name: "%CLASSNAME_LC%:index")]
|
||||
##[Breadcrumb(parent: "", icon: "", lang: "app.lang.breadcrumb")]
|
||||
public function index(ServerRequestInterface $request, array $arguments) : ResponseInterface
|
||||
{
|
||||
$search = %ENTITY_NS%\%CLASSNAME%::searchRequest()->fromRequest($request) ;
|
||||
$list = %ENTITY_NS%\%CLASSNAME%::repository()->filterServerRequest($search)->loadAll();
|
||||
|
||||
return $this->renderView('%CLASSNAME_LC%/index', get_defined_vars());
|
||||
}
|
||||
|
||||
#[Route("/create", name: "%CLASSNAME_LC%:create", method: ["GET", "POST"])]
|
||||
##[Breadcrumb(parent: "%CLASSNAME_LC%:index", icon: "", lang: "app.lang.breadcrumb")]
|
||||
public function create(ServerRequestInterface $request, array $arguments) : ResponseInterface
|
||||
{
|
||||
$entity = new %ENTITY_NS%\%CLASSNAME%();
|
||||
|
||||
form($this->formFactory->%SAVE_FORM_CLASSNAME_LC%($entity), $this->pushContext($this->formFactory->%SAVE_FORM_CONTEXT_CLASSNAME_LC%($request, "%CLASSNAME_LC%.create")));
|
||||
|
||||
if ($entity->isLoaded()) {
|
||||
return $this->redirect(route("%CLASSNAME_LC%:edit", [ 'id' => $entity->id ]) );
|
||||
}
|
||||
|
||||
return $this->renderView('%CLASSNAME_LC%/create', get_defined_vars());
|
||||
}
|
||||
|
||||
#[Route("/{id:\d+}/edit", name: "%CLASSNAME_LC%:edit", method: ["GET", "POST"])]
|
||||
##[Breadcrumb(parent: "%CLASSNAME_LC%:index", icon: "", lang: "app.lang.breadcrumb")]
|
||||
public function edit(ServerRequestInterface $request, array $arguments) : ResponseInterface
|
||||
{
|
||||
$search = %ENTITY_NS%\%CLASSNAME%::searchRequest()->fromRequest($request);
|
||||
$entity = %ENTITY_NS%\%CLASSNAME%::repository()->filterServerRequest($search)->loadOne();
|
||||
|
||||
form($this->formFactory->%SAVE_FORM_CLASSNAME_LC%($entity), $this->pushContext($this->formFactory->%SAVE_FORM_CONTEXT_CLASSNAME_LC%($request, "%CLASSNAME_LC%.edit")));
|
||||
|
||||
return $this->renderView('%CLASSNAME_LC%/edit', get_defined_vars());
|
||||
}
|
||||
|
||||
#[Route("/{id:\d+}/delete", name: "%CLASSNAME_LC%:delete", method: ["POST", "DELETE"])]
|
||||
public function delete(ServerRequestInterface $request, array $arguments) : ResponseInterface
|
||||
{
|
||||
$search = %ENTITY_NS%\%CLASSNAME%::searchRequest()->fromRequest($request);
|
||||
$entity = %ENTITY_NS%\%CLASSNAME%::repository()->filterServerRequest($search)->loadOne();
|
||||
|
||||
form($this->formFactory->%DELETE_FORM_CLASSNAME_LC%($entity), $this->pushContext($this->formFactory->%DELETE_FORM_CONTEXT_CLASSNAME_LC%($request, "%CLASSNAME_LC%.delete")));
|
||||
|
||||
return $this->redirect(route("%CLASSNAME_LC%:index"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace %NAMESPACE%\%FORM_NS%;
|
||||
|
||||
use Picea\Ui\Method\{ FormContextInterface };
|
||||
use Lean\Api\Factory\MessageFactoryInterface;
|
||||
use Lean\LanguageHandler;
|
||||
|
||||
use %NAMESPACE%\{%USE_ENTITY_NS%, };
|
||||
|
||||
class %DELETE_FORM_CLASSNAME% extends \Lean\Api\Form\Delete
|
||||
{
|
||||
protected string $contextClass = %DELETE_FORM_CONTEXT_CLASSNAME%::class;
|
||||
|
||||
public function __construct(
|
||||
protected LanguageHandler $languageHandler,
|
||||
protected MessageFactoryInterface $message,
|
||||
protected %ENTITY_NS%\%CLASSNAME% $entity,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace %NAMESPACE%\%FORM_NS%;
|
||||
|
||||
use Lean\Api\Attribute\ContextField;
|
||||
use %NAMESPACE%\{ %USE_ENTITY_NS% };
|
||||
|
||||
#[ContextField]
|
||||
class %DELETE_FORM_CONTEXT_CLASSNAME% extends \Lean\Api\Lib\FormContext
|
||||
{
|
||||
# #[ContextField]
|
||||
# public string $name;
|
||||
|
||||
public function valid(? %ENTITY_NS%\%CLASSNAME% $entity = null) : bool
|
||||
{
|
||||
if ( ! $this->getEntity()->isLoaded() ) {
|
||||
$this->pushErrorMessage('lean.api.form.delete.error.entity');
|
||||
}
|
||||
|
||||
return parent::valid();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace %NAMESPACE%\%ENTITY_NS%;
|
||||
|
||||
use Ulmus\{
|
||||
Attribute\IndexTypeEnum,
|
||||
Attribute\Obj\Table,
|
||||
Attribute\Property\Field,
|
||||
Attribute\Property\Index,
|
||||
Attribute\Property\OrderBy,
|
||||
Attribute\Property\Relation,
|
||||
Attribute\Property\Virtual,
|
||||
Entity\EntityInterface,
|
||||
EntityCollection,
|
||||
Entity\Field\Datetime,
|
||||
Repository,
|
||||
SearchRequest,
|
||||
};
|
||||
|
||||
use Ulmus\SearchRequest\Attribute\SearchWhere;
|
||||
use Notes\Attribute\Ignore;
|
||||
|
||||
use %NAMESPACE%\Lib;
|
||||
|
||||
#[Table(name: "%CLASSNAME_LC%")]
|
||||
class %CLASSNAME% implements \JsonSerializable, EntityInterface
|
||||
{
|
||||
use Lib\EntityTrait;
|
||||
|
||||
#[Field\Id]
|
||||
public int $id;
|
||||
|
||||
#[Ignore]
|
||||
public static function searchRequest(...$arguments) : SearchRequest\SearchRequestInterface
|
||||
{
|
||||
return new #[SearchRequest\Attribute\SearchRequestParameter(%CLASSNAME%::class)] class(... $arguments) extends SearchRequest\SearchRequest {
|
||||
|
||||
#[SearchWhere(parameter: [ '%CLASSNAME_LC%_id', 'id' ], source: SearchRequest\Attribute\PropertyValueSource::RequestAttribute)]
|
||||
public int $id;
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
public function %SAVE_FORM_CLASSNAME_LC%(EntityInterface|%ENTITY_NS%\%CLASSNAME% $entity): FormInterface
|
||||
{
|
||||
return new %FORM_NS%\%SAVE_FORM_CLASSNAME%($this->languageHandler, $this->message, $entity);
|
||||
}
|
||||
|
||||
public function %SAVE_FORM_CONTEXT_CLASSNAME_LC%(ServerRequestInterface $request, ? string $formName = ''): FormContextInterface
|
||||
{
|
||||
return new %FORM_NS%\%SAVE_FORM_CONTEXT_CLASSNAME%($this->languageHandler, $this->message, $request, $formName);
|
||||
}
|
||||
|
||||
public function %DELETE_FORM_CLASSNAME_LC%(EntityInterface|%ENTITY_NS%\%CLASSNAME% $entity): FormInterface
|
||||
{
|
||||
return new %FORM_NS%\%DELETE_FORM_CLASSNAME%($this->languageHandler, $this->message, $entity);
|
||||
}
|
||||
|
||||
public function %DELETE_FORM_CONTEXT_CLASSNAME_LC%(ServerRequestInterface $request, ? string $formName = ''): FormContextInterface
|
||||
{
|
||||
return new %FORM_NS%\%DELETE_FORM_CONTEXT_CLASSNAME%($this->languageHandler, $this->message, $request, $formName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
public function %SAVE_FORM_CLASSNAME_LC%(EntityInterface|%ENTITY_NS%\%CLASSNAME% $entity): FormInterface;
|
||||
public function %SAVE_FORM_CONTEXT_CLASSNAME_LC%(ServerRequestInterface $request, ? string $formName = ''): FormContextInterface;
|
||||
public function %DELETE_FORM_CLASSNAME_LC%(EntityInterface|%ENTITY_NS%\%CLASSNAME% $entity): FormInterface;
|
||||
public function %DELETE_FORM_CONTEXT_CLASSNAME_LC%(ServerRequestInterface $request, ? string $formName = ''): FormContextInterface;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace %NAMESPACE%\%FACTORY_TRAIT_NS%;
|
||||
|
||||
use %NAMESPACE%\{ %USE_ENTITY_NS%, %USE_FORM_NS%, };
|
||||
use Picea\Ui\Method\FormContextInterface;
|
||||
use Picea\Ui\Method\FormInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Ulmus\Entity\EntityInterface;
|
||||
|
||||
trait %CLASSNAME%Trait
|
||||
{
|
||||
public function %SAVE_FORM_CLASSNAME_LC%(EntityInterface|%ENTITY_NS%\%CLASSNAME% $entity): FormInterface
|
||||
{
|
||||
return new %FORM_NS%\%SAVE_FORM_CLASSNAME%($this->languageHandler, $this->messageFactory, $entity);
|
||||
}
|
||||
|
||||
public function %SAVE_FORM_CONTEXT_CLASSNAME_LC%(ServerRequestInterface $request, ? string $formName = ''): FormContextInterface
|
||||
{
|
||||
return new %FORM_NS%\%SAVE_FORM_CONTEXT_CLASSNAME%($this->languageHandler, $this->messageFactory, $request, $formName);
|
||||
}
|
||||
|
||||
public function %DELETE_FORM_CLASSNAME_LC%(EntityInterface|%ENTITY_NS%\%CLASSNAME% $entity): FormInterface
|
||||
{
|
||||
return new %FORM_NS%\%DELETE_FORM_CLASSNAME%($this->languageHandler, $this->messageFactory, $entity);
|
||||
}
|
||||
|
||||
public function %DELETE_FORM_CONTEXT_CLASSNAME_LC%(ServerRequestInterface $request, ? string $formName = ''): FormContextInterface
|
||||
{
|
||||
return new %FORM_NS%\%DELETE_FORM_CONTEXT_CLASSNAME%($this->languageHandler, $this->messageFactory, $request, $formName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace %NAMESPACE%\%FORM_NS%;
|
||||
|
||||
use Picea\Ui\Method\{ FormContextInterface };
|
||||
use Lean\Api\Factory\MessageFactoryInterface;
|
||||
use Lean\LanguageHandler;
|
||||
|
||||
use %NAMESPACE%\{%USE_ENTITY_NS%, };
|
||||
|
||||
class %SAVE_FORM_CLASSNAME% extends \Lean\Api\Form\Save
|
||||
{
|
||||
protected string $contextClass = %SAVE_FORM_CONTEXT_CLASSNAME%::class;
|
||||
|
||||
public function __construct(
|
||||
protected LanguageHandler $languageHandler,
|
||||
protected MessageFactoryInterface $message,
|
||||
protected %ENTITY_NS%\%CLASSNAME% $entity,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace %NAMESPACE%\%FORM_NS%;
|
||||
|
||||
use Lean\Api\Attribute\ContextField;
|
||||
use %NAMESPACE%\{ %USE_ENTITY_NS% };
|
||||
|
||||
#[ContextField]
|
||||
class %SAVE_FORM_CONTEXT_CLASSNAME% extends \Lean\Api\Lib\FormContext
|
||||
{
|
||||
# #[ContextField]
|
||||
# public string $name;
|
||||
|
||||
public function valid(? %ENTITY_NS%\%CLASSNAME% $entity = null) : bool
|
||||
{
|
||||
return parent::valid();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
# Title
|
||||
|
||||
## API 1.0
|
||||
|
||||
[APP](../) / %CLASSNAME%
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
### Routes
|
||||
|
||||
{route:descriptor}
|
||||
|
||||
{request:debugger}
|
||||
|
||||
### Forms
|
||||
|
||||
{form:descriptor}
|
||||
|
||||
### Entities
|
||||
|
||||
{entity:descriptor}
|
||||
Reference in new issue
Block a user