From 11666237dbdc0eb9e01d5d739994bdd88a551168 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Sat, 7 Nov 2015 15:06:50 +0100 Subject: Prepare for release: update (c) year to 2015, version to 3.3 --- framework/pradolite.php | 153 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 121 insertions(+), 32 deletions(-) (limited to 'framework/pradolite.php') diff --git a/framework/pradolite.php b/framework/pradolite.php index fcf73364..af6026ae 100644 --- a/framework/pradolite.php +++ b/framework/pradolite.php @@ -1,7 +1,7 @@ $version, '%%Time%%' => @strftime('%Y-%m-%d %H:%M',time()) ); - $CGI=substr(php_sapi_name(), 0, 3) == 'cgi'; if($isDebug) - { - if ($CGI) - header("Status: $statusCode ".$exception->getMessage(), true, TPropertyValue::ensureInteger($statusCode)); - else - header("HTTP/1.0 $statusCode ".$exception->getMessage(), true, TPropertyValue::ensureInteger($statusCode)); - } else { - if ($CGI) - header("Status: $statusCode", true, TPropertyValue::ensureInteger($statusCode)); - else - header("HTTP/1.0 $statusCode", true, TPropertyValue::ensureInteger($statusCode)); - } + $this->getApplication()->getResponse()->setStatusCode($statusCode, $isDebug ? $exception->getMessage() : null); echo strtr($content,$tokens); } protected function handleRecursiveError($exception) @@ -2385,7 +2374,7 @@ class TXmlDocument extends TXmlElement { return $this->saveToString(); } - private function buildElement($node) + protected function buildElement($node) { $element=new TXmlElement($node->tagName); $element->setValue($node->nodeValue); @@ -2894,14 +2883,23 @@ class TJavaScript } public static function jsonEncode($value, $options = 0) { - if (is_string($value) && - ($g=Prado::getApplication()->getGlobalization(false))!==null && - strtoupper($enc=$g->getCharset())!='UTF-8') - $value=iconv($enc, 'UTF-8', $value); + if (($g=Prado::getApplication()->getGlobalization(false))!==null && + strtoupper($enc=$g->getCharset())!='UTF-8') { + self::convertToUtf8($value, $enc); + } $s = @json_encode($value,$options); self::checkJsonError(); return $s; } + private static function convertToUtf8(&$value, $sourceEncoding) { + if(is_string($value)) + $value=iconv($sourceEncoding, 'UTF-8', $value); + else if (is_array($value)) + { + foreach($value as &$element) + self::convertToUtf8($element, $sourceEncoding); + } + } public static function jsonDecode($value, $assoc = false, $depth = 512) { $s= @json_decode($value, $assoc, $depth); @@ -3951,10 +3949,12 @@ class THttpResponse extends TModule implements ITextWriter } protected function sendHttpHeader() { - if (($version=$this->getRequest()->getHttpProtocolVersion())==='') - header (' ', true, $this->_status); - else - header($version.' '.$this->_status.' '.$this->_reason, true, $this->_status); + $protocol=$this->getRequest()->getHttpProtocolVersion(); + if($this->getRequest()->getHttpProtocolVersion() === null) + $protocol='HTTP/1.1'; + $phpSapiName = substr(php_sapi_name(), 0, 3); + $cgi = $phpSapiName == 'cgi' || $phpSapiName == 'fpm'; + header(($cgi ? 'Status:' : $protocol).' '.$this->_status.' '.$this->_reason, true, TPropertyValue::ensureInteger($this->_status)); $this->_httpHeaderSent = true; } protected function ensureContentTypeHeaderSent() @@ -4103,7 +4103,7 @@ class THttpSession extends TApplicationComponent implements IteratorAggregate,Ar if($this->_customStorage) session_set_save_handler(array($this,'_open'),array($this,'_close'),array($this,'_read'),array($this,'_write'),array($this,'_destroy'),array($this,'_gc')); if($this->_cookie!==null) - session_set_cookie_params($this->_cookie->getExpire(),$this->_cookie->getPath(),$this->_cookie->getDomain(),$this->_cookie->getSecure()); + session_set_cookie_params($this->_cookie->getExpire(),$this->_cookie->getPath(),$this->_cookie->getDomain(),$this->_cookie->getSecure(),$this->_cookie->getHttpOnly()); if(ini_get('session.auto_start')!=='1') session_start(); $this->_started=true; @@ -4202,8 +4202,11 @@ class THttpSession extends TApplicationComponent implements IteratorAggregate,Ar else { $value=TPropertyValue::ensureEnum($value,'THttpSessionCookieMode'); - if($value===THttpSessionCookieMode::None) + if($value===THttpSessionCookieMode::None) + { ini_set('session.use_cookies','0'); + ini_set('session.use_only_cookies','0'); + } else if($value===THttpSessionCookieMode::Allow) { ini_set('session.use_cookies','1'); @@ -4536,9 +4539,6 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable private $_stage=0; private $_flags=0; private $_rf=array(); - public function __construct() - { - } public function __get($name) { if(isset($this->_rf[self::RF_NAMED_OBJECTS][$name])) @@ -5536,6 +5536,7 @@ interface IButtonControl } interface ISurroundable { + public function getSurroundingTag(); public function getSurroundingTagID(); } class TBroadcastEventParameter extends TEventParameter @@ -6804,6 +6805,77 @@ class TTemplateControl extends TCompositeControl throw new TConfigurationException('templatecontrol_mastercontrol_required',get_class($this)); parent::initRecursive($namingContainer); } + public function tryToUpdateView($arObj, $throwExceptions = false) + { + $objAttrs = get_class_vars(get_class($arObj)); + foreach (array_keys($objAttrs) as $key) + { + try + { + if ($key != "RELATIONS") + { + $control = $this->{$key}; + if ($control instanceof TTextBox) + $control->Text = $arObj->{$key}; + elseif ($control instanceof TCheckBox) + $control->Checked = (boolean) $arObj->{$key}; + elseif ($control instanceof TDatePicker) + $control->Date = $arObj->{$key}; + } + else + { + foreach ($objAttrs["RELATIONS"] as $relKey => $relValues) + { + $relControl = $this->{$relKey}; + switch ($relValues[0]) + { + case TActiveRecord::BELONGS_TO: + case TActiveRecord::HAS_ONE: + $relControl->Text = $arObj->{$relKey}; + break; + case TActiveRecord::HAS_MANY: + if ($relControl instanceof TListControl) + { + $relControl->DataSource = $arObj->{$relKey}; + $relControl->dataBind(); + } + break; + } + } + break; + } + } + catch (Exception $ex) + { + if ($throwExceptions) + throw $ex; + } + } + } + public function tryToUpdateAR($arObj, $throwExceptions = false) + { + $objAttrs = get_class_vars(get_class($arObj)); + foreach (array_keys($objAttrs) as $key) + { + try + { + if ($key == "RELATIONS") + break; + $control = $this->{$key}; + if ($control instanceof TTextBox) + $arObj->{$key} = $control->Text; + elseif ($control instanceof TCheckBox) + $arObj->{$key} = $control->Checked; + elseif ($control instanceof TDatePicker) + $arObj->{$key} = $control->Date; + } + catch (Exception $ex) + { + if ($throwExceptions) + throw $ex; + } + } + } } class TForm extends TControl { @@ -7078,7 +7150,7 @@ class TClientScriptManager extends TApplicationComponent $this->registerPradoScriptInternal('jquery'); if($target instanceof TControl) $target=$target->getClientID(); - $this->_endScripts['prado:focus'] = 'new Prado.Element.scrollTo(\''.$target.'\'); jQuery(\'#'.$target.'\').focus();'; + $this->_endScripts['prado:focus'] = 'jQuery(\'#'.$target.'\').focus();'; $params=func_get_args(); $this->_page->registerCachingAction('Page.ClientScript','registerFocusControl',$params); } @@ -8944,7 +9016,7 @@ class TTemplate extends TApplicationComponent implements ITemplate } else { - if (! ($class->hasMethod('set'.$name) || $class->hasMethod('setjs'.$name)) ) + if (! ($class->hasMethod('set'.$name) || $class->hasMethod('setjs'.$name) || $this->isClassBehaviorMethod($class,'set'.$name)) ) { if ($class->hasMethod('get'.$name) || $class->hasMethod('getjs'.$name)) throw new TConfigurationException('template_property_readonly',$type,$name); @@ -8977,7 +9049,7 @@ class TTemplate extends TApplicationComponent implements ITemplate throw new TConfigurationException('template_event_forbidden',$type,$name); else { - if(strcasecmp($name,'id')!==0 && !$class->hasMethod('set'.$name)) + if(strcasecmp($name,'id')!==0 && !($class->hasMethod('set'.$name) || $this->isClassBehaviorMethod($class,'set'.$name))) { if($class->hasMethod('get'.$name)) throw new TConfigurationException('template_property_readonly',$type,$name); @@ -9050,6 +9122,23 @@ class TTemplate extends TApplicationComponent implements ITemplate } return $input; } + protected function isClassBehaviorMethod(ReflectionClass $class,$method) + { + $component=new ReflectionClass('TComponent'); + $behaviors=$component->getStaticProperties(); + if(!isset($behaviors['_um'])) + return false; + foreach($behaviors['_um'] as $name=>$list) + { + if(strtolower($class->getShortName())!==$name && !$class->isSubclassOf($name)) continue; + foreach($list as $param) + { + if(method_exists($param->getBehavior(),$method)) + return true; + } + } + return false; + } } class TThemeManager extends TModule { @@ -9589,7 +9678,7 @@ class TPageService extends TService } if(!class_exists($className,false) || ($className!=='TPage' && !is_subclass_of($className,'TPage'))) throw new THttpException(404,'pageservice_page_unknown',$pagePath); - $page=new $className; + $page=Prado::createComponent($className); $page->setPagePath($pagePath); if($hasTemplateFile) $page->setTemplate($this->getTemplateManager()->getTemplateByFileName($path.self::PAGE_FILE_EXT)); -- cgit v1.2.3