[wp-trac] [WordPress Trac] #28216: Allow to register pre-instantiated widgets
WordPress Trac
noreply at wordpress.org
Thu May 14 18:07:30 UTC 2015
#28216: Allow to register pre-instantiated widgets
-------------------------------+------------------------------
Reporter: Denis-de-Bernardy | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Widgets | Version: 3.9.1
Severity: normal | Resolution:
Keywords: | Focuses:
-------------------------------+------------------------------
Comment (by westonruter):
Replying to [comment:6 Denis-de-Bernardy]:
> The use-case for dependency injection is probably too broad for a Trac
answer. In a nutshell, though, it's about composition, loose coupling, and
testability. A URL for further reading:
>
> http://stackoverflow.com/q/130794/417194
>
> In the event it needs to be stressed, the purpose to be play better with
PHP frameworks such as Symfony 2:
>
>
http://symfony.com/doc/current/components/dependency_injection/index.html
>
> I was looking into creating a sensible WP Widget wrapper that played
well with a Symfony DIC when I opened this ticket.
Why not use setter injection or property injection instead of constructor
injection? For instance:
{{{#!php
<?php
add_action( 'widgets_init', function () {
/** @var \WP_Widget_Factory $wp_widget_factory */
global $wp_widget_factory;
register_widget( 'My_Widget' );
$wp_widget_factory->widgets['My_Widget']->otherDependency = $foo;
} );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/28216#comment:7>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list