<?php

require_once 'common/bean/Bean.php';

/**
 * Lazy Bean attribute.
 * 
 * This class encapsulates a <em>Bean</em>'s attribute, handling the lazy 
 * initialization capabilities of this attribute.
 * This class is used as attribute for a <em>OrmLazyBean</em>.
 * 
 * @author  $Author: pruna $
 * @package orm/vo
 * @version $Revision: 1.3 $
 * @created 18-Oct-2005
 * @modified $Date: 2005/12/06 02:56:45 $
 */
class OrmLazyAttribute extends Bean {
    
    /**
     * Constructor that defines basic properties for this Bean.
     * 
     * It follows Collection rules for constructor.
     * Basic elements are: 
     * <ul>
     * <li>key: Key of this attribute (mixed)</li>
     * <li>map: OrmMap used for loading (OrmMap)</li>
     * <li>method: Method to use for loading (string)</li>
     * <li>param: Param to use when calling method (mixed)</li>
     * </ul>
     * Default values may serve as guide for preferred data types.
     * For a full description about this elements, see @docs
     * 
     * @access  public
     * @param   ICollection    $collection    Initial elements
     */
    public function __construct($collection = null) {
        parent::__construct(array(
            'key' => null,
            'map' => null,
            'method' => '',
            'param' => null,
            'db' => null,
        ));
        $this->setAll($collection);
    }
    
    /**
     * Looks for real content to be used to replace this attribute.
     *
     * @access  default
     * @return  mixed
     */
    function wakeUp() {
        $dao = new OrmCore($this->getMap(), $this->getDb());
        $method = $this->getMethod();
        return $dao->$method($this->getParam());
    }
    
}

?>