Permalink
Browse files

API CHANGE: Change variable expose method in TemplateGlobalProvider a…

…nd TemplateIteratorProvider to (a) not clash with each other and, (b) be less generic
  • Loading branch information...
1 parent 2c65d3a commit 374ed19406b847b3b7d463fb084536f27cc3600a Hamish Friedlander committed Feb 21, 2012
View
@@ -584,7 +584,7 @@ static function join_links() {
return $result;
}
- public static function get_exposed_variables() {
+ public static function get_template_global_variables() {
return array(
'CurrentPage' => 'curr',
);
View
@@ -870,7 +870,7 @@ static function isTest() {
* @return array Returns an array of strings of the method names of methods on the call that should be exposed
* as global variables in the templates.
*/
- public static function get_exposed_variables() {
+ public static function get_template_global_variables() {
return array(
'absoluteBaseURL',
'baseURL',
View
@@ -1957,7 +1957,7 @@ static function merge_locale_data($locale, $extra) {
}
}
- public static function get_exposed_variables() {
+ public static function get_template_global_variables() {
return array(
'i18nLocale' => 'get_locale',
'get_locale',
View
@@ -1379,7 +1379,7 @@ function getHtmlEditorConfigForCMS() {
return $currentName ? $currentName : 'cms';
}
- public static function get_exposed_variables() {
+ public static function get_template_global_variables() {
return array(
'CurrentMember' => 'currentUser',
'currentUser'
View
@@ -622,7 +622,7 @@ public function onBeforeWrite() {
Permission::flush_permission_cache();
}
- public static function get_exposed_variables() {
+ public static function get_template_global_variables() {
return array(
'HasPerm' => 'check'
);
@@ -218,7 +218,7 @@ protected function generate() {
return $generator->generateHash('sha1');
}
- public static function get_exposed_variables() {
+ public static function get_template_global_variables() {
return array(
'getSecurityID',
'SecurityID' => 'getSecurityID'
@@ -990,7 +990,7 @@ function lotsOfArguments11($a, $b, $c, $d, $e, $f, $g, $h, $i, $j, $k) {
class SSViewerTest_GlobalProvider implements TemplateGlobalProvider, TestOnly {
- public static function get_exposed_variables() {
+ public static function get_template_global_variables() {
return array(
'SSViewerTest_GlobalHTMLFragment' => array('method' => 'get_html'),
'SSViewerTest_GlobalHTMLEscaped' => array('method' => 'get_html', 'casting' => 'Varchar'),
View
@@ -134,7 +134,7 @@ class SSViewer_BasicIteratorSupport implements TemplateIteratorProvider {
protected $iteratorPos;
protected $iteratorTotalItems;
- public static function get_exposed_variables() {
+ public static function get_template_iterator_variables() {
return array(
'First',
'Last',
@@ -307,28 +307,28 @@ function __construct($item, $extras = array()){
if (self::$globalProperties === null) {
self::$globalProperties = array();
// Get all the exposed variables from all classes that implement the TemplateGlobalProvider interface
- $this->createCallableArray(self::$globalProperties, "TemplateGlobalProvider");
+ $this->createCallableArray(self::$globalProperties, "TemplateGlobalProvider", "get_template_global_variables");
}
// Build up iterator property providers array only once per request
if (self::$iteratorProperties === null) {
self::$iteratorProperties = array();
// Get all the exposed variables from all classes that implement the TemplateIteratorProvider interface
- $this->createCallableArray(self::$iteratorProperties, "TemplateIteratorProvider", true); //call non-statically
+ $this->createCallableArray(self::$iteratorProperties, "TemplateIteratorProvider", "get_template_iterator_variables", true); //call non-statically
}
$this->extras = $extras;
}
- protected function createCallableArray(&$extraArray, $interfaceToQuery, $createObject = false) {
+ protected function createCallableArray(&$extraArray, $interfaceToQuery, $variableMethod, $createObject = false) {
$implementers = ClassInfo::implementorsOf($interfaceToQuery);
if($implementers) foreach($implementers as $implementer) {
// Create a new instance of the object for method calls
if ($createObject) $implementer = new $implementer();
// Get the exposed variables
- $exposedVariables = $implementer::get_exposed_variables();
+ $exposedVariables = $implementer::$variableMethod();
foreach($exposedVariables as $varName => $details) {
if (!is_array($details)) $details = array('method' => $details, 'casting' => Object::get_static('ViewableData', 'default_cast'));
@@ -1,21 +1,35 @@
<?php
/**
- * Interface that is implemented by any classes that want to expose a method that can be called in a template.
+ * Interface that is implemented by any classes that want to expose a method that can be called in any scope in a template.
+ *
* Director::AbsoluteBaseURL is an example of this.
+ *
* @package sapphire
* @subpackage core
*/
interface TemplateGlobalProvider {
+
/**
+ * Called by SSViewer to get a list of global variables to expose to the template, the static method to call on
+ * this class to get the value for those variables, and the class to use for casting the returned value for use
+ * in a template
+ *
+ * If the method to call is not included for a particular template variable, a method named the same as the template
+ * variable will be called
+ *
+ * If the casting class is not specified for a particular template variable, ViewableData::$default_cast is used
+ *
+ * The first letter of the template variable is case-insensitive. However the method name is always case sensitive.
+ *
* @abstract
- * @return array Returns an array of strings of the method names of methods on the call that should be exposed
- * as global variables in the templates. A map (template-variable-name => method-name) can optionally be supplied
- * if the template variable name is different from the name of the method to call. The case of the first character
- * in the method name called from the template does not matter, although names specified in the map should
- * correspond to the actual method name in the relevant class.
- * Note that the template renderer must be able to call these methods statically.
+ * @return array Returns an array of items. Each key => value pair is one of three forms:
+ * - template name (no key)
+ * - template name => method name
+ * - template name => array(), where the array can contain these key => value pairs
+ * - "method" => method name
+ * - "casting" => casting class to use (i.e., Varchar, HTMLText, etc)
*/
- public static function get_exposed_variables();
+ public static function get_template_global_variables();
}
?>
@@ -1,24 +1,43 @@
<?php
/**
- * Interface that is implemented by any classes that want to expose a method that can be called in a template.
+ * Interface that is implemented by any classes that want to expose a method that can be called in any scope in a template
+ * that returns values dependant on the state of the iterator of the current scope.
+ *
* SSViewer_BasicIteratorSupport is an example of this. See also @TemplateGlobalProvider
+ *
* @package sapphire
* @subpackage core
*/
interface TemplateIteratorProvider {
+
/**
+ * Called by SSViewer to get a list of iterator variables to expose to the template, the instance method to call on
+ * an instance of this class to get the value for those variables, and the class to use for casting the returned value
+ * for use in a template
+ *
+ * If the method to call is not included for a particular template variable, a method named the same as the template
+ * variable will be called
+ *
+ * If the casting class is not specified for a particular template variable, ViewableData::$default_cast is used
+ *
+ * The first letter of the template variable is case-insensitive. However the method name is always case sensitive.
+ *
* @abstract
- * @return array Returns an array of strings of the method names of methods on the call that should be exposed
- * as global variables in the templates. A map (template-variable-name => method-name) can optionally be supplied
- * if the template variable name is different from the name of the method to call. The case of the first character
- * in the method name called from the template does not matter, although names specified in the map should
- * correspond to the actual method name in the relevant class.
- * Note that the template renderer must be able to call these methods statically.
+ * @return array Returns an array of items. Each key => value pair is one of three forms:
+ * - template name (no key)
+ * - template name => method name
+ * - template name => array(), where the array can contain these key => value pairs
+ * - "method" => method name
+ * - "casting" => casting class to use (i.e., Varchar, HTMLText, etc)
*/
- public static function get_exposed_variables();
+ public static function get_template_iterator_variables();
/**
* Set the current iterator properties - where we are on the iterator.
+ *
+ * This is called by SSViewer prior to calling any of the variables exposed to the template (that is, as returned
+ * from a call to get_template_iterator_variables)
+ *
* @abstract
* @param int $pos position in iterator
* @param int $totalItems total number of items

0 comments on commit 374ed19

Please sign in to comment.