Skip to content

Commit

Permalink
Merge branch 'master' into client-timeout-exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk authored Aug 19, 2024
2 parents 8639b82 + 2269d76 commit 8f55842
Show file tree
Hide file tree
Showing 12 changed files with 941 additions and 86 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"react/promise": "^2.9",
"roadrunner-php/roadrunner-api-dto": "^1.9.0",
"roadrunner-php/version-checker": "^1.0",
"spiral/attributes": "^3.1.4",
"spiral/attributes": "^3.1.6",
"spiral/roadrunner": "^2024.1",
"spiral/roadrunner-cli": "^2.5",
"spiral/roadrunner-kv": "^4.2",
Expand Down
8 changes: 0 additions & 8 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1540,14 +1540,6 @@
<code><![CDATA[run]]></code>
</MissingReturnType>
</file>
<file src="src/Worker/WorkerOptions.php">
<LessSpecificReturnStatement>
<code><![CDATA[new self()]]></code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType>
<code><![CDATA[static]]></code>
</MoreSpecificReturnType>
</file>
<file src="src/WorkerFactory.php">
<DeprecatedClass>
<code><![CDATA[new AnnotationReader()]]></code>
Expand Down
4 changes: 2 additions & 2 deletions src/Client/Common/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*
* @template TItem
* @implements IteratorAggregate<TItem>
* @internal
* @psalm-internal Temporal\Client
*/
final class Paginator implements IteratorAggregate, Countable
{
Expand Down Expand Up @@ -46,6 +44,8 @@ private function __construct(
* @param null|callable(): int<0, max> $counter Returns total number of items.
*
* @return self<TInitItem>
*
* @internal
*/
public static function createFromGenerator(Generator $loader, ?callable $counter): self
{
Expand Down
4 changes: 0 additions & 4 deletions src/Internal/Marshaller/Type/EnumType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ class EnumType extends Type implements RuleFactoryInterface

public function __construct(MarshallerInterface $marshaller, string $class = null)
{
if (PHP_VERSION_ID < 80104) {
throw new \RuntimeException('Enums are not available in this version of PHP');
}

if ($class === null) {
throw new \RuntimeException('Enum is required');
}
Expand Down
80 changes: 80 additions & 0 deletions src/Internal/Marshaller/Type/EnumValueType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php

/**
* This file is part of Temporal package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Temporal\Internal\Marshaller\Type;

use BackedEnum;
use Temporal\Internal\Marshaller\MarshallerInterface;
use Temporal\Internal\Marshaller\MarshallingRule;

/**
* @extends Type<int|string>
*/
class EnumValueType extends Type implements RuleFactoryInterface
{
private const ERROR_MESSAGE = 'Invalid Enum value. Expected: int or string scalar value for BackedEnum. %s given.';

/** @var class-string<\BackedEnum> */
private string $classFQCN;

/**
* @param class-string<\BackedEnum>|null $class
*/
public function __construct(MarshallerInterface $marshaller, ?string $class = null)
{
$this->classFQCN = $class ?? throw new \RuntimeException('Enum is required.');
\is_a($class, BackedEnum::class, true) ?: throw new \RuntimeException(
'Class for EnumValueType must be an instance of BackedEnum.',
);
parent::__construct($marshaller);
}

/**
* {@inheritDoc}
*/
public static function makeRule(\ReflectionProperty $property): ?MarshallingRule
{
$type = $property->getType();

if (!$type instanceof \ReflectionNamedType || !\is_subclass_of($type->getName(), \UnitEnum::class)) {
return null;
}

return $type->allowsNull()
? new MarshallingRule(
$property->getName(),
NullableType::class,
new MarshallingRule(type: self::class, of: $type->getName()),
)
: new MarshallingRule($property->getName(), self::class, $type->getName());
}

/**
* {@inheritDoc}
*/
public function parse($value, $current)
{
if (\is_object($value)) {
return $value;
}

if (\is_int($value) || \is_string($value)) {
return $this->classFQCN::from($value);
}

throw new \InvalidArgumentException(\sprintf(self::ERROR_MESSAGE, \ucfirst(\get_debug_type($value))));
}

public function serialize($value): int|string
{
return $value->value;
}
}
7 changes: 3 additions & 4 deletions src/Internal/Marshaller/TypeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Temporal\Internal\Marshaller\Type\DetectableTypeInterface;
use Temporal\Internal\Marshaller\Type\EncodedCollectionType;
use Temporal\Internal\Marshaller\Type\EnumType;
use Temporal\Internal\Marshaller\Type\EnumValueType;
use Temporal\Internal\Marshaller\Type\ObjectType;
use Temporal\Internal\Marshaller\Type\OneOfType;
use Temporal\Internal\Marshaller\Type\RuleFactoryInterface as TypeRuleFactoryInterface;
Expand Down Expand Up @@ -139,10 +140,8 @@ private function createMatchers(iterable $matchers): void
*/
private function getDefaultMatchers(): iterable
{
if (PHP_VERSION_ID >= 80104) {
yield EnumType::class;
}

yield EnumType::class;
yield EnumValueType::class;
yield DateTimeType::class;
yield DateIntervalType::class;
yield UuidType::class;
Expand Down
1 change: 1 addition & 0 deletions src/Internal/Transport/Router/GetWorkerInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ private function workerToArray(WorkerInterface $worker): array
// ActivityInfo[]
'Activities' => $this->map($worker->getActivities(), $activityMap),
'PhpSdkVersion' => SdkVersion::getSdkVersion(),
'Flags' => (object)[],
];
}

Expand Down
Loading

0 comments on commit 8f55842

Please sign in to comment.