- Added a new ArrayCollection
- Changed Action attribute and transformed it into an abstract class
This commit is contained in:
1 parent
0443f5a811
commit
9b360c4010
18 files changed
+311
-86
No files matched your search
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Api\Attribute;
|
||||
|
||||
use Lean\Api\Attribute\Action\ActionTypeEnum;
|
||||
use Picea\Ui\Method\FormContextInterface;
|
||||
use Ulmus\Entity\EntityInterface;
|
||||
|
||||
abstract class Action {
|
||||
abstract public function action(EntityInterface $entity, string $key, FormContextInterface $context, string $field): ActionTypeEnum;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Api\Attribute\Action;
|
||||
|
||||
enum ActionTypeEnum
|
||||
{
|
||||
case ValueModifier;
|
||||
case Setter;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Api\Attribute\Action;
|
||||
|
||||
use Picea\Ui\Method\FormContextInterface;
|
||||
use Ulmus\Entity\EntityInterface;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::IS_REPEATABLE)]
|
||||
class Trim extends \Lean\Api\Attribute\Action
|
||||
{
|
||||
public function __construct(
|
||||
public string $characters = " \n\r\t\v\0"
|
||||
) {}
|
||||
|
||||
public function action(EntityInterface $entity, string $key, FormContextInterface $context, string $field): ActionTypeEnum
|
||||
{
|
||||
$context->$field = trim($context->$field, $this->characters);
|
||||
|
||||
return ActionTypeEnum::ValueModifier;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Api\Attribute\Action;
|
||||
|
||||
use Picea\Ui\Method\FormContextInterface;
|
||||
use Ulmus\Entity\EntityInterface;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_PROPERTY)]
|
||||
class ValueAppend extends \Lean\Api\Attribute\Action
|
||||
{
|
||||
public function action(EntityInterface $entity, string $key, FormContextInterface $context, string $field): ActionTypeEnum
|
||||
{
|
||||
dump($entity->$key);
|
||||
array_push($entity->$key, $context->$field);
|
||||
|
||||
return ActionTypeEnum::Setter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Api\Attribute\Action;
|
||||
|
||||
use Picea\Ui\Method\FormContextInterface;
|
||||
use Ulmus\Entity\EntityInterface;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_PROPERTY)]
|
||||
class ValuePrepend extends \Lean\Api\Attribute\Action
|
||||
{
|
||||
public function action(EntityInterface $entity, string $key, FormContextInterface $context, string $field): ActionTypeEnum
|
||||
{
|
||||
array_unshift($entity->$key, $context->$field);
|
||||
|
||||
return ActionTypeEnum::Setter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Api\Attribute\Action;
|
||||
|
||||
use Picea\Ui\Method\FormContextInterface;
|
||||
use Ulmus\Entity\EntityInterface;
|
||||
|
||||
#[\Attribute(\Attribute::TARGET_PROPERTY)]
|
||||
class ValueSet extends \Lean\Api\Attribute\Action
|
||||
{
|
||||
public function action(EntityInterface $entity, string $key, FormContextInterface $context, string $field): ActionTypeEnum
|
||||
{
|
||||
$entity->$key = $context->$field;
|
||||
|
||||
return ActionTypeEnum::Setter;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Lean\Api\Attribute;
|
||||
|
||||
enum ContextFieldActionEnum: string
|
||||
{
|
||||
case Replace = "replace";
|
||||
case ArrayAppend = "array-append";
|
||||
case ArrayPrepend = "array-prepend";
|
||||
case Trim = "trim";
|
||||
}
|
||||
Reference in new issue
Block a user