Completed
Push — master ( ec2c00...c3f83b )
by Markus
05:40
created

SampleAppBaseView::execute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 1
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
use Agavi\View\View;
3
use Agavi\Controller\ExecutionContainer;
4
use Agavi\Request\RequestDataHolder;
5
use Agavi\Exception\ViewException;
6
7
class SampleAppBaseView extends View
8
{
9
	/*
10
		This is the base view all your application's views should extend.
11
		This way, you can easily inject new functionality into all of your views.
12
		
13
		One example would be to extend the initialize() method and assign commonly
14
		used objects such as the request as protected class members.
15
		
16
		Even if you don't need any of the above and this class remains empty, it is
17
		strongly recommended you keep it. There shall come the day where you are
18
		happy to have it this way ;)
19
		
20
		This default implementation throws an exception if execute() is called,
21
		which means that no execute*() method specific to the current output type
22
		was declared in your view, and no such method exists in this class either.
23
		
24
		It is of course highly recommended that you change the names of any default
25
		base classes to carry a prefix and have an overall meaningful naming scheme.
26
		You can enable the usage of the respective custom template files via
27
		build.properties settings. Also, keep in mind that you can define templates
28
		for specific modules in case you require this.
29
	*/
30
	
31
	const DEFAULT_SLOT_LAYOUT_NAME = 'slot';
32
	
33
	/**
34
	 * @var        Routing
35
	 */
36
	protected $ro;
37
	
38
	/**
39
	 * @var        Request
40
	 */
41
	protected $rq;
42
	
43
	/**
44
	 * @var        TranslationManager
45
	 */
46
	protected $tm;
47
	
48
	/**
49
	 * @var        AgaviUser
50
	 */
51
	protected $us;
52
	
53
	public function initialize(ExecutionContainer $container)
54
	{
55
		parent::initialize($container);
56
		
57
		$this->ro = $this->getContext()->getRouting();
58
		$this->rq = $this->getContext()->getRequest();
59
		$this->tm = $this->getContext()->getTranslationManager();
60
		$this->us = $this->getContext()->getUser();
61
	}
62
	
63
	public final function execute(RequestDataHolder $rd)
64
	{
65
		throw new ViewException(sprintf(
66
			'The View "%1$s" does not implement an "execute%3$s()" method to serve '.
67
			'the Output Type "%2$s", and the base View "%4$s" does not implement an '.
68
			'"execute%3$s()" method to handle this situation.',
69
			get_class($this),
70
			$this->container->getOutputType()->getName(),
71
			ucfirst(strtolower($this->container->getOutputType()->getName())),
72
			get_class()
73
		));
74
	}
75
	
76
	public function executeHtml(RequestDataHolder $rd)
77
	{
78
		throw new ViewException(sprintf(
79
			'The View "%1$s" does not implement an "execute%3$s()" method to serve '.
80
			'the Output Type "%2$s". It is recommended that you change the code of '.
81
			'the method "execute%3$s()" in the base View "%4$s" that is throwing '.
82
			'this exception to deal with this situation in a more appropriate '.
83
			'way, for example by forwarding to the default 404 error action, or by '.
84
			'showing some other meaningful error message to the user which explains '.
85
			'that the operation was unsuccessful beacuse the desired Output Type is '.
86
			'not implemented.',
87
			get_class($this),
88
			$this->container->getOutputType()->getName(),
89
			ucfirst(strtolower($this->container->getOutputType()->getName())),
90
			get_class()
91
		));
92
	}
93
	
94
	public function executeJson(RequestDataHolder $rd)
95
	{
96
		throw new ViewException(sprintf(
97
			'The View "%1$s" does not implement an "execute%3$s()" method to serve '.
98
			'the Output Type "%2$s". It is recommended that you change the code of '.
99
			'the method "execute%3$s()" in the base View "%4$s" that is throwing '.
100
			'this exception to deal with this situation in a more appropriate '.
101
			'way, for example by forwarding to the default 404 error action, or by '.
102
			'showing some other meaningful error message to the user which explains '.
103
			'that the operation was unsuccessful beacuse the desired Output Type is '.
104
			'not implemented.',
105
			get_class($this),
106
			$this->container->getOutputType()->getName(),
107
			ucfirst(strtolower($this->container->getOutputType()->getName())),
108
			get_class()
109
		));
110
	}
111
	
112
	public function setupHtml(RequestDataHolder $rd, $layoutName = null)
113
	{
114
		if($layoutName === null && $this->getContainer()->getParameter('is_slot', false)) {
115
			$layoutName = self::DEFAULT_SLOT_LAYOUT_NAME;
116
		} else {
117
			// set a default title just to avoid warnings
118
			$this->setAttribute('_title', '');
119
		}
120
		
121
		$this->loadLayout($layoutName);
122
	}
123
}
124
125
?>