rename Transformers_Mangaer to Transformer_Factory
Some checks failed
Unit Testing / phpunit (7.2) (push) Waiting to run
Unit Testing / phpunit (7.3) (push) Waiting to run
Unit Testing / phpunit (7.4) (push) Waiting to run
Unit Testing / phpunit (8.0) (push) Waiting to run
Unit Testing / phpunit (8.1) (push) Waiting to run
Unit Testing / phpunit (8.2) (push) Waiting to run
Unit Testing / phpunit (latest) (push) Waiting to run
PHP_CodeSniffer / phpcs (push) Failing after 4m3s
Unit Testing / phpunit (5.6, 6.2) (push) Failing after 4m36s
Unit Testing / phpunit (7.0) (push) Has been cancelled

This commit is contained in:
André Menrath 2023-11-30 08:36:05 +01:00
parent 628f3611d2
commit 225e06dfec
10 changed files with 22 additions and 19 deletions

View file

@ -5,7 +5,7 @@ use WP_Post;
use Activitypub\Activity\Activity; use Activitypub\Activity\Activity;
use Activitypub\Collection\Users; use Activitypub\Collection\Users;
use Activitypub\Collection\Followers; use Activitypub\Collection\Followers;
use Activitypub\Transformer\Transformers_Manager; use Activitypub\Transformer\Transformer_Factory;
use function Activitypub\is_single_user; use function Activitypub\is_single_user;
use function Activitypub\is_user_disabled; use function Activitypub\is_user_disabled;
@ -65,7 +65,7 @@ class Activity_Dispatcher {
return; return;
} }
$object = Transformers_Manager::instance()->transform( $wp_post ); $object = Transformer_Factory::instance()->transform( $wp_post );
$activity = new Activity(); $activity = new Activity();
$activity->set_type( $type ); $activity->set_type( $type );
@ -101,7 +101,7 @@ class Activity_Dispatcher {
return; return;
} }
$object = Transformers_Manager::instance()->transform( $wp_post ); $object = Transformer_Factory::instance()->transform( $wp_post );
$activity = new Activity(); $activity = new Activity();
$activity->set_type( 'Announce' ); $activity->set_type( 'Announce' );

View file

@ -4,7 +4,7 @@ namespace Activitypub\Rest;
use WP_Error; use WP_Error;
use WP_REST_Server; use WP_REST_Server;
use WP_REST_Response; use WP_REST_Response;
use Activitypub\Transformer\Transformers_Manager; use Activitypub\Transformer\Transformer_Factory;
use Activitypub\Activity\Activity; use Activitypub\Activity\Activity;
use Activitypub\Collection\Users as User_Collection; use Activitypub\Collection\Users as User_Collection;
@ -168,7 +168,7 @@ class Collection {
); );
foreach ( $posts as $post ) { foreach ( $posts as $post ) {
$response['orderedItems'][] = Transformers_Manager::instance()->transform( $post ); $response['orderedItems'][] = Transformer_Factory::instance()->transform( $post );
} }
$rest_response = new WP_REST_Response( $response, 200 ); $rest_response = new WP_REST_Response( $response, 200 );

View file

@ -5,7 +5,7 @@ use stdClass;
use WP_Error; use WP_Error;
use WP_REST_Server; use WP_REST_Server;
use WP_REST_Response; use WP_REST_Response;
use Activitypub\Transformer\Transformers_Manager; use Activitypub\Transformer\Transformer_Factory;
use Activitypub\Activity\Activity; use Activitypub\Activity\Activity;
use Activitypub\Collection\Users as User_Collection; use Activitypub\Collection\Users as User_Collection;
@ -105,7 +105,7 @@ class Outbox {
); );
foreach ( $posts as $post ) { foreach ( $posts as $post ) {
$object = \Activitypub\Transformer\Transformers_Manager::instance()->transform( $post ); $object = \Activitypub\Transformer\Transformer_Factory::instance()->transform( $post );
$activity = new Activity(); $activity = new Activity();
$activity->set_type( 'Create' ); $activity->set_type( 'Create' );
$activity->set_context( null ); $activity->set_context( null );

View file

@ -116,17 +116,20 @@ class Post extends Base {
* @return \Activitypub\Activity\Base_Object The ActivityPub Object * @return \Activitypub\Activity\Base_Object The ActivityPub Object
*/ */
public function transform() { public function transform() {
if ( ! $this->wp_post ) {
return;
}
$object = new Base_Object(); $object = new Base_Object();
$object->set_id( $this->get_id() ); $object->set_id( $this->get_id() );
$object->set_url( $this->get_url() ); $object->set_url( $this->get_url() );
$object->set_type( $this->get_object_type() ); $object->set_type( $this->get_object_type() );
$published = \strtotime( $wp_post->post_date_gmt ); $published = \strtotime( $this->$wp_post->post_date_gmt );
$object->set_published( \gmdate( 'Y-m-d\TH:i:s\Z', $published ) ); $object->set_published( \gmdate( 'Y-m-d\TH:i:s\Z', $published ) );
$updated = \strtotime( $wp_post->post_modified_gmt ); $updated = \strtotime( $this->$wp_post->post_modified_gmt );
if ( $updated > $published ) { if ( $updated > $published ) {
$object->set_updated( \gmdate( 'Y-m-d\TH:i:s\Z', $updated ) ); $object->set_updated( \gmdate( 'Y-m-d\TH:i:s\Z', $updated ) );
@ -135,7 +138,7 @@ class Post extends Base {
$object->set_attributed_to( $this->get_attributed_to() ); $object->set_attributed_to( $this->get_attributed_to() );
$object->set_content( $this->get_content() ); $object->set_content( $this->get_content() );
$object->set_content_map( $this->get_content_map ); $object->set_content_map( $this->get_content_map );
$path = sprintf( 'users/%d/followers', intval( $wp_post->post_author ) ); $path = sprintf( 'users/%d/followers', intval( $this->$wp_post->post_author ) );
$object->set_to( $object->set_to(
array( array(

View file

@ -26,7 +26,7 @@ if ( ! defined( 'ABSPATH' ) ) {
* *
* @since version_number_transformer_management_placeholder * @since version_number_transformer_management_placeholder
*/ */
class Transformers_Manager { class Transformer_Factory {
const DEFAULT_TRANSFORMER_MAPPING = array( const DEFAULT_TRANSFORMER_MAPPING = array(
'post' => ACTIVITYPUB_DEFAULT_TRANSFORMER, 'post' => ACTIVITYPUB_DEFAULT_TRANSFORMER,
'page' => ACTIVITYPUB_DEFAULT_TRANSFORMER, 'page' => ACTIVITYPUB_DEFAULT_TRANSFORMER,
@ -229,7 +229,7 @@ class Transformers_Manager {
* *
* @since version_number_transformer_management_placeholder * @since version_number_transformer_management_placeholder
* *
* @param Transformers_Manager $this The widgets manager. * @param Transformer_Factory $this The widgets manager.
*/ */
do_action( 'activitypub_transformers_register', $this ); do_action( 'activitypub_transformers_register', $this );
} }

View file

@ -2,7 +2,7 @@
// phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
$post = \get_post(); $post = \get_post();
$object = \Activitypub\Transformer\Transformers_Manager::instance()->transform( $post ); $object = \Activitypub\Transformer\Transformer_Factory::instance()->transform( $post );
$json = \array_merge( array( '@context' => \Activitypub\get_context() ), $object->to_array() ); $json = \array_merge( array( '@context' => \Activitypub\get_context() ), $object->to_array() );

View file

@ -237,7 +237,7 @@
return $object->name; return $object->name;
}, $all_public_post_types); }, $all_public_post_types);
$transformer_manager = \Activitypub\Transformer\Transformers_Manager::instance(); $transformer_manager = \Activitypub\Transformer\Transformer_Factory::instance();
$transformers = $transformer_manager->get_transformers(); $transformers = $transformer_manager->get_transformers();
?> ?>

View file

@ -18,7 +18,7 @@ class Test_Activitypub_Activity extends WP_UnitTestCase {
); );
$wp_post = get_post( $post ); $wp_post = get_post( $post );
$activitypub_post = \Activitypub\Transformer\Transformers_Manager::instance()->transform(); $activitypub_post = \Activitypub\Transformer\Transformer_Factory::instance()->transform();
$activitypub_activity = new \Activitypub\Activity\Activity(); $activitypub_activity = new \Activitypub\Activity\Activity();
$activitypub_activity->set_type( 'Create' ); $activitypub_activity->set_type( 'Create' );

View file

@ -10,13 +10,13 @@ class Test_Activitypub_Post extends WP_UnitTestCase {
$permalink = \get_permalink( $post ); $permalink = \get_permalink( $post );
$activitypub_post = \Activitypub\Transformer\Transformers_Manager::instance()->transform( get_post( $post ) ); $activitypub_post = \Activitypub\Transformer\Transformer_Factory::instance()->transform( get_post( $post ) );
$this->assertEquals( $permalink, $activitypub_post->get_id() ); $this->assertEquals( $permalink, $activitypub_post->get_id() );
\wp_trash_post( $post ); \wp_trash_post( $post );
$activitypub_post = \Activitypub\Transformer\Transformers_Manager::instance()->transform( get_post( $post ) ); $activitypub_post = \Activitypub\Transformer\Transformer_Factory::instance()->transform( get_post( $post ) );
$this->assertEquals( $permalink, $activitypub_post->get_id() ); $this->assertEquals( $permalink, $activitypub_post->get_id() );

View file

@ -10,7 +10,7 @@ class Test_Activitypub_Signature_Verification extends WP_UnitTestCase {
) )
); );
$remote_actor = \get_author_posts_url( 2 ); $remote_actor = \get_author_posts_url( 2 );
$activitypub_post = \Activitypub\Transformer\Transformers_Manager::instance()->transform( get_post( $post ) ); $activitypub_post = \Activitypub\Transformer\Transformer_Factory::instance()->transform( get_post( $post ) );
$activitypub_activity = new Activitypub\Activity\Activity( 'Create' ); $activitypub_activity = new Activitypub\Activity\Activity( 'Create' );
$activitypub_activity->set_type( 'Create' ); $activitypub_activity->set_type( 'Create' );
$activitypub_activity->set_object( $activitypub_post ); $activitypub_activity->set_object( $activitypub_post );
@ -82,7 +82,7 @@ class Test_Activitypub_Signature_Verification extends WP_UnitTestCase {
); );
$remote_actor = \get_author_posts_url( 2 ); $remote_actor = \get_author_posts_url( 2 );
$remote_actor_inbox = Activitypub\get_rest_url_by_path( '/inbox' ); $remote_actor_inbox = Activitypub\get_rest_url_by_path( '/inbox' );
$activitypub_post = \Activitypub\Transformer\Transformers_Manager::instance()->transform( get_post( $post ) ); $activitypub_post = \Activitypub\Transformer\Transformer_Factory::instance()->transform( get_post( $post ) );
$activitypub_activity = new Activitypub\Activity\Activity(); $activitypub_activity = new Activitypub\Activity\Activity();
$activitypub_activity->set_type( 'Create' ); $activitypub_activity->set_type( 'Create' );
$activitypub_activity->set_object( $activitypub_post ); $activitypub_activity->set_object( $activitypub_post );