- Some work done on entity generation

This commit is contained in:
Dave Mc Nicoll committed 2026-05-21 14:58:21 +00:00
1 parent 05975089e5
commit 2dc71cd350
12 files changed
+94 -28

No files matched your search

+5 -8
View File
@@ -567,14 +567,11 @@ class EntityGenerate
protected function replaceClassname(string $boilerplate) : string
{
return match($this->apiBase ?? false) {
false => $boilerplate,
default => str_replace(
[ '%CLASSNAME_LC%', '%CLASSNAME%' ],
[ strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $this->name)), $this->name ],
$boilerplate
)
};
return str_replace(
[ '%CLASSNAME_LC%', '%CLASSNAME%' ],
[ strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $this->name)), $this->name ],
$boilerplate
);
}
protected function readComposerNamespace() : ? string
+3
View File
@@ -7,6 +7,7 @@ use Lean\Factory\HttpFactory;
use Notes\ObjectReflection;
use Notes\Route\Attribute\Method\Route;
use Ulmus\Attribute\Obj\Table;
use Ulmus\Attribute\Property\ArrayOf;
use Ulmus\Attribute\Property\Field;
use Ulmus\SearchRequest\Attribute\SearchParameter;
use Ulmus\SearchRequest\Attribute\SearchRequestParameter;
@@ -34,6 +35,7 @@ class EntityDescriptor
$field = $property->getAttribute(Field::class);
if ($field) {
$arrayOf = $property->getAttribute(ArrayOf::class);
$types = $property->getTypes();
if ($property->value ?? false) {
@@ -53,6 +55,7 @@ class EntityDescriptor
'length' => $field->object->length ?? null,
'readonly' => $field->object->readonly,
'default' => $default,
'arrayOf' => $arrayOf ?? null,
];
}
}
+1 -1
View File
@@ -27,7 +27,7 @@ abstract class Form
{
if(isset($this->contextClass) && ! $context instanceof $this->contextClass ) {
throw new \LogicException(
sprintf("Your context type should be a %s", $this->contextClass)
sprintf("Your context type should be a %s, received %s", $this->contextClass, $context::class)
);
}
}
+8 -3
View File
@@ -14,16 +14,21 @@ use Lean\Api\Attribute\EntityField;
use Ulmus\Entity\EntityInterface;
use Ulmus\Entity\Field\Datetime;
use Ulmus\EntityCollection;
abstract class Save extends Form implements \Picea\Ui\Method\FormInterface {
protected bool $skipEntityCreatedAt = false;
protected bool $skipEntityLastModified = false;
protected array $reflectedProperties;
protected string $contextClass = FormContext::class;
public function initialize(FormContextInterface $context) : void
{
if ( ! $this->getEntity()->isLoaded() ) {
if ( $this->getEntity() instanceof EntityInterface && ! $this->getEntity()->isLoaded() ) {
if (method_exists($context, 'initializeEntity')) {
$context->initializeEntity($this->getEntity());
}
@@ -46,13 +51,13 @@ abstract class Save extends Form implements \Picea\Ui\Method\FormInterface {
{
$entity = $this->getEntity();
if ($entity->isLoaded()) {
if ($entity->isLoaded() && ! $this->skipEntityLastModified) {
if (property_exists($entity, 'updatedAt') && $entity->repository()->generateDatasetDiff($entity) ) {
$cls = $entity::resolveEntity()->field('updatedAt')->type->type;
$entity->updatedAt = new $cls();
}
}
else {
elseif (! $this->skipEntityCreatedAt) {
if (property_exists($entity, 'createdAt') && empty($entity->createdAt)) {
$cls = $entity::resolveEntity()->field('createdAt')->type->type;
$entity->createdAt = new $cls();
+16 -3
View File
@@ -24,8 +24,6 @@ class ApiRenderer implements MiddlewareInterface {
$response = $handler->handle($request);
}
catch(\Throwable $ex) {
if (static::awaitingJson($request)) {
return HttpFactory::createJsonResponse([
'status' => 'failed',
@@ -48,7 +46,7 @@ class ApiRenderer implements MiddlewareInterface {
$payload = $response->getPayload();
# For now, we match only response having a 'data' field
if (isset($payload['data'])) {
if ( (is_array($payload) || $payload instanceof \ArrayAccess) && isset($payload['data'])) {
return HttpFactory::createJsonResponse([
'status' => 'success',
'ts' => time(),
@@ -84,4 +82,19 @@ class ApiRenderer implements MiddlewareInterface {
{
return str_contains(strtolower($request->getHeaderLine('content-type')), 'json');
}
public static function encodeHtml(iterable& $array) : iterable
{
foreach($array as &$item) {
if (is_array($item)) {
$item = static::encodeHtml($item);
}
elseif (is_string($item)) {
dump($item);
$item = htmlspecialchars($item);
}
}
return $array;
}
}
+4 -3
View File
@@ -35,19 +35,20 @@ class RouteDescriptor
$attribute = $reflector->reflectClass()->getAttribute(\Notes\Route\Attribute\Object\Route::class);
$base = $attribute ? $attribute->object->base : "";
$base = $attribute ? $attribute->object->getBase() : "";
foreach($reflector->reflectMethods() as $method) {
foreach(array_reverse($method->getAttributes(Route::class)) as $routeAttribute) {
$itemBase = $routeAttribute->object->getBase() ?? $base;
$route = $routeAttribute->object;
$path = rtrim($route->route, '/');
$cleaned = $this->cleanRouteFromRegex($base.$path);
$cleaned = $this->cleanRouteFromRegex($itemBase.$path);
$url = $this->urlExtension->buildUrl($cleaned);
$routes[] = [
'name' => $route->name,
'route' => $url,
'path' => $base.$path,
'path' => $itemBase.$path,
'cleaned' => $cleaned,
'description'=> $route->description,
#'methods' =>implode(', ', (array)$route->method),