Permalink
Browse files

BackwardsCompatibilityBreak - fRecordSet::registerCallback() was rena…

…med to fRecordSet::registerMethodCallback(). fORMJSON refactored slightly.
  • Loading branch information...
wbond committed Sep 14, 2008
1 parent dc35e6a commit 095c09ac4ed6bbaa69e0b7cdae25ab8081469cd7
Showing with 12 additions and 39 deletions.
  1. +6 −33 classes/fORMJSON.php
  2. +6 −6 classes/fRecordSet.php
View
@@ -32,13 +32,7 @@ static public function extend()
array('fORMJSON', 'toJSON')
);
fORM::registerHookCallback(
'*',
'replace::toArray()',
array('fORMJSON', 'toArray')
);
fRecordSet::registerCallback(
fRecordSet::registerMethodCallback(
'toJSON',
array('fORMJSON', 'toJSONRecordSet')
);
@@ -72,7 +66,7 @@ static public function reflect($class, &$signatures, $include_doc_comments)
/**
* Returns the values array - used by {@link toJSONRecordSet()}
* Returns a JSON object representation of the record
*
* @internal
*
@@ -84,38 +78,17 @@ static public function reflect($class, &$signatures, $include_doc_comments)
* @param array &$parameters The parameters passed to the method
* @return string The JSON object that represents the values of this record
*/
static public function toArray($object, &$values, &$old_values, &$related_records, &$method_name, &$parameters)
static public function toJSON($object, &$values, &$old_values, &$related_records, &$method_name, &$parameters)
{
$output = array();
foreach ($values as $column => $value) {
if (is_object($value) && is_callable(array($value, '__toString'))) {
$value = $value->__toString();
}
$output[$column] = $value;
}
}
return $output;
}
/**
* Returns a JSON object representation of the record
*
* @internal
*
* @param fActiveRecord $object The fActiveRecord instance
* @param array &$values The current values
* @param array &$old_values The old values
* @param array &$related_records Any records related to this record
* @param string &$method_name The method that was called
* @param array &$parameters The parameters passed to the method
* @return string The JSON object that represents the values of this record
*/
static public function toJSON($object, &$values, &$old_values, &$related_records, &$method_name, &$parameters)
{
$method = 'toArray';
$params = array();
return fJSON::encode(self::toArray($object, $values, $old_values, $related_records, $method, $params));
return fJSON::encode($output);
}
@@ -133,7 +106,7 @@ static public function toJSON($object, &$values, &$old_values, &$related_records
*/
static public function toJSONRecordSet($record_set, $class, &$records, &$pointer, &$associate)
{
return fJSON::encode($record_set->call('toArray'));
return '[' . join(',', $record_set->call('toJSON')) . ']';
}
View
@@ -19,7 +19,7 @@ class fRecordSet implements Iterator
*
* @var array
*/
static private $callbacks = array();
static private $method_callbacks = array();
/**
@@ -319,7 +319,7 @@ static public function configure($class)
/**
* Registers a callback to be called when a specific method name is handled by __call()
* Registers a callback to be called when a specific method is handled by __call()
*
* The callback should accept the following parameters:
* - $record_set: The actual record set
@@ -332,9 +332,9 @@ static public function configure($class)
* @param callback $callback The callback to execute - see method description for parameter list
* @return void
*/
static public function registerCallback($method, $callback)
static public function registerMethodCallback($method, $callback)
{
self::$callbacks[$method] = $callback;
self::$method_callbacks[$method] = $callback;
}
@@ -394,9 +394,9 @@ public function __call($method_name, $parameters)
{
list($action, $element) = explode('_', fGrammar::underscorize($method_name), 2);
if (isset(self::$callbacks[$method_name])) {
if (isset(self::$method_callbacks[$method_name])) {
return call_user_func_array(
self::$callbacks[$method_name],
self::$method_callbacks[$method_name],
array(
$this,
$this->class,

0 comments on commit 095c09a

Please sign in to comment.