inpsyde / wpml2mlp

Convert posts from an existing WPML multilingual site via WXR Export/Import for MultilingualPress
https://wordpress.org/plugins/wpml-to-multilingualpress/
GNU General Public License v2.0
10 stars 6 forks source link

Refactor Observer interfaces, provide listener interfaces instead. #54

Open dnaber-de opened 8 years ago

dnaber-de commented 8 years ago

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

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.