Deprecated: Function get_magic_quotes_gpc() is deprecated in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 99
Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 619
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 832
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
Warning: Cannot modify header information - headers already sent by (output started at /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php:99) in /hermes/walnacweb04/walnacweb04ab/b2791/pow.jasaeld/htdocs/De1337/nothing/index.php on line 839
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 84edf33b..8db94632 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
+## [4.1.1] - 2025-03-21
+### Fixed
+* Fixed #648 TelemetryEvent cannot handle nested array as $body argument by @danielmorell #649.
+
## [4.1.0] - 2025-02-14
### Added
* Added support for Telemetry by @danielmorell in #634.
diff --git a/src/Payload/Notifier.php b/src/Payload/Notifier.php
index f38b86fb..dac1842e 100644
--- a/src/Payload/Notifier.php
+++ b/src/Payload/Notifier.php
@@ -8,7 +8,7 @@
class Notifier implements SerializerInterface
{
const NAME = "rollbar-php";
- const VERSION = "4.1.0";
+ const VERSION = "4.1.1";
use UtilitiesTrait;
diff --git a/src/Payload/TelemetryBody.php b/src/Payload/TelemetryBody.php
index 3bb84a50..7fc1d351 100644
--- a/src/Payload/TelemetryBody.php
+++ b/src/Payload/TelemetryBody.php
@@ -70,6 +70,29 @@ public function __construct(
$this->extra = $extra;
}
+ /**
+ * Creates a {@see TelemetryBody} instance from an array of data.
+ *
+ * The data array may be loosely structured, as only the keys that match the defined keys will be used to create the
+ * instance. Any undefined keys in data will be stored in the {@see $extra} property.
+ *
+ * @param array $data The data to create the {@see TelemetryBody} instance from.
+ * @return self
+ *
+ * @since 4.1.1
+ */
+ public static function fromArray(array $data): self
+ {
+ // This filters out any keys that are not accepted by the constructor to prevent duplicate parameter errors from
+ // named and positional arguments.
+ $params = array_intersect_key($data, array_flip(self::DEFINED_KEYS));
+ // Generates an array of all the keys not used in the constructor.
+ $extra = array_diff_key($data, $params);
+ $instance = new self(...$params);
+ $instance->extra = $extra;
+ return $instance;
+ }
+
/**
* Returns the array representation of the telemetry body.
*
diff --git a/src/Payload/TelemetryEvent.php b/src/Payload/TelemetryEvent.php
index a3ce387e..019f337f 100644
--- a/src/Payload/TelemetryEvent.php
+++ b/src/Payload/TelemetryEvent.php
@@ -47,7 +47,7 @@ public function __construct(
if (is_null($this->timestamp)) {
$this->timestamp = floor(microtime(true) * 1000);
}
- $this->body = is_array($body) ? new TelemetryBody(...$body): $body;
+ $this->body = is_array($body) ? TelemetryBody::fromArray($body): $body;
}
public function serialize(): array
diff --git a/tests/Payload/TelemetryBodyTest.php b/tests/Payload/TelemetryBodyTest.php
index 3043455d..1c3721a7 100644
--- a/tests/Payload/TelemetryBodyTest.php
+++ b/tests/Payload/TelemetryBodyTest.php
@@ -97,4 +97,55 @@ public function testExtraDoesNotOverrideProperty(): void
self::assertSame(['message' => 'foo'], $body->serialize());
}
+
+ /**
+ * @since 4.1.1
+ */
+ public function testFromArray(): void
+ {
+ $body = TelemetryBody::fromArray([
+ 'message' => 'message',
+ 'method' => 'method',
+ 'url' => 'url',
+ 'status_code' => 'status',
+ 'subtype' => 'sub',
+ 'stack' => 'stack',
+ 'from' => 'from',
+ 'to' => 'to',
+ 'start_timestamp_ms' => 42,
+ 'end_timestamp_ms' => 43,
+ 'extraOne' => 'foo',
+ 'extraTwo' => 'bar',
+ ]);
+
+ self::assertSame('message', $body->message);
+ self::assertSame('method', $body->method);
+ self::assertSame('url', $body->url);
+ self::assertSame('status', $body->status_code);
+ self::assertSame('sub', $body->subtype);
+ self::assertSame('stack', $body->stack);
+ self::assertSame('from', $body->from);
+ self::assertSame('to', $body->to);
+ self::assertSame(42, $body->start_timestamp_ms);
+ self::assertSame(43, $body->end_timestamp_ms);
+ self::assertSame([
+ 'extraOne' => 'foo',
+ 'extraTwo' => 'bar',
+ ], $body->extra);
+ }
+
+ /**
+ * @since 4.1.1
+ */
+ public function testFromArrayNested(): void
+ {
+ // Assert that nested/non-standard arrays don't throw an error.
+ $body = TelemetryBody::fromArray([["data" => "some data"]]);
+ self::assertSame([["data" => "some data"]], $body->extra);
+
+ // Assert that positional arguments are not passed to named arguments on the constructor.
+ $body = TelemetryBody::fromArray(["0" => ["id" => "some id"], 'message' => 'test message']);
+ self::assertSame('test message', $body->message);
+ self::assertSame(["0" => ["id" => "some id"]], $body->extra);
+ }
}
diff --git a/tests/Payload/TelemetryEventTest.php b/tests/Payload/TelemetryEventTest.php
index ddf3d103..0beba133 100644
--- a/tests/Payload/TelemetryEventTest.php
+++ b/tests/Payload/TelemetryEventTest.php
@@ -20,4 +20,30 @@ public function testConstruct(): void
self::assertGreaterThanOrEqual($before, $event->timestamp);
self::assertLessThanOrEqual($after, $event->timestamp);
}
+
+ /**
+ * @since 4.1.1
+ */
+ public function testNestedArrayBody(): void
+ {
+ $event = new TelemetryEvent(EventType::Network, EventLevel::Info, [
+ 'method' => 'GET',
+ 'url' => 'https://example.com',
+ 'status_code' => '200',
+ [
+ 'unstructured' => 'data',
+ 0 => 'foo',
+ ],
+ ]);
+
+ self::assertSame('GET', $event->body->method);
+ self::assertSame('https://example.com', $event->body->url);
+ self::assertSame('200', $event->body->status_code);
+ self::assertSame([
+ [
+ 'unstructured' => 'data',
+ 0 => 'foo',
+ ],
+ ], $event->body->extra);
+ }
}