mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
MINOR Removed usage of deprecated Object::uninherited_static() in core, improves CMS loading speed in live mode by ~3.5%
This commit is contained in:
parent
0fd7ce6a1e
commit
c73b80049a
@ -208,7 +208,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
* @return array Map of fieldname to specification, similiar to {@link DataObject::$db}.
|
* @return array Map of fieldname to specification, similiar to {@link DataObject::$db}.
|
||||||
*/
|
*/
|
||||||
public static function custom_database_fields($class) {
|
public static function custom_database_fields($class) {
|
||||||
$fields = Object::uninherited_static($class, 'db');
|
$fields = Config::inst()->get($class, 'db', Config::UNINHERITED);
|
||||||
|
|
||||||
foreach(self::composite_fields($class, false) as $fieldName => $fieldClass) {
|
foreach(self::composite_fields($class, false) as $fieldName => $fieldClass) {
|
||||||
// Remove the original fieldname, its not an actual database column
|
// Remove the original fieldname, its not an actual database column
|
||||||
@ -222,7 +222,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add has_one relationships
|
// Add has_one relationships
|
||||||
$hasOne = Object::uninherited_static($class, 'has_one');
|
$hasOne = Config::inst()->get($class, 'has_one', Config::UNINHERITED);
|
||||||
if($hasOne) foreach(array_keys($hasOne) as $field) {
|
if($hasOne) foreach(array_keys($hasOne) as $field) {
|
||||||
$fields[$field . 'ID'] = 'ForeignKey';
|
$fields[$field . 'ID'] = 'ForeignKey';
|
||||||
}
|
}
|
||||||
@ -268,7 +268,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
private static function cache_composite_fields($class) {
|
private static function cache_composite_fields($class) {
|
||||||
$compositeFields = array();
|
$compositeFields = array();
|
||||||
|
|
||||||
$fields = Object::uninherited_static($class, 'db');
|
$fields = Config::inst()->get($class, 'db', Config::UNINHERITED);
|
||||||
if($fields) foreach($fields as $fieldName => $fieldClass) {
|
if($fields) foreach($fields as $fieldName => $fieldClass) {
|
||||||
// Strip off any parameters
|
// Strip off any parameters
|
||||||
$bPos = strpos('(', $fieldClass);
|
$bPos = strpos('(', $fieldClass);
|
||||||
@ -954,7 +954,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
$classes = array_reverse(ClassInfo::ancestry($this));
|
$classes = array_reverse(ClassInfo::ancestry($this));
|
||||||
|
|
||||||
foreach($classes as $class) {
|
foreach($classes as $class) {
|
||||||
$defaults = Object::uninherited_static($class, 'defaults');
|
$defaults = Config::inst()->get($class, 'defaults', Config::UNINHERITED);
|
||||||
|
|
||||||
if($defaults && !is_array($defaults)) {
|
if($defaults && !is_array($defaults)) {
|
||||||
user_error("Bad '$this->class' defaults given: " . var_export($defaults, true),
|
user_error("Bad '$this->class' defaults given: " . var_export($defaults, true),
|
||||||
@ -1417,13 +1417,13 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
if(in_array($class, array('Object', 'ViewableData', 'DataObject'))) continue;
|
if(in_array($class, array('Object', 'ViewableData', 'DataObject'))) continue;
|
||||||
|
|
||||||
if($component) {
|
if($component) {
|
||||||
$hasOne = Object::uninherited_static($class, 'has_one');
|
$hasOne = Config::inst()->get($class, 'has_one', Config::UNINHERITED);
|
||||||
|
|
||||||
if(isset($hasOne[$component])) {
|
if(isset($hasOne[$component])) {
|
||||||
return $hasOne[$component];
|
return $hasOne[$component];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$newItems = (array) Object::uninherited_static($class, 'has_one');
|
$newItems = (array)Config::inst()->get($class, 'has_one', Config::UNINHERITED);
|
||||||
// Validate the data
|
// Validate the data
|
||||||
foreach($newItems as $k => $v) {
|
foreach($newItems as $k => $v) {
|
||||||
if(!is_string($k) || is_numeric($k) || !is_string($v)) user_error("$class::\$has_one has a bad entry: "
|
if(!is_string($k) || is_numeric($k) || !is_string($v)) user_error("$class::\$has_one has a bad entry: "
|
||||||
@ -1484,13 +1484,13 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($fieldName) {
|
if($fieldName) {
|
||||||
$db = Object::uninherited_static($class, 'db');
|
$db = Config::inst()->get($class, 'db', Config::UNINHERITED);
|
||||||
|
|
||||||
if(isset($db[$fieldName])) {
|
if(isset($db[$fieldName])) {
|
||||||
return $db[$fieldName];
|
return $db[$fieldName];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$newItems = (array) Object::uninherited_static($class, 'db');
|
$newItems = (array)Config::inst()->get($class, 'db', Config::UNINHERITED);
|
||||||
// Validate the data
|
// Validate the data
|
||||||
foreach($newItems as $k => $v) {
|
foreach($newItems as $k => $v) {
|
||||||
if(!is_string($k) || is_numeric($k) || !is_string($v)) user_error("$class::\$db has a bad entry: "
|
if(!is_string($k) || is_numeric($k) || !is_string($v)) user_error("$class::\$db has a bad entry: "
|
||||||
@ -1635,7 +1635,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
if(in_array($class, array('ViewableData', 'Object', 'DataObject'))) continue;
|
if(in_array($class, array('ViewableData', 'Object', 'DataObject'))) continue;
|
||||||
|
|
||||||
if($component) {
|
if($component) {
|
||||||
$manyMany = Object::uninherited_static($class, 'many_many');
|
$manyMany = Config::inst()->get($class, 'many_many', Config::UNINHERITED);
|
||||||
// Try many_many
|
// Try many_many
|
||||||
$candidate = (isset($manyMany[$component])) ? $manyMany[$component] : null;
|
$candidate = (isset($manyMany[$component])) ? $manyMany[$component] : null;
|
||||||
if($candidate) {
|
if($candidate) {
|
||||||
@ -1645,13 +1645,13 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try belongs_many_many
|
// Try belongs_many_many
|
||||||
$belongsManyMany = Object::uninherited_static($class, 'belongs_many_many');
|
$belongsManyMany = Config::inst()->get($class, 'belongs_many_many', Config::UNINHERITED);
|
||||||
$candidate = (isset($belongsManyMany[$component])) ? $belongsManyMany[$component] : null;
|
$candidate = (isset($belongsManyMany[$component])) ? $belongsManyMany[$component] : null;
|
||||||
if($candidate) {
|
if($candidate) {
|
||||||
$childField = $candidate . "ID";
|
$childField = $candidate . "ID";
|
||||||
|
|
||||||
// We need to find the inverse component name
|
// We need to find the inverse component name
|
||||||
$otherManyMany = Object::uninherited_static($candidate, 'many_many');
|
$otherManyMany = Config::inst()->get($candidate, 'many_many', Config::UNINHERITED);
|
||||||
if(!$otherManyMany) {
|
if(!$otherManyMany) {
|
||||||
user_error("Inverse component of $candidate not found ({$this->class})", E_USER_ERROR);
|
user_error("Inverse component of $candidate not found ({$this->class})", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
@ -1670,7 +1670,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
user_error("Orphaned \$belongs_many_many value for $this->class.$component", E_USER_ERROR);
|
user_error("Orphaned \$belongs_many_many value for $this->class.$component", E_USER_ERROR);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$newItems = (array) Object::uninherited_static($class, 'many_many');
|
$newItems = (array)Config::inst()->get($class, 'many_many', Config::UNINHERITED);
|
||||||
// Validate the data
|
// Validate the data
|
||||||
foreach($newItems as $k => $v) {
|
foreach($newItems as $k => $v) {
|
||||||
if(!is_string($k) || is_numeric($k) || !is_string($v)) user_error("$class::\$many_many has a bad entry: "
|
if(!is_string($k) || is_numeric($k) || !is_string($v)) user_error("$class::\$many_many has a bad entry: "
|
||||||
@ -1678,7 +1678,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
}
|
}
|
||||||
$items = isset($items) ? array_merge($newItems, $items) : $newItems;
|
$items = isset($items) ? array_merge($newItems, $items) : $newItems;
|
||||||
|
|
||||||
$newItems = (array) Object::uninherited_static($class, 'belongs_many_many');
|
$newItems = (array)Config::inst()->get($class, 'belongs_many_many', Config::UNINHERITED);
|
||||||
// Validate the data
|
// Validate the data
|
||||||
foreach($newItems as $k => $v) {
|
foreach($newItems as $k => $v) {
|
||||||
if(!is_string($k) || is_numeric($k) || !is_string($v)) user_error("$class::\$belongs_many_many has a bad entry: "
|
if(!is_string($k) || is_numeric($k) || !is_string($v)) user_error("$class::\$belongs_many_many has a bad entry: "
|
||||||
@ -1700,8 +1700,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
* @return array or false
|
* @return array or false
|
||||||
*/
|
*/
|
||||||
function database_extensions($class){
|
function database_extensions($class){
|
||||||
|
$extensions = Config::inst()->get($class, 'database_extensions', Config::UNINHERITED);
|
||||||
$extensions = Object::uninherited_static($class, 'database_extensions');
|
|
||||||
|
|
||||||
if($extensions)
|
if($extensions)
|
||||||
return $extensions;
|
return $extensions;
|
||||||
@ -2126,7 +2125,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
|
|
||||||
// if no fieldmap is cached, get all fields
|
// if no fieldmap is cached, get all fields
|
||||||
if(!$fieldMap) {
|
if(!$fieldMap) {
|
||||||
$fieldMap = Object::uninherited_static($this->class, 'db');
|
$fieldMap = Config::inst()->get($this->class, 'db', Config::UNINHERITED);
|
||||||
|
|
||||||
// all $db fields on this specific class (no parents)
|
// all $db fields on this specific class (no parents)
|
||||||
foreach(self::composite_fields($this->class, false) as $fieldname => $fieldtype) {
|
foreach(self::composite_fields($this->class, false) as $fieldname => $fieldtype) {
|
||||||
@ -2138,7 +2137,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
|
|
||||||
// all has_one relations on this specific class,
|
// all has_one relations on this specific class,
|
||||||
// add foreign key
|
// add foreign key
|
||||||
$hasOne = Object::uninherited_static($this->class, 'has_one');
|
$hasOne = Config::inst()->get($this->class, 'has_one', Config::UNINHERITED);
|
||||||
if($hasOne) foreach($hasOne as $fieldName => $fieldSchema) {
|
if($hasOne) foreach($hasOne as $fieldName => $fieldSchema) {
|
||||||
$fieldMap[$fieldName . 'ID'] = "ForeignKey";
|
$fieldMap[$fieldName . 'ID'] = "ForeignKey";
|
||||||
}
|
}
|
||||||
@ -2171,7 +2170,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
if(get_parent_class($dataClass) == 'DataObject') {
|
if(get_parent_class($dataClass) == 'DataObject') {
|
||||||
DataObject::$cache_has_own_table[$dataClass] = true;
|
DataObject::$cache_has_own_table[$dataClass] = true;
|
||||||
} else {
|
} else {
|
||||||
DataObject::$cache_has_own_table[$dataClass] = Object::uninherited_static($dataClass, 'db') || Object::uninherited_static($dataClass, 'has_one');
|
DataObject::$cache_has_own_table[$dataClass] = Config::inst()->get($dataClass, 'db', Config::UNINHERITED) || Config::inst()->get($dataClass, 'has_one', Config::UNINHERITED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return DataObject::$cache_has_own_table[$dataClass];
|
return DataObject::$cache_has_own_table[$dataClass];
|
||||||
@ -2967,7 +2966,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
if($ancestry) foreach($ancestry as $ancestorClass) {
|
if($ancestry) foreach($ancestry as $ancestorClass) {
|
||||||
if($ancestorClass == 'ViewableData') break;
|
if($ancestorClass == 'ViewableData') break;
|
||||||
$types = array(
|
$types = array(
|
||||||
'db' => (array) Object::uninherited_static($ancestorClass, 'db'),
|
'db' => (array)Config::inst()->get($ancestorClass, 'db', Config::UNINHERITED)
|
||||||
);
|
);
|
||||||
if($includerelations){
|
if($includerelations){
|
||||||
$types['has_one'] = (array)singleton($ancestorClass)->uninherited('has_one', true);
|
$types['has_one'] = (array)singleton($ancestorClass)->uninherited('has_one', true);
|
||||||
|
@ -292,8 +292,7 @@ class ViewableData extends Object implements IteratorAggregate {
|
|||||||
$mergeFields = is_subclass_of($class, 'DataObject') ? array('db', 'casting') : array('casting');
|
$mergeFields = is_subclass_of($class, 'DataObject') ? array('db', 'casting') : array('casting');
|
||||||
|
|
||||||
if($mergeFields) foreach($mergeFields as $field) {
|
if($mergeFields) foreach($mergeFields as $field) {
|
||||||
$casting = Object::uninherited_static($class, $field);
|
$casting = Config::inst()->get($class, $field, Config::UNINHERITED);
|
||||||
|
|
||||||
if($casting) foreach($casting as $field => $cast) {
|
if($casting) foreach($casting as $field => $cast) {
|
||||||
if(!isset($cache[$field])) $cache[$field] = self::castingObjectCreatorPair($cast);
|
if(!isset($cache[$field])) $cache[$field] = self::castingObjectCreatorPair($cast);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user