|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
4
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
|
5
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
|
6
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
|
7
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
|
8
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace ZfTwitterWidget\View; |
|
12
|
|
|
|
|
13
|
|
|
use InvalidArgumentException; |
|
14
|
|
|
use TwitterWidgets\Options\WidgetOptions; |
|
15
|
|
|
use TwitterWidgets\Options\WidgetOptionsInterface; |
|
16
|
|
|
use TwitterWidgets\Timeline\TimelineBuilderInterface; |
|
17
|
|
|
use Zend\View\Helper\AbstractHelper; |
|
18
|
|
|
|
|
19
|
|
|
class TwViewHelper extends AbstractHelper |
|
20
|
|
|
{ |
|
21
|
|
|
protected $widgetOptions; |
|
22
|
|
|
protected $timeline; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @param WidgetOptions $widgetOptions |
|
26
|
|
|
* @param TimelineBuilderInterface $timeline |
|
27
|
|
|
*/ |
|
28
|
3 |
|
public function __construct(WidgetOptions $widgetOptions, TimelineBuilderInterface $timeline) |
|
29
|
|
|
{ |
|
30
|
3 |
|
$this->widgetOptions = $widgetOptions; |
|
31
|
3 |
|
$this->timeline = $timeline; |
|
32
|
3 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param array|WidgetOptionsInterface $options |
|
36
|
|
|
* @param bool $addJs |
|
37
|
|
|
* @return string |
|
38
|
|
|
* @throws InvalidArgumentException |
|
39
|
|
|
*/ |
|
40
|
2 |
|
public function __invoke($options, $addJs = true) |
|
41
|
|
|
{ |
|
42
|
2 |
|
if (!is_array($options) && !($options instanceof WidgetOptionsInterface)) { |
|
43
|
1 |
|
throw new InvalidArgumentException( |
|
44
|
1 |
|
'"options" must be an array or an implementation of WidgetOptionsInterface' |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
1 |
|
$this->widgetOptions->setFromArray($options); |
|
48
|
|
|
|
|
49
|
1 |
|
return $this->timeline->renderWidget($addJs); |
|
50
|
|
|
} |
|
51
|
|
|
} |
|
52
|
|
|
|