/**
  * 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);
             }
         }
     }
 }
示例#2
0
 protected function initializeHeaderCell($cell, $columnIndex)
 {
     $text = $this->getHeaderText();
     if (($classPath = $this->getHeaderRenderer()) !== '') {
         $control = Prado::createComponent($classPath);
         if ($control instanceof \Prado\IDataRenderer) {
             if ($control instanceof IItemDataRenderer) {
                 $item = $cell->getParent();
                 $control->setItemIndex($item->getItemIndex());
                 $control->setItemType($item->getItemType());
             }
             $control->setData($text);
         }
         $cell->getControls()->add($control);
     } else {
         if ($this->getAllowSorting()) {
             $sortExpression = $this->getSortExpression();
             if (($url = $this->getHeaderImageUrl()) !== '') {
                 $button = new TActiveImageButton();
                 $button->setImageUrl($url);
                 $button->setCommandName(TDataGrid::CMD_SORT);
                 $button->setCommandParameter($sortExpression);
                 if ($text !== '') {
                     $button->setAlternateText($text);
                     $button->setToolTip($text);
                 }
                 $button->setCausesValidation(false);
                 $cell->getControls()->add($button);
             } else {
                 if ($text !== '') {
                     $button = new TActiveLinkButton();
                     $button->setText($text);
                     $button->setCommandName(TDataGrid::CMD_SORT);
                     $button->setCommandParameter($sortExpression);
                     $button->setCausesValidation(false);
                     $cell->getControls()->add($button);
                 } else {
                     $cell->setText(' ');
                 }
             }
         } else {
             if (($url = $this->getHeaderImageUrl()) !== '') {
                 $image = new TActiveImage();
                 $image->setImageUrl($url);
                 if ($text !== '') {
                     $image->setAlternateText($text);
                     $image->setToolTip($text);
                 }
                 $cell->getControls()->add($image);
             } else {
                 if ($text !== '') {
                     $cell->setText($text);
                 } else {
                     $cell->setText(' ');
                 }
             }
         }
     }
 }
 /**
  * Create an instance of an object give by the attribute named 'class' in the
  * node and set the properties on the object given by attribute names and values.
  * @param SimpleXmlNode property node
  * @return Object new instance of class with class name given by 'class' attribute value.
  */
 protected function createObjectFromNode($node)
 {
     if (isset($node['class'])) {
         $obj = Prado::createComponent((string) $node['class']);
         $this->setObjectPropFromNode($obj, $node, array('class'));
         return $obj;
     }
     throw new TSqlMapConfigurationException('sqlmap_node_class_undef', $node, $this->getConfigFile());
 }
示例#4
0
 /**
  * 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));
     }
 }
示例#5
0
 /**
  * Sets the location of image file of the THyperLink.
  * @param string the image file location
  */
 public function setImageUrl($value)
 {
     if (parent::getImageUrl() === $value) {
         return;
     }
     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());
     }
 }
示例#6
0
 /**
  * Performs XSL transformation and render the output.
  * @param THtmlWriter The writer used for the rendering purpose
  */
 public function render($writer)
 {
     if (($document = $this->getSourceXmlDocument()) === null) {
         $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter());
         parent::render($htmlWriter);
         $document = new DOMDocument();
         $document->loadXML($htmlWriter->flush());
     }
     $stylesheet = $this->getTransformXmlDocument();
     // Perform XSL transformation
     $xslt = new XSLTProcessor();
     $xslt->importStyleSheet($stylesheet);
     // Check for parameters
     $parameters = $this->getParameters();
     foreach ($parameters as $name => $value) {
         $xslt->setParameter('', $name, $value);
     }
     $output = $xslt->transformToXML($document);
     // Write output
     $writer->write($output);
 }
示例#7
0
 /**
  * @return TActiveRecordManager
  */
 public function getManager()
 {
     if ($this->_manager === null) {
         $this->_manager = Prado::createComponent($this->getManagerClass());
     }
     return TActiveRecordManager::getInstance($this->_manager);
 }
示例#8
0
 /**
  * Instantiate the external edit renderer.
  * @param TActiveRecord record to be edited
  * @param string external edit renderer class name.
  * @throws TConfigurationException raised when renderer is not an
  * instance of IScaffoldEditRenderer.
  */
 protected function createEditRenderer($record, $classPath)
 {
     $this->_editRenderer = Prado::createComponent($classPath);
     if ($this->_editRenderer instanceof IScaffoldEditRenderer) {
         $index = $this->getControls()->remove($this->getInputRepeater());
         $this->getControls()->insertAt($index, $this->_editRenderer);
         $this->_editRenderer->setData($record);
     } else {
         throw new TConfigurationException('scaffold_invalid_edit_renderer', $this->getID(), get_class($record));
     }
 }
示例#9
0
 /**
  * Returns a user instance given the user name.
  * @param string user name, null if it is a guest.
  * @return TUser the user instance, null if the specified username is not in the user database.
  */
 public function getUser($username = null)
 {
     if ($username === null) {
         $user = Prado::createComponent($this->_userClass, $this);
         $user->setIsGuest(true);
         return $user;
     } else {
         return $this->_userFactory->createUser($username);
     }
 }
示例#10
0
 /**
  * Creates empty repeater content.
  */
 protected function createEmptyContent()
 {
     if (($classPath = $this->getEmptyRenderer()) !== '') {
         $this->getControls()->add(Prado::createComponent($classPath));
     } else {
         if ($this->_emptyTemplate !== null) {
             $this->_emptyTemplate->instantiateIn($this);
         }
     }
 }
示例#11
0
 /**
  * @return string parameter contents.
  */
 public function getParameter()
 {
     $value = $this->getValue();
     if (strlen($value) > 0) {
         return $value;
     }
     $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), new TTextWriter());
     $this->renderControl($htmlWriter);
     return $this->getTrim() ? trim($htmlWriter->flush()) : $htmlWriter->flush();
 }
示例#12
0
 /**
  * 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 = array();
         $feed = null;
         if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) {
             if (isset($feedConfig['class'])) {
                 $feed = Prado::createComponent($feedConfig['class']);
                 if ($service instanceof IFeedContentProvider) {
                     $properties = isset($feedConfig['properties']) ? $feedConfig['properties'] : array();
                 } else {
                     throw new TConfigurationException('jsonservice_response_type_invalid', $id);
                 }
             } else {
                 throw new TConfigurationException('jsonservice_class_required', $id);
             }
         } else {
             $properties = $feedConfig->getAttributes();
             if (($class = $properties->remove('class')) !== null) {
                 $feed = Prado::createComponent($class);
                 if (!$feed instanceof IFeedContentProvider) {
                     throw new TConfigurationException('feedservice_feedtype_invalid', $id);
                 }
             } else {
                 throw new TConfigurationException('feedservice_class_required', $id);
             }
         }
         // 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 THttpException(404, 'feedservice_feed_unknown', $id);
     }
 }
示例#13
0
 /**
  * Loads parameters into application.
  * @param mixed XML of PHP representation of the parameters
  * @throws TConfigurationException if the parameter file format is invalid
  */
 protected function loadParameters($config)
 {
     $parameters = array();
     if (is_array($config)) {
         foreach ($config as $id => $parameter) {
             if (is_array($parameter) && isset($parameter['class'])) {
                 $properties = isset($parameter['properties']) ? $parameter['properties'] : array();
                 $parameters[$id] = array($parameter['class'], $properties);
             } else {
                 $parameters[$id] = $parameter;
             }
         }
     } else {
         if ($config instanceof TXmlElement) {
             foreach ($config->getElementsByTagName('parameter') as $node) {
                 $properties = $node->getAttributes();
                 if (($id = $properties->remove('id')) === null) {
                     throw new TConfigurationException('parametermodule_parameterid_required');
                 }
                 if (($type = $properties->remove('class')) === null) {
                     if (($value = $properties->remove('value')) === null) {
                         $parameters[$id] = $node;
                     } else {
                         $parameters[$id] = $value;
                     }
                 } else {
                     $parameters[$id] = array($type, $properties->toArray());
                 }
             }
         }
     }
     $appParams = $this->getApplication()->getParameters();
     foreach ($parameters as $id => $parameter) {
         if (is_array($parameter)) {
             $component = Prado::createComponent($parameter[0]);
             foreach ($parameter[1] as $name => $value) {
                 $component->setSubProperty($name, $value);
             }
             $appParams->add($id, $component);
         } else {
             $appParams->add($id, $parameter);
         }
     }
 }
示例#14
0
 /**
  * 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 \Prado\Web\UI\WebControls\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);
         }
     }
 }
示例#15
0
 /**
  * Initializes the specified cell to its initial values.
  * This method overrides the parent implementation.
  * It creates a textbox for item in edit mode and the column is not read-only.
  * Otherwise it displays a static text.
  * The caption of the button and the static text are retrieved
  * from the datasource.
  * @param TTableCell the cell to be initialized.
  * @param integer the index to the Columns property that the cell resides in.
  * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
  */
 public function initializeCell($cell, $columnIndex, $itemType)
 {
     $item = $cell->getParent();
     switch ($itemType) {
         case TListItemType::Item:
         case TListItemType::AlternatingItem:
         case TListItemType::SelectedItem:
             if (($classPath = $this->getItemRenderer()) !== '') {
                 $control = Prado::createComponent($classPath);
                 if ($control instanceof IItemDataRenderer) {
                     $control->setItemIndex($item->getItemIndex());
                     $control->setItemType($item->getItemType());
                 }
                 $cell->getControls()->add($control);
             } else {
                 $control = $cell;
             }
             $control->attachEventHandler('OnDataBinding', array($this, 'dataBindColumn'));
             break;
         case TListItemType::EditItem:
             if (!$this->getReadOnly()) {
                 if (($classPath = $this->getEditItemRenderer()) !== '') {
                     $control = Prado::createComponent($classPath);
                     if ($control instanceof IItemDataRenderer) {
                         $control->setItemIndex($item->getItemIndex());
                         $control->setItemType($item->getItemType());
                     }
                     $cell->getControls()->add($control);
                     $cell->registerObject('EditControl', $control);
                 } else {
                     $control = new TTextBox();
                     $cell->getControls()->add($control);
                     $cell->registerObject('TextBox', $control);
                 }
             } else {
                 if (($classPath = $this->getItemRenderer()) !== '') {
                     $control = Prado::createComponent($classPath);
                     if ($control instanceof IItemDataRenderer) {
                         $control->setItemIndex($item->getItemIndex());
                         $control->setItemType($item->getItemType());
                     }
                     $cell->getControls()->add($control);
                 } else {
                     $control = $cell;
                 }
             }
             $control->attachEventHandler('OnDataBinding', array($this, 'dataBindColumn'));
             break;
         default:
             parent::initializeCell($cell, $columnIndex, $itemType);
             break;
     }
 }
示例#16
0
 /**
  * @return TActiveRecordGateway default record gateway.
  */
 protected function createRecordGateway()
 {
     return Prado::createComponent($this->getGatewayClass(), $this);
 }
示例#17
0
 private function buildUrlMapping($class, $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);
     }
     if ($url instanceof TXmlElement) {
         $text = $url->getValue();
         if ($text) {
             $text = preg_replace('/(\\s+)/S', '', $text);
             if (($regExp = $pattern->getRegularExpression()) !== '') {
                 trigger_error(sPrintF('%s.RegularExpression property value "%s" for ServiceID="%s" and ServiceParameter="%s" was replaced by node value "%s"', get_class($pattern), $regExp, $pattern->getServiceID(), $pattern->getServiceParameter(), $text), E_USER_NOTICE);
             }
             $pattern->setRegularExpression($text);
         }
     }
     $this->_patterns[] = $pattern;
     $pattern->init($url);
     $key = $pattern->getServiceID() . ':' . $pattern->getServiceParameter();
     $this->_constructRules[$key][] = $pattern;
 }
示例#18
0
 /**
  * Gets the current Active Record instance. Creates new instance if the
  * primary key value is null otherwise the record is fetched from the db.
  * @param array primary key value
  * @return TActiveRecord record instance
  */
 protected function getRecordObject($pk = null)
 {
     if ($this->_record === null) {
         if ($pk !== null) {
             $this->_record = $this->getRecordFinder()->findByPk($pk);
             if ($this->_record === null) {
                 throw new TConfigurationException('scaffold_invalid_record_pk', $this->getRecordClass(), $pk);
             }
         } else {
             $class = $this->getRecordClass();
             if ($class !== null) {
                 $this->_record = Prado::createComponent($class);
             } else {
                 throw new TConfigurationException('scaffold_invalid_record_class', $this->getRecordClass(), $this->getID());
             }
         }
     }
     return $this->_record;
 }
示例#19
0
 /**
  * Runs the service.
  * This method is invoked by application automatically.
  */
 public function run()
 {
     $id = $this->getRequest()->getServiceParameter();
     if (isset($this->_services[$id])) {
         $serviceConfig = $this->_services[$id];
         if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) {
             if (isset($serviceConfig['class'])) {
                 $service = Prado::createComponent($serviceConfig['class']);
                 if ($service instanceof TJsonResponse) {
                     $properties = isset($serviceConfig['properties']) ? $serviceConfig['properties'] : array();
                     $this->createJsonResponse($service, $properties, $serviceConfig);
                 } else {
                     throw new TConfigurationException('jsonservice_response_type_invalid', $id);
                 }
             } else {
                 throw new TConfigurationException('jsonservice_class_required', $id);
             }
         } else {
             $properties = $serviceConfig->getAttributes();
             if (($class = $properties->remove('class')) !== null) {
                 $service = Prado::createComponent($class);
                 if ($service instanceof TJsonResponse) {
                     $this->createJsonResponse($service, $properties, $serviceConfig);
                 } else {
                     throw new TConfigurationException('jsonservice_response_type_invalid', $id);
                 }
             } else {
                 throw new TConfigurationException('jsonservice_class_required', $id);
             }
         }
     } else {
         throw new THttpException(404, 'jsonservice_provider_unknown', $id);
     }
 }
示例#20
0
文件: TPage.php 项目: pradosoft/prado
 /**
  * @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;
 }
示例#21
0
 /**
  * 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));
 }
示例#22
0
 /**
  * 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;
 }
示例#23
0
 /**
  * Performs the OnInit step for the control and all its child controls.
  * This method overrides the parent implementation
  * by ensuring child controls are created first,
  * and if master class is set, master will be applied.
  * Only framework developers should use this method.
  * @param TControl the naming container control
  */
 protected function initRecursive($namingContainer = null)
 {
     $this->ensureChildControls();
     if ($this->_masterClass !== '') {
         $master = Prado::createComponent($this->_masterClass);
         if (!$master instanceof TTemplateControl) {
             throw new TInvalidDataValueException('templatecontrol_mastercontrol_invalid');
         }
         $this->_master = $master;
         $this->getControls()->clear();
         $this->getControls()->add($master);
         $master->ensureChildControls();
         foreach ($this->_contents as $id => $content) {
             $master->injectContent($id, $content);
         }
     } else {
         if (!empty($this->_contents)) {
             throw new TConfigurationException('templatecontrol_mastercontrol_required', get_class($this));
         }
     }
     parent::initRecursive($namingContainer);
 }
示例#24
0
 /**
  * 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);
 }
示例#25
0
 /**
  * Renders the output cache control.
  * This method overrides the parent implementation by capturing the output
  * from its child controls and saving it into cache, if output cache is needed.
  * @param THtmlWriter
  */
 public function render($writer)
 {
     if ($this->_dataCached) {
         $writer->write($this->_contents);
     } else {
         if ($this->_cacheAvailable) {
             $textwriter = new TTextWriter();
             $multiwriter = new TOutputCacheTextWriterMulti(array($writer->getWriter(), $textwriter));
             $htmlWriter = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), $multiwriter);
             $stack = $this->getPage()->getCachingStack();
             $stack->push($this);
             parent::render($htmlWriter);
             $stack->pop();
             $content = $textwriter->flush();
             $data = array($content, $this->_state, $this->_actions, time());
             $this->_cache->set($this->getCacheKey(), $data, $this->getDuration(), $this->getCacheDependency());
         } else {
             parent::render($writer);
         }
     }
 }
 /**
  * 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);
     }
 }
示例#27
0
 /**
  * @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);
 }
示例#28
0
 /**
  * Loads configuration from an XML element or PHP array
  * @param mixed configuration node
  * @throws TConfigurationException if log route class or type is not specified
  */
 private function loadConfig($config)
 {
     if (is_array($config)) {
         if (isset($config['routes']) && is_array($config['routes'])) {
             foreach ($config['routes'] as $route) {
                 $properties = isset($route['properties']) ? $route['properties'] : array();
                 if (!isset($route['class'])) {
                     throw new TConfigurationException('logrouter_routeclass_required');
                 }
                 $route = Prado::createComponent($route['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($route);
             }
         }
     } else {
         foreach ($config->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);
         }
     }
 }
示例#29
0
 /**
  * Starts a transaction.
  * @return TDbTransaction the transaction initiated
  * @throws TDbException if the connection is not active
  */
 public function beginTransaction()
 {
     if ($this->getActive()) {
         $this->_pdo->beginTransaction();
         return $this->_transaction = Prado::createComponent($this->getTransactionClass(), $this);
     } else {
         throw new TDbException('dbconnection_connection_inactive');
     }
 }
示例#30
0
 /**
  * Creates a page instance based on requested page path.
  * @param string requested page path
  * @return TPage the requested page instance
  * @throws THttpException if requested page path is invalid
  * @throws TConfigurationException if the page class cannot be found
  */
 protected function createPage($pagePath)
 {
     $path = $this->getBasePath() . DIRECTORY_SEPARATOR . strtr($pagePath, '.', DIRECTORY_SEPARATOR);
     $hasTemplateFile = is_file($path . self::PAGE_FILE_EXT);
     $hasClassFile = is_file($path . Prado::CLASS_FILE_EXT);
     if (!$hasTemplateFile && !$hasClassFile) {
         throw new THttpException(404, 'pageservice_page_unknown', $pagePath);
     }
     if ($hasClassFile) {
         $className = basename($path);
         $namespacedClassName = static::PAGE_NAMESPACE_PREFIX . str_replace('.', '\\', $pagePath);
         if (!class_exists($className, false) && !class_exists($namespacedClassName, false)) {
             include_once $path . Prado::CLASS_FILE_EXT;
         }
         if (!class_exists($className, false)) {
             $className = $namespacedClassName;
         }
     } else {
         $className = $this->getBasePageClass();
         Prado::using($className);
         if (($pos = strrpos($className, '.')) !== false) {
             $className = substr($className, $pos + 1);
         }
     }
     if (!class_exists($className, false) || $className !== 'TPage' && !is_subclass_of($className, 'TPage')) {
         throw new THttpException(404, 'pageservice_page_unknown', $pagePath);
     }
     $page = Prado::createComponent($className);
     $page->setPagePath($pagePath);
     if ($hasTemplateFile) {
         $page->setTemplate($this->getTemplateManager()->getTemplateByFileName($path . self::PAGE_FILE_EXT));
     }
     return $page;
 }