Skip to content

Commit 5a4c07c

Browse files
authored
Merge branch 'master' into php-8-5
2 parents 1387e85 + 143a9e8 commit 5a4c07c

44 files changed

Lines changed: 651 additions & 268 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/run-test-suite.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ jobs:
9595

9696
- name: Run tests
9797
run: ${{ inputs.test-command }}
98+
env:
99+
XDEBUG_MODE: off
98100

99101
- name: Check for failures
100102
if: steps.validate.outcome == 'failure'

psalm-baseline.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,7 @@
11781178
<code><![CDATA[$scope]]></code>
11791179
</PropertyNotSetInConstructor>
11801180
<UnsupportedPropertyReferenceUsage>
1181+
<code><![CDATA[$ctx->currentDetails = &$context->currentDetails]]></code>
11811182
<code><![CDATA[$ctx->trace = &$context->trace]]></code>
11821183
</UnsupportedPropertyReferenceUsage>
11831184
</file>

src/DataConverter/DataConverter.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,33 @@ public static function createDefault(): DataConverterInterface
3939
);
4040
}
4141

42-
public function fromPayload(Payload $payload, $type)
42+
/**
43+
* @param string|\ReflectionClass|\ReflectionType|Type|null $type
44+
*/
45+
public function fromPayload(Payload $payload, $type): mixed
4346
{
47+
$type = Type::create($type);
48+
49+
if ($type->isClass() && $type->getName() === RawValue::class) {
50+
return new RawValue($payload);
51+
}
52+
4453
/** @var \ArrayAccess $meta */
4554
$meta = $payload->getMetadata();
4655

4756
$encoding = $meta[EncodingKeys::METADATA_ENCODING_KEY];
4857

4958
if (!isset($this->converters[$encoding])) {
50-
throw new DataConverterException(\sprintf('Undefined payload encoding %s', $encoding));
59+
throw new DataConverterException(\sprintf('Undefined payload encoding "%s"', $encoding));
5160
}
5261

53-
$type = Type::create($type);
54-
if (\in_array($type->getName(), [Type::TYPE_VOID, Type::TYPE_NULL, Type::TYPE_FALSE, Type::TYPE_TRUE], true)) {
55-
return match ($type->getName()) {
56-
Type::TYPE_VOID, Type::TYPE_NULL => null,
57-
Type::TYPE_TRUE => true,
58-
Type::TYPE_FALSE => false,
59-
};
60-
}
61-
62-
return $this->converters[$encoding]->fromPayload($payload, $type);
62+
return match ($type->getName()) {
63+
Type::TYPE_VOID,
64+
Type::TYPE_NULL => null,
65+
Type::TYPE_TRUE => true,
66+
Type::TYPE_FALSE => false,
67+
default => $this->converters[$encoding]->fromPayload($payload, $type),
68+
};
6369
}
6470

6571
/**
@@ -69,6 +75,9 @@ public function fromPayload(Payload $payload, $type)
6975
*/
7076
public function toPayload($value): Payload
7177
{
78+
if ($value instanceof RawValue) {
79+
return $value->getPayload();
80+
}
7281
foreach ($this->converters as $converter) {
7382
$payload = $converter->toPayload($value);
7483

src/DataConverter/DataConverterInterface.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ interface DataConverterInterface
2323
* @psalm-mutation-free
2424
* @throws DataConverterException
2525
*/
26-
public function fromPayload(Payload $payload, $type);
26+
public function fromPayload(Payload $payload, mixed $type);
2727

2828
/**
29-
* @param mixed $value
30-
*
3129
* @throws DataConverterException
3230
*/
33-
public function toPayload($value): Payload;
31+
public function toPayload(mixed $value): Payload;
3432
}

src/DataConverter/EncodingKeys.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ final class EncodingKeys
1717
public const METADATA_MESSAGE_TYPE = 'messageType';
1818
public const METADATA_ENCODING_NULL = 'binary/null';
1919
public const METADATA_ENCODING_RAW = 'binary/plain';
20+
public const METADATA_ENCODING_RAW_VALUE = 'binary';
2021
public const METADATA_ENCODING_JSON = 'json/plain';
2122
public const METADATA_ENCODING_PROTOBUF_JSON = 'json/protobuf';
2223
public const METADATA_ENCODING_PROTOBUF = 'binary/protobuf';

src/DataConverter/ProtoJsonConverter.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,13 @@ public function toPayload($value): ?Payload
5050
public function fromPayload(Payload $payload, Type $type)
5151
{
5252
if (!$type->isClass()) {
53-
throw new DataConverterException('Unable to decode value using protobuf converter - ');
53+
throw new DataConverterException(
54+
\sprintf(
55+
'Unable to decode value using "%s" encoding converter: resulting type must be a class, "%s" given',
56+
$this->getEncodingType(),
57+
$type->getName(),
58+
),
59+
);
5460
}
5561

5662
try {

src/DataConverter/RawValue.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Temporal package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace Temporal\DataConverter;
13+
14+
use Temporal\Api\Common\V1\Payload;
15+
16+
final class RawValue
17+
{
18+
private Payload $payload;
19+
20+
public function __construct(Payload $data)
21+
{
22+
$this->payload = $data;
23+
}
24+
25+
public function getPayload(): Payload
26+
{
27+
return $this->payload;
28+
}
29+
}

src/DataConverter/Type.php

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,25 +79,14 @@ public static function fromReflectionType(\ReflectionType $type): self
7979
*/
8080
public static function create($type): Type
8181
{
82-
switch (true) {
83-
case $type instanceof ReturnType:
84-
return new self($type->name, $type->nullable);
85-
86-
case $type instanceof self:
87-
return $type;
88-
89-
case \is_string($type):
90-
return new self($type);
91-
92-
case $type instanceof \ReflectionClass:
93-
return self::fromReflectionClass($type);
94-
95-
case $type instanceof \ReflectionType:
96-
return self::fromReflectionType($type);
97-
98-
default:
99-
return new self();
100-
}
82+
return match (true) {
83+
$type instanceof ReturnType => new self($type->name, $type->nullable),
84+
$type instanceof self => $type,
85+
\is_string($type) => new self($type),
86+
$type instanceof \ReflectionClass => self::fromReflectionClass($type),
87+
$type instanceof \ReflectionType => self::fromReflectionType($type),
88+
default => new self(),
89+
};
10190
}
10291

10392
public function getName(): string

src/Internal/Transport/Router/InvokeQuery.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ private function workflowMetadata(Deferred $resolver, WorkflowContext $context):
122122
static function () use ($resolver, $context): void {
123123
try {
124124
$result = EncodedValues::fromValues([
125-
(new WorkflowMetadata())->setDefinition(
126-
(new WorkflowDefinition())
127-
->setQueryDefinitions($context->getQueryDispatcher()->getQueryHandlers())
128-
->setSignalDefinitions($context->getSignalDispatcher()->getSignalHandlers())
129-
->setUpdateDefinitions($context->getUpdateDispatcher()->getUpdateHandlers()),
130-
),
125+
(new WorkflowMetadata())
126+
->setDefinition(
127+
(new WorkflowDefinition())
128+
->setQueryDefinitions($context->getQueryDispatcher()->getQueryHandlers())
129+
->setSignalDefinitions($context->getSignalDispatcher()->getSignalHandlers())
130+
->setUpdateDefinitions($context->getUpdateDispatcher()->getUpdateHandlers()),
131+
)
132+
->setCurrentDetails((string) $context->getCurrentDetails()),
131133
]);
132134

133135
$resolver->resolve($result);

src/Internal/Workflow/ScopeContext.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ public static function fromWorkflowContext(
5757
$ctx->readonly = $context->readonly;
5858
$ctx->continueAsNew = $context->continueAsNew;
5959
$ctx->trace = &$context->trace;
60+
$ctx->currentDetails = &$context->currentDetails;
6061

6162
return $ctx;
6263
}

0 commit comments

Comments
 (0)