Source for file Control.php
Documentation is available at Control.php
6: * Copyright (c) 2004, 2009 David Grudl (http://davidgrudl.com)
8: * This source file is subject to the "Nette license" that is bundled
9: * with this package in the file license.txt.
11: * For more information please see http://nettephp.com
13: * @copyright Copyright (c) 2004, 2009 David Grudl
14: * @license http://nettephp.com/license Nette license
15: * @link http://nettephp.com
17: * @package Nette\Application
22: require_once dirname(__FILE__) .
'/../Application/PresenterComponent.php';
24: require_once dirname(__FILE__) .
'/../Application/IRenderable.php';
29: * Control is renderable component.
31: * @author David Grudl
32: * @copyright Copyright (c) 2004, 2009 David Grudl
33: * @package Nette\Application
35: * @property-read ITemplate $template
39: /** @var ITemplate */
43: private $invalidSnippets =
array();
47: /********************* template factory ****************d*g**/
56: if ($this->template ===
NULL) {
58: if (!($value instanceof
ITemplate ||
$value ===
NULL)) {
60: throw new UnexpectedValueException("Object returned by $this->class::createTemplate() must be instance of Nette\\Templates\\ITemplate, '$class' given.");
62: $this->template =
$value;
64: return $this->template;
76: $template->onPrepareFilters[] =
array($this, 'templatePrepareFilters');
78: // default parameters
79: $template->component =
$this; // DEPRECATED!
80: $template->control =
$this;
81: $template->presenter =
$presenter;
83: $template->basePath =
rtrim($template->baseUri, '/');
86: if ($presenter !==
NULL &&
$presenter->hasFlashSession()) {
88: $template->flashes =
$presenter->getFlashSession()->$id;
90: if (!isset($template->flashes) ||
!is_array($template->flashes)) {
91: $template->flashes =
array();
95: $template->registerHelper('escape', 'Nette\Templates\TemplateHelpers::escapeHtml');
96: $template->registerHelper('escapeUrl', 'rawurlencode');
97: $template->registerHelper('stripTags', 'strip_tags');
98: $template->registerHelper('nl2br', 'nl2br');
99: $template->registerHelper('substr', 'iconv_substr');
100: $template->registerHelper('repeat', 'str_repeat');
101: $template->registerHelper('implode', 'implode');
102: $template->registerHelper('number', 'number_format');
103: $template->registerHelperLoader('Nette\Templates\TemplateHelpers::loader');
111: * Descendant can override this method to customize template compile-time filters.
124: * Returns widget component specified by name.
126: * @return IComponent
136: * Saves the message to template, that can be displayed after redirect.
145: $messages[] =
$flash = (object)
array(
146: 'message' =>
$message,
156: /********************* rendering ****************d*g**/
161: * Forces control or its snippet to repaint.
167: $this->invalidSnippets[$snippet] =
TRUE;
173: * Allows control or its snippet to not repaint.
179: if ($snippet ===
NULL) {
180: $this->invalidSnippets =
array();
183: unset($this->invalidSnippets[$snippet]);
190: * Is required to repaint the control or its snippet?
191: * @param string snippet name
196: if ($snippet ===
NULL) {
197: if (count($this->invalidSnippets) >
0) {
202: if ($component instanceof
IRenderable &&
$component->isControlInvalid()) {
203: // $this->invalidSnippets['__child'] = TRUE; // as cache
211: return isset($this->invalidSnippets[NULL]) ||
isset($this->invalidSnippets[$snippet]);
218: * Returns snippet HTML ID.
219: * @param string snippet name
224: // HTML 4 ID & NAME: [A-Za-z][A-Za-z0-9:_.-]*