ViewBase Class Reference
[View]
Basic genric view implementation. More...
Public Member Functions |
|
__construct ($template, $cache_id= '') | |
assign ($var, $value) | |
Pass a variable to the view. |
|
assign_array ($vars) | |
Pass an associative array to the view.
|
|
copy_to ($view) | |
Copy all variables to other view. |
|
create_child_view ($template) | |
Creates a view of type IViewFactory::MESSAGE
and given template and copies all variables set on this view.
|
|
get_cache_id () | |
Returns cache id. |
|
is_cached () | |
Returns true, if a cache entry exists.
|
|
render ($policy=self::NONE) | |
Process view and returnd the created
content. |
|
retrieve ($var) | |
Retrieve a variable from the view. |
|
retrieve_array () | |
Retrieve all variables. |
|
set_cache_id ($cacheid) | |
Set cache id. |
|
Protected Member Functions |
|
after_render (&$rendered_content, $policy) | |
Called after content is rendered, but not if
content is taken from cache. |
|
assign_default_vars ($policy) | |
Assign all default vars. |
|
before_render (&$rendered_content, $policy) | |
Called before content is rendered, but not
if content is taken from cache. |
|
create_template_engine ($engine) | |
Creates a template engine based on template
type. |
|
do_render ($policy) | |
Render. |
|
do_render_cache ($cache, $policy) | |
Read content from cache object. |
|
get_cache_lifetime () | |
Returns cache life time in seconds. |
|
get_cache_object () | |
Reads the cache. |
|
read_cache ($cache_key) | |
Retrieve ressource from cache. |
|
render_content (&$rendered_content, $policy) | |
Sets content. |
|
render_from_cache ($policy) | |
Retrieve item from cache, if cached and
caching is enabled. |
|
render_postprocess (&$rendered_content, $policy) | |
Called after content is rendered, always.
|
|
render_preprocess ($policy) | |
Called before content is rendered, always.
|
|
should_cache () | |
Returns true, if cache should be used.
|
|
split_template ($template) | |
Splites templates into engine and resource.
|
|
store_cache ($cache_key, $content, $lifetime, $policy) | |
Write content to cache. |
|
update_cache (&$data, $policy) | |
Store item in cache, if required. |
|
Protected Attributes |
|
$cache_id | |
$cached_content = null | |
$template | |
$vars = array() |
Detailed Description
Basic genric view implementation.
Definition at line 10 of file viewbase.cls.php.
Constructor & Destructor Documentation
ViewBase::__construct | ( | $ | template, | |
$ | cache_id = '' |
|||
) |
Reimplemented in ContentViewBase, ConsolePageView, and MimeView.
Definition at line 36 of file viewbase.cls.php.
00036 { 00037 $this->template = $template; 00038 $this->set_cache_id($cache_id); 00039 }
Member Function Documentation
ViewBase::after_render | ( | &$ | rendered_content, | |
$ | policy | |||
) | [protected] |
Called after content is rendered, but not if content is taken from cache.
- Parameters:
-
string $rendered_content The content rendered int $policy If set to IView::DISPLAY, content is printed, if false it is returned only
- Returns:
- void
Reimplemented in XmlViewBase, AjaxView, and ConsolePageView.
Definition at line 287 of file viewbase.cls.php.
00287 { 00288 EventSource::Instance()->invoke_event('view_after_render', array('view' => $this, 'policy' => $policy), $rendered_content); 00289 }
ViewBase::assign | ( | $ | var, | |
$ | value | |||
) |
Pass a variable to the view.
- Parameters:
-
string $var The name of the variable as string mixed $value The value
Implements IView.
Definition at line 60 of file viewbase.cls.php.
ViewBase::assign_array | ( | $ | vars | ) |
Pass an associative array to the view.
- Parameters:
-
array $vars Associative array of variable names and values
Implements IView.
Definition at line 69 of file viewbase.cls.php.
00069 { 00070 $this->vars = array_merge($this->vars, $vars); 00071 }
ViewBase::assign_default_vars | ( | $ | policy | ) | [protected] |
Assign all default vars.
- Parameters:
-
int $policy If set to IView::DISPLAY, content is printed, if false it is returned only
Reimplemented in ContentViewBase, PageViewBase, AjaxView, and ConsolePageView.
Definition at line 380 of file viewbase.cls.php.
00380 { 00381 $this->assign('self', $this); 00382 $this->assign('appname', Config::get_value(Config::TITLE)); 00383 $this->assign('baseurl', Config::get_value(Config::URL_BASEDIR)); 00384 $this->assign('baseurl_ssl', Config::get_url(Config::URL_BASEURL_SAFE)); 00385 $this->assign('baseurl_http', Config::get_url(Config::URL_BASEURL)); 00386 $this->assign('url_self', Url::current()->clear_query()->build(Url::RELATIVE)); 00387 $this->assign('applang', GyroLocale::get_language()); 00388 $this->assign('appcharset', GyroLocale::get_charset()); 00389 00390 $imageurl = Config::get_url(Config::URL_IMAGES); 00391 $this->assign('imageurl', $imageurl); 00392 if (strpos($imageurl, '//') === false) { 00393 $imageurl = Config::get_url(Config::URL_SERVER) . $imageurl; 00394 } 00395 $this->assign('imageurl_http', $imageurl); 00396 }
ViewBase::before_render | ( | &$ | rendered_content, | |
$ | policy | |||
) | [protected] |
Called before content is rendered, but not if content is taken from cache.
- Parameters:
-
string $rendered_content The content rendered int $policy If set to IView::DISPLAY, content is printed, if false it is returned only
- Returns:
- void
Definition at line 276 of file viewbase.cls.php.
00276 { 00277 EventSource::Instance()->invoke_event('view_before_render', array('view' => $this, 'policy' => $policy), $rendered_content); 00278 }
ViewBase::copy_to | ( | $ | view | ) |
Copy all variables to other view.
- Parameters:
-
IView $view
Implements IView.
Definition at line 97 of file viewbase.cls.php.
ViewBase::create_child_view | ( | $ | template | ) |
Creates a view of type IViewFactory::MESSAGE and given template and copies all variables set on this view.
- Parameters:
-
string $template
- Returns:
- IView
Definition at line 48 of file viewbase.cls.php.
00048 { 00049 $view = ViewFactory::create_view(IViewFactory::MESSAGE, $template); 00050 $this->copy_to($view); 00051 return $view; 00052 }
ViewBase::create_template_engine | ( | $ | engine | ) | [protected] |
Creates a template engine based on template type.
The template engine to choose is detected by a template protocol. E.g. "core::template" will use the core template engine, while "myengine::template" will use "myengine". If the protocol is ommitet, DEFAULT_TEMPLATE_ENGINE is used.
- Parameters:
-
string $engine A string specifying the engine
- Returns:
- ITemplateEngine
Definition at line 336 of file viewbase.cls.php.
00336 { 00337 Load::directories('view/templateengines/' . $engine); 00338 require_once dirname(__FILE__) . '/templatepathresolver.cls.php'; 00339 $cls = 'TemplateEngine' . ucfirst($engine); // $engine is supposed to be ASCII 00340 return new $cls(); 00341 }
ViewBase::do_render | ( | $ | policy | ) | [protected] |
Render.
- Parameters:
-
int $policy If set to IView::DISPLAY, content is printed, if false it is returned only
- Returns:
- mixed
Definition at line 239 of file viewbase.cls.php.
00239 { 00240 $timer = new Timer(); 00241 00242 $this->assign_default_vars($policy); 00243 $ret = ''; 00244 $this->before_render($ret, $policy); 00245 $this->render_content($ret, $policy); 00246 $this->after_render($ret, $policy); 00247 return $ret; 00248 }
ViewBase::do_render_cache | ( | $ | cache, | |
$ | policy | |||
) | [protected] |
Read content from cache object.
- Parameters:
-
int $policy If set to IView::DISPLAY, content is printed, if false it is returned only ICacheItem $cache ICacheItem instance
- Returns:
- mixed
Reimplemented in PageViewBase.
Definition at line 371 of file viewbase.cls.php.
ViewBase::get_cache_id | ( | ) |
Returns cache id.
- Returns:
- mixed
Implements ICache.
Definition at line 106 of file viewbase.cls.php.
ViewBase::get_cache_lifetime | ( | ) | [protected] |
Returns cache life time in seconds.
- Returns:
- int
Reimplemented in PageViewBase.
Definition at line 154 of file viewbase.cls.php.
00154 { 00155 return 2 * GyroDate::ONE_HOUR; // 2 hours 00156 }
ViewBase::get_cache_object | ( | ) | [protected] |
Reads the cache.
- Returns:
- ICacheItem
Definition at line 142 of file viewbase.cls.php.
00142 { 00143 if (is_null($this->cached_content)) { 00144 $this->cached_content = $this->should_cache() ? $this->read_cache($this->cache_id) : false; 00145 } 00146 return $this->cached_content; 00147 }
ViewBase::is_cached | ( | ) |
Returns true, if a cache entry exists.
- Returns:
- bool
Implements ICache.
Definition at line 133 of file viewbase.cls.php.
00133 { 00134 return ($this->get_cache_object() !== false); 00135 }
ViewBase::read_cache | ( | $ | cache_key | ) | [protected] |
Retrieve ressource from cache.
- Parameters:
-
string $cache_key Either a string or an array
- Returns:
- ICacheItem
Definition at line 360 of file viewbase.cls.php.
00360 { 00361 return Cache::read($cache_key); 00362 }
ViewBase::render | ( | $ | policy =
self::NONE |
) |
Process view and returnd the created content.
The control flow on rendering is as follows:
A) If item is not cached or caching is disabled
1. render_preprocess 2. render_from_cache 3. do_render 3.1 before_render 3.2 render_content 3.3 after_render 4. update_cache 4.1 store_cache (if item should be cached) 5. render_postprocess
B) If item is cached and caching is enabled
1. render_preprocess 2. render_from_cache 2.1 do_render_cache 3. update_cache 4. render_postprocess
- Parameters:
-
int $policy If set to IView::DISPLAY, content is printed, if false it is returned only
- Returns:
- string The rendered content
Implements IRenderer.
Reimplemented in ContentViewBase, PageViewBase, and ConsolePageView.
Definition at line 186 of file viewbase.cls.php.
00186 { 00187 $this->render_preprocess($policy); 00188 00189 $ret = ''; 00190 $ret = $this->render_from_cache($policy); 00191 // Cache may be empty, so check that 00192 if (empty($ret)) { 00193 $ret = $this->do_render($policy); 00194 } 00195 $this->update_cache($ret, $policy); 00196 $this->render_postprocess($ret, $policy); 00197 00198 if (Common::flag_is_set($policy, self::DISPLAY)) { 00199 print $ret; 00200 } 00201 return $ret; 00202 }
ViewBase::render_content | ( | &$ | rendered_content, | |
$ | policy | |||
) | [protected] |
Sets content.
- Parameters:
-
string $rendered_content The content rendered int $policy If set to IView::DISPLAY, content is printed, if false it is returned only
- Returns:
- void
Reimplemented in PageViewBase, and AjaxView.
Definition at line 298 of file viewbase.cls.php.
00298 { 00299 $arr_engine = $this->split_template($this->template); 00300 $template_engine = $this->create_template_engine($arr_engine['engine']); 00301 $template_engine->assign_array($this->vars); 00302 $rendered_content = $template_engine->fetch($arr_engine['resource']); 00303 }
ViewBase::render_from_cache | ( | $ | policy | ) | [protected] |
Retrieve item from cache, if cached and caching is enabled.
- Parameters:
-
int $policy
- Returns:
- mixed
Definition at line 210 of file viewbase.cls.php.
00210 { 00211 $ret = ''; 00212 if (!Common::flag_is_set($policy, self::NO_CACHE) && $this->is_cached()) { 00213 $ret = $this->do_render_cache($this->get_cache_object(), $policy); 00214 } 00215 return $ret; 00216 }
ViewBase::render_postprocess | ( | &$ | rendered_content, | |
$ | policy | |||
) | [protected] |
Called after content is rendered, always.
- Parameters:
-
mixed $rendered_content The content rendered int $policy If set to IView::DISPLAY, content is printed, if false it is returned only
- Returns:
- void
Reimplemented in PageViewBase, AjaxView, ConsolePageView, and MimeView.
Definition at line 266 of file viewbase.cls.php.
ViewBase::render_preprocess | ( | $ | policy | ) | [protected] |
Called before content is rendered, always.
- Parameters:
-
int $policy If set to IView::DISPLAY, content is printed, if false it is returned only
- Returns:
- void
Reimplemented in PageViewBase, XmlViewBase, and ConsolePageView.
Definition at line 256 of file viewbase.cls.php.
ViewBase::retrieve | ( | $ | var | ) |
Retrieve a variable from the view.
- Parameters:
-
string $var The name of the variable as string
- Returns:
- mixed The Value
Implements IView.
Definition at line 79 of file viewbase.cls.php.
00079 { 00080 return Arr::get_item($this->vars, $var, false); 00081 }
ViewBase::retrieve_array | ( | ) |
Retrieve all variables.
- Returns:
- array Associative array
Implements IView.
Definition at line 88 of file viewbase.cls.php.
ViewBase::set_cache_id | ( | $ | cacheid | ) |
Set cache id.
- Parameters:
-
string|array $cacheid A cache id, a string or an array
Implements ICache.
Definition at line 115 of file viewbase.cls.php.
ViewBase::should_cache | ( | ) | [protected] |
Returns true, if cache should be used.
- Returns:
- bool
Reimplemented in PageViewBase, AjaxView, ConsolePageView, and MimeView.
Definition at line 124 of file viewbase.cls.php.
ViewBase::split_template | ( | $ | template | ) | [protected] |
Splites templates into engine and resource.
- Parameters:
-
string $template String of type engine:resource
Definition at line 310 of file viewbase.cls.php.
00310 { 00311 $arr_ret = array( 00312 'engine' => Config::get_value(Config::DEFAULT_TEMPLATE_ENGINE), 00313 'resource' => $template 00314 ); 00315 $pos_colon = is_string($template) ? strpos($template, '::') : false; 00316 if ($pos_colon !== false) { 00317 // There is a "::" in the template file name, so use this as protocol 00318 // Example core::page => $engine = core, $template = page 00319 $arr_ret['engine'] = substr($template, 0, $pos_colon); 00320 $arr_ret['resource'] = substr($template, $pos_colon + 2); 00321 } 00322 return $arr_ret; 00323 }
ViewBase::store_cache | ( | $ | cache_key, | |
$ | content, | |||
$ | lifetime, | |||
$ | policy | |||
) | [protected] |
Write content to cache.
- Parameters:
-
string|array $cache_key Either a string or an array string $content Content to cache as string int $lifetime Lifetime in seconds
Reimplemented in PageViewBase.
Definition at line 350 of file viewbase.cls.php.
00350 { 00351 Cache::store($cache_key, $content, $lifetime); 00352 }
ViewBase::update_cache | ( | &$ | data, | |
$ | policy | |||
) | [protected] |
Store item in cache, if required.
- Parameters:
-
string $data int $policy
Definition at line 224 of file viewbase.cls.php.
00224 { 00225 if (!Common::flag_is_set($policy, self::NO_CACHE) 00226 && !$this->is_cached() 00227 && $this->should_cache()) 00228 { 00229 $this->store_cache($this->cache_id, $data, $this->get_cache_lifetime(), $policy); 00230 } 00231 }
Member Data Documentation
ViewBase::$cache_id
[protected] |
Definition at line 28 of file viewbase.cls.php.
ViewBase::$cached_content = null
[protected] |
Definition at line 16 of file viewbase.cls.php.
ViewBase::$template
[protected] |
Definition at line 34 of file viewbase.cls.php.
ViewBase::$vars = array()
[protected] |
Definition at line 22 of file viewbase.cls.php.
The documentation for this class was generated from the following file:
- gyro/core/view/base/viewbase.cls.php