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
4 changes: 4 additions & 0 deletions .github/changelog/fix-stream-typed-connector-properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Fixed a fatal error when Stream 4.5.0 or newer is active.
29 changes: 14 additions & 15 deletions integration/stream/class-connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,22 @@
*/
class Connector extends \WP_Stream\Connector {
/**
* Connector slug.
* Set the connector slug and the actions registered for this connector.
*
* @var string
* These are assigned here rather than redeclared as properties. Stream 4.5.0
* added native types to the parent class properties, and PHP requires a
* redeclared property to match the parent's type exactly. Assigning them
* keeps the connector compatible with Stream versions before and after 4.5.0.
*/
public $name = 'activitypub';

/**
* Actions registered for this connector.
*
* @var array
*/
public $actions = array(
'activitypub_handled_follow',
'activitypub_sent_to_inbox',
'activitypub_outbox_processing_complete',
'activitypub_outbox_processing_batch_complete',
);
public function __construct() {
$this->name = 'activitypub';
$this->actions = array(
'activitypub_handled_follow',
'activitypub_sent_to_inbox',
'activitypub_outbox_processing_complete',
'activitypub_outbox_processing_batch_complete',
);
}

/**
* Return translated connector label.
Expand Down
27 changes: 27 additions & 0 deletions tests/phpunit/tests/integration/class-test-stream-connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,33 @@ public function test_prepare_outbox_data_for_response_blog_user_url() {
public function test_class_hierarchy() {
$this->assertInstanceOf( '\WP_Stream\Connector', $this->stream_connector );
}

/**
* Test that the connector does not redeclare properties of the parent class.
*
* Stream 4.5.0 added native types to the properties of WP_Stream\Connector.
* A child class that redeclares one of them must use the same type, which
* would break older Stream versions where the properties are untyped. The
* connector must assign these values instead of redeclaring them.
*
* @see https://github.com/Automattic/wordpress-activitypub/issues/4066
*
* @covers ::__construct
*/
public function test_connector_does_not_redeclare_parent_properties() {
$parent_class = \get_parent_class( Connector::class );
$parent = new \ReflectionClass( $parent_class );

foreach ( $parent->getProperties( \ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED ) as $parent_property ) {
$property = new \ReflectionProperty( Connector::class, $parent_property->getName() );

$this->assertSame(
$parent->getName(),
$property->getDeclaringClass()->getName(),
\sprintf( 'Connector must not redeclare the parent property $%s.', $parent_property->getName() )
);
}
}
}

// Mock WP_Stream\Connector if it doesn't exist.
Expand Down
Loading