Skip to content
This repository has been archived by the owner on Nov 28, 2019. It is now read-only.

Refactor Observer interfaces, provide listener interfaces instead. #54

Open
dnaber-de opened this issue Feb 7, 2016 · 0 comments
Open
Assignees
Milestone

Comments

@dnaber-de
Copy link
Member

The current idea of the observer interface depends on the mutable behavior of the Type\WpImport{TYPE} objects. This has two downsides:

  • it forces the Importer instances to actual call $importType->id( $new_id ); which breaks encapsulation.
  • it is overall redundant. We can solve each task (primarily the ID mapping) by simply listening to the w2m_{TYPE}_imported actions.

Further, the current Import\Data\IdObserverInterface is limited to be used for all types. Listeners to single types are not designated, which violates the interface-segregation principle.

The refactored structure:

interface Import\Data\PostImportListenerInterface {

    /**
     * @wp-hook w2m_post_imported
     *
     * @param WP_Post $wp_post
     * @param Import\Type\ImportPostInterface $import_post
     *
     * @return void
     */
    public function record_post( WP_Post $wp_post, Type\ImportPostInterface $import_post );
}

along with that there are Import\Data\ImportTermListenerInterface, Import\Data\ImportUserListenerInterface and of course Import\Data\ImportCommentListenerInterface.

The Import\Data\IdObserverInterface will be replaced by Import\Data\ImportListenerInterface which is just a »semantic« interface and extends all these new four types:

interface ImportListenerInterface extends 
    ImportPostListenerInterface,
    ImportTermListenerInterface,
    ImportUserListenerInterface,
    ImportCommentListenerInterface 
{}

This requires also a refactoring of Import\Data\PresetUserTypeIdMapper, Import\Data\ImportListeningTypeIdMapper and Controller\DataIdObserverProvider.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant