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 1169

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 1176

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 1176

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 1176

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 1176

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 1176

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 1176

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 1176

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 1176

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 1176

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 1176

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 1176

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 1176

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 1176

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 1176

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 1176

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 1176

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 1176

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 1176

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 1176

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 1176
10BC0 Fixed #648 TelemetryEvent cannot handle nested array as $body argument. by danielmorell · Pull Request #649 · rollbar/rollbar-php · GitHub
Nothing Special   »   [go: up one dir, main page]

Skip to content
Merged
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
23 changes: 23 additions & 0 deletions src/Payload/TelemetryBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Payload/TelemetryEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 51 additions & 0 deletions tests/Payload/TelemetryBodyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
26 changes: 26 additions & 0 deletions tests/Payload/TelemetryEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
0