kla/php-activerecord — pull request #243 by leightonshank (2012-11-15 21:45:37+00:00)
Title: Custom attributes serialization and access

Updated the ActiveRecord\Serialization method `check_methods()` so that it will check for a getter method with the name of the method passed. This way, custom attributes defined as getter methods, e.g. `get_full_name()` can be passed directly to a serialization method in the `methods` option.

Example:
```
first_name} {$this->last_name}";
}
}

$person = Person::find(1);
$person->to_json(array("methods" => "full_name"));

# {"first_name":"John", "last_name":"Smith", "full_name": "John Smith"}
```

In the same vein, updated the ActiveRecord\Model `__get()` magic method so that custom attributes can be accessed through a method of the same name. For example, if I have a method in my model named `initials()` then that method can be accessed as a property or a method. If the method takes arguments, then calling as a property is the same as calling with no arguments (using defaults). If the method requires arguments, then obviously it cannot be called as a property.

Example:
```
first_name[0] . "." . $this->last_name[1] . "."
: $this->first_name[0] . $this->last_name[1];
}
}

$person = Person::find(1);
print $person->initials; # JS
print $person->initials(); # JS
print $person->initials(true); # J.S.
```