Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/migrate to laravel data package #26

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"require": {
"php": ">=8.0",
"ext-simplexml": "*",
"spatie/data-transfer-object": "^3.6.1",
"guzzlehttp/guzzle": "^7.2"
"guzzlehttp/guzzle": "^7.2",
"spatie/laravel-data": "^2.2"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 4 additions & 3 deletions src/Dto/Casters/CarbonCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
namespace Laravolt\Camunda\Dto\Casters;

use Illuminate\Support\Carbon;
use Spatie\DataTransferObject\Caster;
use Spatie\LaravelData\Casts\Cast;
use Spatie\LaravelData\Support\DataProperty;

class CarbonCaster implements Caster
class CarbonCaster implements Cast
{
public function cast(mixed $value): Carbon
public function cast(DataProperty $property, mixed $value, array $context): mixed
{
return Carbon::parse($value);
}
Expand Down
16 changes: 8 additions & 8 deletions src/Dto/Casters/VariablesCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

use ArrayAccess;
use LogicException;
use Spatie\DataTransferObject\Caster;
use Spatie\LaravelData\Casts\Cast;
use Spatie\LaravelData\Support\DataProperty;

class VariablesCaster implements Caster
class VariablesCaster implements Cast
{
public function __construct(
private array $types,
private string $itemType,
) {
}
) {}

public function cast(mixed $value): array|ArrayAccess
public function cast(DataProperty $property, mixed $value, array $context): mixed
{
foreach ($this->types as $type) {
if ($type === 'array') {
Expand All @@ -34,17 +34,17 @@ public function cast(mixed $value): array|ArrayAccess
private function castArray(mixed $value): array
{
return collect($value)
->map(fn (array $data, string $key) => $this->castItem($key, $data))
->map(fn(array $data, string $key) => $this->castItem($key, $data))
->toArray();
}

private function castArrayAccess(mixed $value): ArrayAccess
{
$arrayAccess = new $this->type();
$arrayAccess = new $this->type(); // TODO: Undefined property '$type'.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ini masih error, belum tau maksudnya gimana


array_walk(
$value,
fn (array $data, string $key) => $arrayAccess[] = $this->castItem($key, $data)
fn(array $data, string $key) => $arrayAccess[] = $this->castItem($key, $data)
);

return $arrayAccess;
Expand Down
44 changes: 17 additions & 27 deletions src/Dto/Deployment.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,23 @@

use Illuminate\Support\Carbon;
use Laravolt\Camunda\Dto\Casters\CarbonCaster;
use Spatie\DataTransferObject\Attributes\CastWith;
use Spatie\DataTransferObject\Attributes\Strict;
use Spatie\DataTransferObject\DataTransferObject;
use Spatie\LaravelData\Attributes\WithCast;
use Spatie\LaravelData\Data;

#[Strict]
class Deployment extends DataTransferObject
class Deployment extends Data
{
public string $id;

public string|null $tenantId;

public ?string $name;

public ?string $source;

#[CastWith(CarbonCaster::class)]
public Carbon $deploymentTime;

public ?array $processDefinitions;

public ?array $links;

public ?array $deployedProcessDefinitions;

public ?array $deployedCaseDefinitions;

public ?array $deployedDecisionDefinitions;

public ?array $deployedDecisionRequirementsDefinitions;
public function __construct(
public string $id,
public ?string $tenantId,
public ?string $name,
public ?string $source,
#[WithCast(CarbonCaster::class)]
public Carbon $deploymentTime,
public ?array $processDefinitions = [],
public ?array $links = [],
public ?array $deployedProcessDefinitions = [],
public ?array $deployedCaseDefinitions = [],
public ?array $deployedDecisionDefinitions = [],
public ?array $deployedDecisionRequirementsDefinitions = [],
) {}
}
78 changes: 28 additions & 50 deletions src/Dto/ExternalTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,56 +4,34 @@

use Illuminate\Support\Carbon;
use Laravolt\Camunda\Dto\Casters\CarbonCaster;
use Laravolt\Camunda\Dto\Casters\VariablesCaster;
use Spatie\DataTransferObject\Attributes\CastWith;
use Spatie\DataTransferObject\Attributes\Strict;
use Spatie\DataTransferObject\DataTransferObject;
use Spatie\LaravelData\Attributes\WithCast;
use Spatie\LaravelData\Data;

#[Strict]
class ExternalTask extends DataTransferObject
class ExternalTask extends Data
{
public string $id;

public string $topicName;

public string|null $workerId;

public string|null $activityId;

public string|null $activityInstanceId;

public string|null $errorMessage;

public string|null $errorDetails;

public string|null $executionId;

public string|null $businessKey;

#[CastWith(CarbonCaster::class)]
public Carbon|null $lockExpirationTime;

public string $processDefinitionId;

public string $processDefinitionKey;

public string|null $processDefinitionVersionTag;

public string $processInstanceId;

public string|null $tenantId;

public ?int $retries;

public int $priority;

/** @var \Laravolt\Camunda\Dto\Variable[] */
#[CastWith(VariablesCaster::class, Variable::class)]
public array|null $variables;

public bool $suspended;

public array|null $extensionProperties;

public string|null $createTime;
public function __construct(
public ?string $activityId,
public ?string $activityInstanceId,
public ?string $errorMessage,
public ?string $errorDetails,
public ?string $executionId,
public string $id,
#[WithCast(CarbonCaster::class)]
public ?Carbon $lockExpirationTime,
#[WithCast(CarbonCaster::class)]
public ?Carbon $createTime,
public string $processDefinitionId,
public string $processDefinitionKey,
public ?string $processDefinitionVersionTag,
public string $processInstanceId,
public ?int $retries,
public bool $suspended,
public ?string $workerId,
public string $topicName,
public ?string $tenantId,
public ?array $variables,
public int $priority,
public ?string $businessKey = null,
public ?array $extensionProperties = [],
) {}
}
49 changes: 18 additions & 31 deletions src/Dto/ProcessDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,24 @@

namespace Laravolt\Camunda\Dto;

use Spatie\DataTransferObject\Attributes\Strict;
use Spatie\DataTransferObject\DataTransferObject;
use Spatie\LaravelData\Data;

#[Strict]
class ProcessDefinition extends DataTransferObject
class ProcessDefinition extends Data
{
public string $id;

public string|null $tenantId;

public string $key;

public string $category;

public ?string $name;

public ?string $description;

public int $version;

public string $resource;

public string $deploymentId;

public ?string $diagram;

public bool $suspended;

public ?string $versionTag;

public ?string $historyTimeToLive;

public bool $startableInTasklist;
public function __construct(
public string $id,
public string $key,
public string $category,
public ?string $description,
public ?string $name,
public int $version,
public string $resource,
public string $deploymentId,
public ?string $diagram,
public bool $suspended,
public ?string $tenantId,
public ?string $versionTag,
public ?string $historyTimeToLive,
public bool $startableInTasklist,
) {}
}
39 changes: 15 additions & 24 deletions src/Dto/ProcessInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,21 @@
namespace Laravolt\Camunda\Dto;

use Laravolt\Camunda\Dto\Casters\VariablesCaster;
use Spatie\DataTransferObject\Attributes\CastWith;
use Spatie\DataTransferObject\Attributes\Strict;
use Spatie\DataTransferObject\DataTransferObject;
use Spatie\LaravelData\Attributes\WithCast;
use Spatie\LaravelData\Data;

#[Strict]
class ProcessInstance extends DataTransferObject
class ProcessInstance extends Data
{
public string $id;

public string|null $tenantId;

public string|null $businessKey;

public array $links;

public string $definitionId;

public ?string $caseInstanceId;

public bool $ended;

public bool $suspended;

/** @var \Laravolt\Camunda\Dto\Variable[] */
#[CastWith(VariablesCaster::class, Variable::class)]
public array|null $variables;
public function __construct(
public array $links,
public string $id,
public string $definitionId,
public ?string $businessKey,
public ?string $caseInstanceId,
public bool $ended,
public bool $suspended,
public ?string $tenantId = null,
#[WithCast(VariablesCaster::class, Variable::class)] // TODO: is this possible?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

karena di VariablesCaster masih error, maka kemungkinan ini masih belum working properly

public ?array $variables = [],
) {}
}
72 changes: 27 additions & 45 deletions src/Dto/ProcessInstanceHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,51 +6,33 @@

use Illuminate\Support\Carbon;
use Laravolt\Camunda\Dto\Casters\CarbonCaster;
use Spatie\DataTransferObject\Attributes\CastWith;
use Spatie\DataTransferObject\Attributes\Strict;
use Spatie\DataTransferObject\DataTransferObject;
use Spatie\LaravelData\Attributes\WithCast;
use Spatie\LaravelData\Data;

#[Strict]
class ProcessInstanceHistory extends DataTransferObject
class ProcessInstanceHistory extends Data
{
public string $id;

public ?string $rootProcessInstanceId;

public ?string $superProcessInstanceId;

public ?string $superCaseInstanceId;

public ?string $caseInstanceId;

public ?string $processDefinitionName;

public string $processDefinitionKey;

public string $processDefinitionVersion;

public string $processDefinitionId;

public ?string $businessKey;

#[CastWith(CarbonCaster::class)]
public Carbon $startTime;

#[CastWith(CarbonCaster::class)]
public ?Carbon $endTime;

#[CastWith(CarbonCaster::class)]
public ?Carbon $removalTime;

public ?int $durationInMillis;

public ?string $startUserId;

public string $startActivityId;

public ?string $deleteReason;

public ?string $tenantId;

public string $state;
public function __construct(
public string $id,
public ?string $businessKey,
public string $processDefinitionId,
public string $processDefinitionKey,
public ?string $processDefinitionName,
public int $processDefinitionVersion,
#[WithCast(CarbonCaster::class)]
public Carbon $startTime,
#[WithCast(CarbonCaster::class)]
public ?Carbon $endTime,
#[WithCast(CarbonCaster::class)]
public ?Carbon $removalTime,
public ?int $durationInMillis,
public ?string $startUserId,
public string $startActivityId,
public ?string $deleteReason,
public ?string $rootProcessInstanceId,
public ?string $superProcessInstanceId,
public ?string $superCaseInstanceId,
public ?string $caseInstanceId,
public ?string $tenantId,
public string $state,
) {}
}
Loading