public static function build($name, $create = false) 
    {
        self::load();
        $data = self::attributes_for($name);
        if (!$data) {
            return null;
        }

        // if is a different class ...
        if (is_array(self::$_options[$name])
            && array_key_exists("class_name", self::$_options[$name])
        ) {
            $name = self::$_options[$name]["class_name"];
        }

        $cls = ucfirst(strtolower($name));
        $obj = new $cls();
        $pk  = $obj::getPK();

        if (!array_key_exists($pk, $data)) {
            $data[$pk] = null;
        }

        $obj = new $cls($data);  
        if ($create) {
            if (!$obj->isValid()) {
                return null;
            }
            $obj->save();
        }
        return $obj;
    }
public static function build($name, $create = false) 
    {
        self::load();
        $data = self::attributes_for($name);
        if (!$data) {
            return null;
        }

        // if is a different class ...
        if (is_array(self::$_options[$name])
            && array_key_exists("class_name", self::$_options[$name])
        ) {
            $name = self::$_options[$name]["class_name"];
        }

        $cls = ucfirst(strtolower($name));
        $obj = new $cls();
        $pk  = $obj::getPK();

        if (!array_key_exists($pk, $data)) {
            $data[$pk] = null;
        }

        $obj = new $cls($data);  
        if ($create) {
            if (!$obj->isValid()) {
                return null;
            }
            $obj->save();
        }
        return $obj;
    }
public static function build ( $ name , $ create = false ) { self :: load ( ) ; $ data = self :: attributes_for ( $ name ) ; if ( ! $ data ) { return null ; } // if is a different class ... if ( is_array ( self :: $ _options [ $ name ] ) && array_key_exists ( "class_name" , self :: $ _options [ $ name ] ) ) { $ name = self :: $ _options [ $ name ] [ "class_name" ] ; } $ cls = ucfirst ( strtolower ( $ name ) ) ; $ obj = new $ cls ( ) ; $ pk = $ obj :: getPK ( ) ; if ( ! array_key_exists ( $ pk , $ data ) ) { $ data [ $ pk ] = null ; } $ obj = new $ cls ( $ data ) ; if ( $ create ) { if ( ! $ obj -> isValid ( ) ) { return null ; } $ obj -> save ( ) ; } return $ obj ; }
Build a factory

@param string  $name   factory name
@param boolean $create create factory

@return mixed factory
Build a factory