Skip to content
This repository
Browse code

MINOR Documentation for new Config system and DataExtension/extraStat…

…ics when upgrading
  • Loading branch information...
commit 3616fb01de1e52d3180a3eca6f9df25a668d0061 1 parent 2b5a906
Sean Harvey authored April 19, 2012

Showing 1 changed file with 73 additions and 0 deletions. Show diff stats Hide diff stats

  1. 73  docs/en/changelogs/3.0.0.md
73  docs/en/changelogs/3.0.0.md
Source Rendered
@@ -27,6 +27,79 @@ Here's a list of steps to check:
27 27
  * Find and replace any references to `sapphire` in your custom code to `framework`. In your PHP code, you can use the constant `FRAMEWORK_DIR`,
28 28
 which points to the framework directory, and in the templates you can use `$ModulePath(framework)`
29 29
 
  30
+### Object static functions replaced with new Config class [new-config] ###
  31
+
  32
+Static functions for getting a static variable on the `Object` class have been deprecated,
  33
+in favour of using the new `Config` class instead.
  34
+
  35
+`Object::set_static('MyClass', 'myvar')` becomes `Config::inst()->update('MyClass', 'myvar', 'myval')` instead.
  36
+`Object::addStaticVars('MyClass', array('myvar' => 'myval'))` should be replaced with individual calls to `Config::inst()->update()` instead.
  37
+`Object::add_static_var('MyClass', 'myvar', 'myval')` becomes `Config::inst()->update('MyClass', 'myvar', 'myval')` instead.
  38
+`Object::set_uninherited('MyClass', 'myvar', 'myval')` becomes `Config::inst()->update('MyClass', 'myvar', 'myval')` instead.
  39
+
  40
+Any arrays you pass as values to `update()` will be automatically merged. To replace the variable, call `remove()` first, then call `update()`.
  41
+
  42
+`Object::get_static('MyClass', 'myvar')` becomes `Config::inst()->get('MyClass', 'myvar', Config::FIRST_SET)`
  43
+`Object::uninherited_static('MyClass', 'myvar')` becomes `Config::inst()->get('MyClass', 'myvar', Config::UNINHERITED)`
  44
+`Object::combined_static('MyClass', 'myvar')` becomes `Config::inst()->get('MyClass', 'myvar')` (no option as third argument)
  45
+
  46
+Note the different options for the third parameter of `get()`:
  47
+
  48
+`Config::INHERITED` will only get the configuration set for the specific class, not any of it's parents.
  49
+`Config::FIRST_SET` will inherit configuration from parents, but stop on the first class that actually provides a value.
  50
+`Config::EXCLUDE_EXTRA_SOURCES` will not use additional static sources (such as those defined on extensions)
  51
+
  52
+If you don't set an option, it will get all the values for the static, including inherited ones.
  53
+This was previously known as `Object::combined_static()`.
  54
+
  55
+### DataExtension and deprecated extraStatics on extension classes [extensions] ###
  56
+
  57
+`DataObjectDecorator` has been renamed to `DataExtension`. Any classes that extend `DataObjectDecorator`
  58
+should now extend `DataExtension` instead.
  59
+
  60
+`extraStatics()` on extensions is now deprecated.
  61
+
  62
+Instead of using `extraStatics()`, you can simply define static variables on your extension directly.
  63
+
  64
+If you need custom logic, e.g. checking for a class before applying the statics on the extension,
  65
+you can use `add_to_class()` as a replacement to `extraStatics()`.
  66
+
  67
+Given the original `extraStatics` function:
  68
+
  69
+	<?php
  70
+	//...
  71
+	function extraStatics($class, $extensionClass) {
  72
+		if($class == 'MyClass') {
  73
+			return array(
  74
+				'db' => array(
  75
+					'Title' => 'Varchar'
  76
+				);
  77
+			);
  78
+		}
  79
+	}
  80
+
  81
+This would now become a static function `add_to_class`, and calls `update()` with an array
  82
+instead of returning it. It also needs to call `parent::add_to_class()`:
  83
+
  84
+	<?php
  85
+	//...
  86
+	static function add_to_class($class, $extensionClass, $args = null) {
  87
+		if($class == 'MyClass') {
  88
+			Config::inst()->update($class, 'db', array(
  89
+				'Title' => 'Varchar'
  90
+			));
  91
+		}
  92
+		parent::add_to_class($class, $extensionClass, $args);
  93
+	}
  94
+
  95
+Alternatively, you can define statics on the extension directly, like this:
  96
+
  97
+	<?php
  98
+	//...
  99
+	static $db = array(
  100
+		'Title' => 'Varchar'
  101
+	);
  102
+
30 103
 ### New ORM: More flexible and expressive querying via `DataList` [new-orm-datalist] ###
31 104
 
32 105
 The new "fluent" syntax to retrieve ORM records allows for a more

0 notes on commit 3616fb0

Please sign in to comment.
Something went wrong with that request. Please try again.