Source for file Collection.class.php
Documentation is available at Collection.class.php
* Gumbo Library Framework
* This library is being released under the terms of the New BSD License. A
* copy of the license is packaged with the software (LICENSE.txt). If no
* copy is found, a copy of the license template can be found at:
* http://www.opensource.org/licenses/bsd-license.php
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
* A Collection is a system for defining a one-to-many relationship between
* two different classes. It will load it's contents only when the information
* is needed. The Collection callback will be responsible for loading the
* The primary class (Student) will contain internal information about the
* object. It will also reference a list of data (Course) through some
* association. When the primary class is loaded, it will only load the
* referenced data when the program needs it. This will allow the program
* to access Student information without loading the Course list a student
* The Collection requires a callback function, which is responsible for
* loading the contents of the Collection. The callback is called when the
* details of the Collection is needed. A callback can be a single function
* or a class method. The callback would need the Collection object it will
* be populating and any additional arguments needed.
* public static function loadStudentCourses (Collection $col, $student_id) {
* $col->setType ("Course");
* foreach ($course_list as $course) {
* Since objects are passed by reference, there is no need to return any values. The
* Collection will accept Course objects (defined by the Type). Certain methods
* inside the Collection will call the callback before returning their results.
* The Student class will define a Collection inside the Constructor. This step
* would require defining the Callback function. The Student class would also provide
* a method to return the Collection.
* private $_id; // student ID
* public function __construct () {
* $this->_courses = new Collection ("loadStudentCourses", "Course", $this->id);
* public function getCourses () {
* return $this->_courses;
* When a new Student is created, the Collection object is created, however it is
* empty. When the program tries to retrieve details from the Collection, the callback
* function is called, and the Collection is populated.
* @copyright Copyright (c) 2007, iBayou, Michael Luster
* @license http://www.opensource.org/licenses/bsd-license.php New BSD License
* @author Michael Luster <mluster79@yahoo.com>
* @link http://sourceforge.net/projects/phpgumbo
* @desc Collection Interface
gumbo_load ("Interface_List");
* Sets the callback function/method (extra arguments will be sent to callback as is)
* The callback function will be called to load the contents of the
* Collection. The value could be a function name or a class method. A
* callback function/method should define a single argument, the
* Collection. When the callback is executed, the Collection will
* pass itself (by reference) to the function. The callback will
* set the values of the Collection.
* <code>$coll->setCallback ("function_name");</code>
* To set a class/object method (3 methods):
* $col->setCallback ("method_name", "class_name");
* // substitute an Object ($obj) for "class_name" if necessary
* @precondition function/method callable
* @param string $name function/method name (array should be (0=>"class",1=>"method"))
* @param string|StdClass$obj class name or Object reference
* Sets the type of Class|Interface the Collection will accept
* Returns the Collection Class|Interface Type
* Returns the callback function/method
* Returns the parameters to pass to the callback
* Returns if the Collection has been loaded