-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWpWidgetFactory.php
More file actions
52 lines (44 loc) · 1.33 KB
/
WpWidgetFactory.php
File metadata and controls
52 lines (44 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* WP Widget Factory
*
* @author Whizark <devaloka@whizark.com>
* @see http://whizark.com
* @copyright Copyright (C) 2014 Whizark.
* @license MIT
* @license GPL-2.0
* @license GPL-3.0
*/
namespace Devaloka\Component\Wp;
use ReflectionClass;
use WP_Widget_Factory;
use Devaloka\Component\DependencyInjection\ContainerAwareTrait;
use Devaloka\Component\DependencyInjection\ContainerAwareInterface;
use Devaloka\Provider\EventListenerProviderInterface;
/**
* Class WpWidgetFactory
*
* @package Devaloka\Component\Wp
*/
class WpWidgetFactory extends WP_Widget_Factory implements ContainerAwareInterface
{
use ContainerAwareTrait;
public function register($widgetClass)
{
$arguments = array_slice(func_get_args(), 1);
$class = new ReflectionClass($widgetClass);
$widget = $class->newInstanceArgs($arguments);
if ($widget instanceof ContainerAwareInterface) {
$widget->setContainer($this->container);
}
if ($widget instanceof EventListenerProviderInterface) {
$widget->subscribe(
$this->container->get('devaloka'),
$this->container->get('container'),
$this->container->get('event_dispatcher')
);
}
$this->widgets[$widgetClass] = $widget;
return $widget;
}
}