/** * @return TWebControlDecorator */ public function getDecorator($create = true) { if ($create && !$this->_decorator) { $this->_decorator = Prado::createComponent('TWebControlDecorator', $this); } return $this->_decorator; }
function insertBrick($sender, $param) { $x = Prado::createComponent("Application.pages.LTemplate"); $x->Size = $sender->NamingContainer->findControl("MySize")->SelectedValue; $this->placeholder->getControls()->add($x); $this->Page->CallbackClient->insertContentAfter($this->AjaxInsertPoint, $x); }
/** * Runs the service. * This method is invoked by application automatically. */ public function run() { $id = $this->getRequest()->getServiceParameter(); if (isset($this->_feeds[$id])) { $feedConfig = $this->_feeds[$id]; $properties = $feedConfig->getAttributes(); if (($class = $properties->remove('class')) !== null) { $feed = Prado::createComponent($class); if ($feed instanceof IFeedContentProvider) { // init feed properties foreach ($properties as $name => $value) { $feed->setSubproperty($name, $value); } $feed->init($feedConfig); $content = $feed->getFeedContent(); //$this->getResponse()->setContentType('application/rss+xml'); $this->getResponse()->setContentType($feed->getContentType()); $this->getResponse()->write($content); } else { throw new TConfigurationException('feedservice_feedtype_invalid', $id); } } else { throw new TConfigurationException('feedservice_class_required', $id); } } else { throw new THttpException(404, 'feedservice_feed_unknown', $id); } }
/** * Creates a new instance of a particular class (for PHP primative types, * their corresponding default value for given type is used). * @param string PHP type name * @return mixed default type value, if no type is specified null is returned. * @throws TSqlMapException if class name is not found. */ public function createInstanceOf($type = '') { if (strlen($type) > 0) { switch (strtolower($type)) { case 'string': return ''; case 'array': return array(); case 'float': case 'double': case 'decimal': return 0.0; case 'integer': case 'int': return 0; case 'bool': case 'boolean': return false; } if (class_exists('Prado', false)) { return Prado::createComponent($type); } else { if (class_exists($type, false)) { //NO auto loading return new $type(); } else { throw new TSqlMapException('sqlmap_unable_to_find_class', $type); } } } }
protected function getThumbnailGenerator() { if (is_null($this->_thumbnailGen)) { $this->_thumbnailGen = Prado::createComponent($this->getThumbnailGeneratorClass()); } return $this->_thumbnailGen; }
function button2_onclick($sender, $param) { $this->label1->Text = "Button 1 was clicked "; $this->label1->Text .= $this->foo->Text; $x = Prado::createComponent('Application.pages.CustomTemplateComponent'); $this->placeholder->getControls()->add($x); $this->placeholder->dataBind(); }
function onLoad($param) { new TActiveButton(); for ($i = 0; $i < 1500; $i++) { $ctl = Prado::createComponent("TLabel"); $ctl->Text = "Label " . $i; $this->Controls[] = $ctl; } }
/** * Sets the location of image file of the THyperLink. * @param string the image file location */ public function setImageUrl($value) { parent::setImageUrl($value); if ($this->getActiveControl()->canUpdateClientSide() && $value !== '') { $textWriter = new TTextWriter(); $renderer = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), $textWriter); $this->createImage($value)->renderControl($renderer); $this->getPage()->getCallbackClient()->update($this, $textWriter->flush()); } }
/** * Gets the statement analyser of type given by * {@link setStatementAnalyserClass StatementAnalyserClass }. * @return IDbStatementAnalysis statement analyser. */ public function getStatementAnalyser() { if ($this->_statementAnalyser === null) { $this->setActive(true); $this->_statementAnalyser = Prado::createComponent($this->getStatementAnalyserClass()); if ($this->getActive()) { $this->_statementAnalyser->setDriverName($this->getDriverName()); } } return $this->_statementAnalyser; }
/** * Renders body content. * This method overrides the parent implementation by replacing * the body content with the processed text content. * @param THtmlWriter writer */ public function renderContents($writer) { if (($text = $this->getText()) === '' && $this->getHasControls()) { $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter()); parent::renderContents($htmlWriter); $text = $htmlWriter->flush(); } if ($text !== '') { $writer->write($this->processText($text)); } }
/** * Gets the TImage for rendering the ImageUrl property. This is not for * creating dynamic images. * @param string image url. * @return TImage image control for rendering. */ protected function createImage($imageUrl) { $image = Prado::createComponent('System.Web.UI.WebControls.TImage'); $image->setImageUrl($imageUrl); if (($toolTip = $this->getToolTip()) !== '') { $image->setToolTip($toolTip); } if (($text = $this->getText()) !== '') { $image->setAlternateText($text); } $image->setBorderWidth('0'); return $image; }
/** * Returns an implementation of a Dao type, implements the Registery * pattern. Multiple calls returns the same Dao instance. * @param string Dao type to find. * @return object instance of the Dao implementation. */ public function getDao($class) { if (isset($this->_dao[$class])) { if (!isset($this->_dao[$class]['instance'])) { $dao = Prado::createComponent($this->_dao[$class]['class']); $dao->setSqlMap($this->getClient()); $this->_dao[$class]['instance'] = $dao; } return $this->_dao[$class]['instance']; } else { throw new TimeTrackerException('daomanager_undefined_dao', $class); } }
/** * Client-side Text property can only be updated after the OnLoad stage. * @param string text content for the textbox */ public function setText($value) { parent::setText($value); if ($this->getActiveControl()->canUpdateClientSide() && $this->getHasLoadedPostData()) { $cb = $this->getPage()->getCallbackClient(); $cb->setValue($this, $value); if ($this->getInputMode() == TDatePickerInputMode::DropDownList) { $s = Prado::createComponent('System.Util.TDateTimeStamp'); $date = $s->getDate($this->getTimeStampFromText()); $id = $this->getClientID(); $cb->select($id . TControl::CLIENT_ID_SEPARATOR . 'day', 'Value', $date['mday'], 'select'); $cb->select($id . TControl::CLIENT_ID_SEPARATOR . 'month', 'Value', $date['mon'] - 1, 'select'); $cb->select($id . TControl::CLIENT_ID_SEPARATOR . 'year', 'Value', $date['year'], 'select'); } } }
protected function matchCountries($token) { $info = Prado::createComponent('System.I18N.core.CultureInfo', 'en'); $list = array(); $count = 0; $token = strtolower($token); foreach ($info->getCountries() as $country) { if (strpos(strtolower($country), $token) === 0) { $list[] = $country; $count++; if ($count > 10) { break; } } } return $list; }
/** * Loads configuration from an XML element * @param TXmlElement configuration node * @throws TConfigurationException if log route class or type is not specified */ private function loadConfig($xml) { foreach ($xml->getElementsByTagName('route') as $routeConfig) { $properties = $routeConfig->getAttributes(); if (($class = $properties->remove('class')) === null) { throw new TConfigurationException('logrouter_routeclass_required'); } $route = Prado::createComponent($class); if (!$route instanceof TLogRoute) { throw new TConfigurationException('logrouter_routetype_invalid'); } foreach ($properties as $name => $value) { $route->setSubproperty($name, $value); } $this->_routes[] = $route; $route->init($routeConfig); } }
/** * Renders the form. * @param THtmlWriter writer */ public function render($writer) { $page = $this->getPage(); $page->beginFormRender($writer); $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter()); $this->renderChildren($htmlWriter); $content = $htmlWriter->flush(); $page->endFormRender($writer); $this->addAttributesToRender($writer); $writer->renderBeginTag('form'); $cs = $page->getClientScript(); if ($page->getClientSupportsJavaScript()) { $cs->renderHiddenFields($writer); $cs->renderScriptFiles($writer); $cs->renderBeginScripts($writer); $writer->write($content); $cs->renderEndScripts($writer); } else { $cs->renderHiddenFields($writer); $writer->write($content); } $writer->renderEndTag(); }
/** * Initializes the footer cell. * * This method attempts to use {@link getFooterRenderer FooterRenderer} to * instantiate the footer cell. If that is not available, it will populate * the cell with a text string specified by {@link getFooterImageUrl FooterImageUrl} * * @param TTableCell the cell to be initialized * @param integer the index to the Columns property that the cell resides in. */ protected function initializeFooterCell($cell, $columnIndex) { $text = $this->getFooterText(); if (($classPath = $this->getFooterRenderer()) !== '') { $control = Prado::createComponent($classPath); $cell->getControls()->add($control); if ($control instanceof IDataRenderer) { if ($control instanceof IItemDataRenderer) { $item = $cell->getParent(); $control->setItemIndex($item->getItemIndex()); $control->setItemType($item->getItemType()); } $control->setData($text); } } else { if ($text !== '') { $cell->setText($text); } else { $cell->setText(' '); } } }
/** * renders the translated string. */ public function render($writer) { $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter()); $subs = array(); foreach ($this->getParameters() as $key => $value) { $subs['{' . $key . '}'] = $value; } foreach ($this->getControls() as $control) { if ($control instanceof TTranslateParameter) { $subs['{' . $control->getKey() . '}'] = $control->getParameter(); } elseif ($control instanceof TControl) { $control->render($htmlWriter); } elseif (is_string($control)) { $htmlWriter->write($control); } } $text = $this->getText(); if (strlen($text) == 0) { $text = $htmlWriter->flush(); } if ($this->getTrim()) { $text = trim($text); } $writer->write($this->translateText($text, $subs)); }
/** * Load cache models from xml mapping. * @param SimpleXmlElement cache node. */ protected function loadCacheModel($node) { $cacheModel = new TSqlMapCacheModel(); $properties = array('id', 'implementation'); foreach ($node->attributes() as $name => $value) { if (in_array(strtolower($name), $properties)) { $cacheModel->{'set' . $name}((string) $value); } } $cache = Prado::createComponent($cacheModel->getImplementationClass(), $cacheModel); $this->setObjectPropFromNode($cache, $node, $properties); foreach ($node->xpath('property') as $propertyNode) { $name = $propertyNode->attributes()->name; if ($name === null || $name === '') { continue; } $value = $propertyNode->attributes()->value; if ($value === null || $value === '') { continue; } if (!TPropertyAccess::has($cache, $name)) { continue; } TPropertyAccess::set($cache, $name, $value); } $this->loadFlushInterval($cacheModel, $node); $cacheModel->initialize($cache); $this->_manager->addCacheModel($cacheModel); foreach ($node->xpath('flushOnExecute') as $flush) { $this->loadFlushOnCache($cacheModel, $node, $flush); } }
/** * Format a date according to the pattern. * @param mixed the time as integer or string in strtotime format. * @return string formatted date time. */ public function format($time, $pattern = 'F', $charset = 'UTF-8') { if (is_numeric($time)) { //assumes unix epoch $time = floatval($time); } else { if (is_string($time)) { $time = @strtotime($time); } } if ($pattern === null) { $pattern = 'F'; } $s = Prado::createComponent('System.Util.TDateTimeStamp'); $date = $s->getDate($time); $pattern = $this->getPattern($pattern); $tokens = $this->getTokens($pattern); for ($i = 0, $k = count($tokens); $i < $k; ++$i) { $pattern = $tokens[$i]; if ($pattern[0] == "'" && $pattern[strlen($pattern) - 1] == "'") { $sub = preg_replace('/(^\')|(\'$)/', '', $pattern); $tokens[$i] = str_replace('``````', '\'', $sub); } else { if ($pattern == '``````') { $tokens[$i] = '\''; } else { $function = $this->getFunctionName($pattern); if ($function != null) { $fName = 'get' . $function; if (in_array($fName, $this->methods)) { $rs = $this->{$fName}($date, $pattern); $tokens[$i] = $rs; } else { throw new Exception('function ' . $function . ' not found.'); } } } } } return I18N_toEncoding(implode('', $tokens), $charset); }
/** * Determine if the given value is of a particular type using RegExp. * @param string value to check * @return boolean true if value fits the type expression. */ protected function evaluateDataTypeCheck($value) { if ($value == '') { return true; } switch ($this->getDataType()) { case TValidationDataType::Integer: return preg_match('/^[-+]?[0-9]+$/', trim($value)); case TValidationDataType::Float: return preg_match('/^[-+]?([0-9]*\\.)?[0-9]+([eE][-+]?[0-9]+)?$/', trim($value)); case TValidationDataType::Date: $dateFormat = $this->getDateFormat(); if (strlen($dateFormat)) { $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter', $dateFormat); return $formatter->isValidDate($value); } else { return strtotime($value) > 0; } } return true; }
/** * Returns the localized month names that depends on the month format pattern. * "MMMM" will return the month names, "MM" or "MMM" return abbr. month names * and "M" return month digits. * @param DateTimeFormatInfo localized date format information. * @return array localized month names. */ protected function getLocalizedMonthNames($info) { $formatter = Prado::createComponent('System.Util.TSimpleDateFormatter', $this->getDateFormat()); switch ($formatter->getMonthPattern()) { case 'MMM': return $info->getAbbreviatedMonthNames(); case 'MM': $array = array(); for ($i = 1; $i <= 12; $i++) { $array[$i - 1] = $i < 10 ? '0' . $i : $i; } return $array; case 'M': $array = array(); for ($i = 1; $i <= 12; $i++) { $array[$i - 1] = $i; } return $array; default: return $info->getMonthNames(); } }
/** * Creates a button and initializes its properties. * The button type is determined by {@link getButtonType ButtonType}. * @param string command name associated with the button * @param string button caption * @param boolean whether the button should cause validation * @param string the validation group that the button belongs to * @return mixed the newly created button. */ protected function createButton($commandName, $text, $causesValidation, $validationGroup) { if ($this->getButtonType() === TButtonColumnType::LinkButton) { $button = Prado::createComponent('System.Web.UI.WebControls.TLinkButton'); } else { if ($this->getButtonType() === TButtonColumnType::PushButton) { $button = Prado::createComponent('System.Web.UI.WebControls.TButton'); } else { $button = Prado::createComponent('System.Web.UI.WebControls.TImageButton'); if (strcasecmp($commandName, 'Update') === 0) { $url = $this->getUpdateImageUrl(); } else { if (strcasecmp($commandName, 'Cancel') === 0) { $url = $this->getCancelImageUrl(); } else { $url = $this->getEditImageUrl(); } } $button->setImageUrl($url); } } $button->setText($text); $button->setCommandName($commandName); $button->setCausesValidation($causesValidation); $button->setValidationGroup($validationGroup); return $button; }
/** * @return IPageStatePersister page state persister */ public function getStatePersister() { if ($this->_statePersister === null) { $this->_statePersister = Prado::createComponent($this->_statePersisterClass); if (!$this->_statePersister instanceof IPageStatePersister) { throw new TInvalidDataTypeException('page_statepersister_invalid'); } $this->_statePersister->setPage($this); } return $this->_statePersister; }
private function buildUrlMapping($class, $pattern, $properties, $url) { $pattern = Prado::createComponent($class, $this); if (!$pattern instanceof TUrlMappingPattern) { throw new TConfigurationException('urlmapping_urlmappingpattern_required'); } foreach ($properties as $name => $value) { $pattern->setSubproperty($name, $value); } $this->_patterns[] = $pattern; $pattern->init($url); $key = $pattern->getServiceID() . ':' . $pattern->getServiceParameter(); $this->_constructRules[$key][] = $pattern; }
public function startService($serviceID) { if (isset($this->_services[$serviceID])) { list($serviceClass, $initProperties, $configElement) = $this->_services[$serviceID]; $service = Prado::createComponent($serviceClass); if (!$service instanceof IService) { throw new THttpException(500, 'application_service_invalid', $serviceClass); } if (!$service->getEnabled()) { throw new THttpException(500, 'application_service_unavailable', $serviceClass); } $service->setID($serviceID); $this->setService($service); foreach ($initProperties as $name => $value) { $service->setSubProperty($name, $value); } if ($configElement !== null) { $config = new TApplicationConfiguration(); if ($this->getConfigurationType() == self::CONFIG_TYPE_PHP) { $config->loadFromPhp($configElement, $this->getBasePath()); } else { $config->loadFromXml($configElement, $this->getBasePath()); } $this->applyConfiguration($config, true); } $service->init($configElement); } else { throw new THttpException(500, 'application_service_unknown', $serviceID); } }
/** * @return TActiveRecordManager */ public function getManager() { if ($this->_manager === null) { $this->_manager = Prado::createComponent($this->getManagerClass()); } return TActiveRecordManager::getInstance($this->_manager); }
/** * Create type handler from {@link Type setType()} or {@link TypeHandler setTypeHandler}. * @param TParameterProperty parameter property * @param TSqlMapTypeHandlerRegistry type handler registry * @return TSqlMapTypeHandler type handler. */ protected function createTypeHandler($property, $registry) { $type = $property->getTypeHandler() ? $property->getTypeHandler() : $property->getType(); $handler = $registry->getTypeHandler($type); if ($handler === null && $property->getTypeHandler()) { $handler = Prado::createComponent($type); } return $handler; }
/** * Instantiates the template. * Content in the template will be instantiated as components and text strings * and passed to the specified parent control. * @param TControl the control who owns the template * @param TControl the control who will become the root parent of the controls on the template. If null, it uses the template control. */ public function instantiateIn($tplControl, $parentControl = null) { $this->_tplControl = $tplControl; if ($parentControl === null) { $parentControl = $tplControl; } if (($page = $tplControl->getPage()) === null) { $page = $this->getService()->getRequestedPage(); } $controls = array(); $directChildren = array(); foreach ($this->_tpl as $key => $object) { if ($object[0] === -1) { $parent = $parentControl; } else { if (isset($controls[$object[0]])) { $parent = $controls[$object[0]]; } else { continue; } } if (isset($object[2])) { $component = Prado::createComponent($object[1]); $properties =& $object[2]; if ($component instanceof TControl) { if ($component instanceof TOutputCache) { $component->setCacheKeyPrefix($this->_hashCode . $key); } $component->setTemplateControl($tplControl); if (isset($properties['id'])) { if (is_array($properties['id'])) { $properties['id'] = $component->evaluateExpression($properties['id'][1]); } $tplControl->registerObject($properties['id'], $component); } if (isset($properties['skinid'])) { if (is_array($properties['skinid'])) { $component->setSkinID($component->evaluateExpression($properties['skinid'][1])); } else { $component->setSkinID($properties['skinid']); } unset($properties['skinid']); } $component->trackViewState(false); $component->applyStyleSheetSkin($page); foreach ($properties as $name => $value) { $this->configureControl($component, $name, $value); } $component->trackViewState(true); if ($parent === $parentControl) { $directChildren[] = $component; } else { $component->createdOnTemplate($parent); } if ($component->getAllowChildControls()) { $controls[$key] = $component; } } else { if ($component instanceof TComponent) { $controls[$key] = $component; if (isset($properties['id'])) { if (is_array($properties['id'])) { $properties['id'] = $component->evaluateExpression($properties['id'][1]); } $tplControl->registerObject($properties['id'], $component); if (!$component->hasProperty('id')) { unset($properties['id']); } } foreach ($properties as $name => $value) { $this->configureComponent($component, $name, $value); } if ($parent === $parentControl) { $directChildren[] = $component; } else { $component->createdOnTemplate($parent); } } } } else { if ($object[1] instanceof TCompositeLiteral) { // need to clone a new object because the one in template is reused $o = clone $object[1]; $o->setContainer($tplControl); if ($parent === $parentControl) { $directChildren[] = $o; } else { $parent->addParsedObject($o); } } else { if ($parent === $parentControl) { $directChildren[] = $object[1]; } else { $parent->addParsedObject($object[1]); } } } } // delay setting parent till now because the parent may cause // the child to do lifecycle catchup which may cause problem // if the child needs its own child controls. foreach ($directChildren as $control) { if ($control instanceof TComponent) { $control->createdOnTemplate($parentControl); } else { $parentControl->addParsedObject($control); } } }
/** * @param string name of the theme to be retrieved * @return TTheme the theme retrieved */ public function getTheme($name) { $themePath = $this->getBasePath() . DIRECTORY_SEPARATOR . $name; $themeUrl = rtrim($this->getBaseUrl(), '/') . '/' . $name; return Prado::createComponent($this->getThemeClass(), $themePath, $themeUrl); }