Page MenuHomeIn-Portal Phabricator

D396.id1057.diff
No OneTemporary

File Metadata

Created
Wed, Feb 26, 8:58 AM

D396.id1057.diff

Index: branches/5.2.x/core/kernel/db/dbitem.php
===================================================================
--- branches/5.2.x/core/kernel/db/dbitem.php
+++ branches/5.2.x/core/kernel/db/dbitem.php
@@ -127,8 +127,7 @@
$formatter = $this->GetFieldOption($field_name, 'formatter');
if ( $formatter ) {
- /** @var kFormatter $formatter */
- $formatter = $this->Application->recallObject($formatter);
+ $formatter = $this->getFormatter($formatter);
if ( $formatter instanceof kMultiLanguage && strpos((string)$format, 'no_default') === false ) {
$format = rtrim('no_default;' . $format, ';');
@@ -187,12 +186,14 @@
$parsed = NULL;
}
- // kFormatter is always used, to make sure, that numeric value is converted to normal representation
- // according to regional format, even when formatter is not set (try seting format to 1.234,56 to understand why)
- /** @var kFormatter $formatter */
- $formatter = $this->Application->recallObject(isset($options['formatter']) ? $options['formatter'] : 'kFormatter');
-
- $parsed = $formatter->Parse($value, $name, $this);
+ /*
+ * kFormatter is always used, to make sure, that numeric value is converted to normal representation
+ * according to regional format, even when formatter is not set (try setting format to 1.234,56 to
+ * understand why).
+ */
+ $parsed = $this
+ ->getFormatter(isset($options['formatter']) ? $options['formatter'] : 'kFormatter')
+ ->Parse($value, $name, $this);
$this->SetDBField($name,$parsed);
}
@@ -543,10 +544,9 @@
foreach ($this->Fields as $field => $options) {
if ( isset($options['formatter']) ) {
- /** @var kFormatter $formatter */
- $formatter = $this->Application->recallObject($options['formatter']);
-
- $formatter->UpdateMasterFields($field, $this->GetDBField($field), $options, $this);
+ $this
+ ->getFormatter($options['formatter'])
+ ->UpdateMasterFields($field, $this->GetDBField($field), $options, $this);
}
}
}
@@ -1565,7 +1565,7 @@
$cdata->SetDBField('ResourceId', $resource_id);
/** @var kMultiLanguage $ml_formatter */
- $ml_formatter = $this->Application->recallObject('kMultiLanguage');
+ $ml_formatter = $this->getFormatter('kMultiLanguage');
/** @var kMultiLanguageHelper $ml_helper */
$ml_helper = $this->Application->recallObject('kMultiLanguageHelper');
Index: branches/5.2.x/core/kernel/kbase.php
===================================================================
--- branches/5.2.x/core/kernel/kbase.php
+++ branches/5.2.x/core/kernel/kbase.php
@@ -266,6 +266,13 @@
protected $parentEvent = null;
/**
+ * Formatters cache.
+ *
+ * @var kFormatter[]
+ */
+ static private $_formattersCache = array();
+
+ /**
* Sets new parent event to the object
*
* @param kEvent $event
@@ -883,10 +890,7 @@
if ( $formatter_class ) {
$value = ($formatter_class == 'kMultiLanguage') && !preg_match('/^l[0-9]+_/', $name) ? '' : $this->GetDBField($name);
- /** @var kFormatter $formatter */
- $formatter = $this->Application->recallObject($formatter_class);
-
- return $formatter->Format($value, $name, $this, $format);
+ return $this->getFormatter($formatter_class)->Format($value, $name, $this, $format);
}
return $this->GetDBField($name);
@@ -933,10 +937,9 @@
foreach ($fields as $field) {
if ( isset($this->Fields[$field]['formatter']) ) {
- /** @var kFormatter $formatter */
- $formatter = $this->Application->recallObject($this->Fields[$field]['formatter']);
-
- $formatter->UpdateSubFields($field, $this->GetDBField($field), $this->Fields[$field], $this);
+ $this
+ ->getFormatter($this->Fields[$field]['formatter'])
+ ->UpdateSubFields($field, $this->GetDBField($field), $this->Fields[$field], $this);
}
}
}
@@ -955,11 +958,26 @@
continue;
}
- /** @var kFormatter $formatter */
- $formatter = $this->Application->recallObject( $this->Fields[$field_name]['formatter'] );
+ $this
+ ->getFormatter($this->Fields[$field_name]['formatter'])
+ ->PrepareOptions($field_name, $this->Fields[$field_name], $this);
+ }
+ }
- $formatter->PrepareOptions($field_name, $this->Fields[$field_name], $this);
+ /**
+ * Returns formatter.
+ *
+ * @param string $name Name.
+ *
+ * @return kFormatter
+ */
+ protected function getFormatter($name)
+ {
+ if ( !isset(self::$_formattersCache[$name]) ) {
+ self::$_formattersCache[$name] = $this->Application->recallObject($name);
}
+
+ return self::$_formattersCache[$name];
}
/**

Event Timeline