Gumbo PHP Library API Documentation
Record
[
class tree
] [
index
] [
all elements
]
Todo List
Packages:
Buffer
Collection
Composite
Config
Converter
Curl
Date
DB
Debug
Encryption
Error
Factory
Filter
Flyweight
Http
Input
Iterator
List
Load
Lockable
Log
Map
Number
Observer
Output
Query
Record
Router
Session
Setting
Singleton
Template
Timer
Utility
Valid
Source for file Flyweight.class.php
Documentation is available at
Flyweight.class.php
<?php
/**
* Gumbo Library Framework
*
* LICENSE
* 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
*
*
@category
Gumbo
*
@package
Record
*
@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
*
@version
0.0.1
*/
/**
* Record Flyweight Class
*
* This class will hold a single Gumbo_Record object, reloading the contents
* with new data supplied by looping through a list of database query rows. Simply
* loop through the results of a query, passing the next row into this class.
* The Record object will be properly loaded.
*
* <pre>
* $fly = new Gumbo_Record_Flyweight (new Gumbo_Record ()); // any Gumbo_Interface_Record Class
* foreach (db_query ("some query") as $res) {
* $record = $fly->get ($res);
* // do something
* ...
* }
* </pre>
*
*
@category
Gumbo
*
@package
Record
*
@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
Record Flyweight Class
*
@version
0.0.1
*/
gumbo_load
(
"Interface_Flyweight"
)
;
gumbo_load
(
"Record"
)
;
class
Gumbo_Record_Flyweight
implements
Gumbo_Interface_Flyweight
{
/**
@var
Gumbo_Interface_Record
$_record
*/
private
$_record
;
/**
* Constructor
*
@param
Gumbo_Interface_Record
$record
Record class to implement (defaults to Gumbo_Record)
*
@uses
Gumbo_Record
*/
public
function
__construct
(
$record
=
null
)
{
if
(
is_null
(
$record
))
{
$record
=
new
Gumbo_Record
(
)
;
}
$this
->
setRecord
(
$record
)
;
}
/** MUTATOR METHODS **/
/**
* Sets the Record object to use
*
@param
Gumbo_Interface_Record
$record
*/
public
function
setRecord
(
Gumbo_Interface_Record
$record
)
{
$this
->
_record
=
$record
;
}
/** ACCESSOR METHODS **/
/**
* Returns the Record object, re-loading with the new data
*
@param
array
$data
associative array of data
*
@return
Gumbo_Interface_Record
*/
public
function
get
(
$data
=
null
)
{
if
(
is_null
(
$data
))
{
return
$this
->
_record
;
}
try
{
// verify precondition
if
(
!
is_array
(
$data
))
{
throw
new
Gumbo_Exception
(
"
Invalid
Argument
'
data
:
arr
' => {
$data
}
:
"
.
gettype
(
$data
))
;
}
$this
->
_record
->
unload
(
true
)
;
$this
->
_record
->
setPrimaryValue
(
$data
)
;
$this
->
_record
->
load
(
)
;
return
$this
->
_record
;
}
catch
(
Gumbo_Exception
$e
)
{
$e
->
setFunction
(
__METHOD__
)
;
gumbo_trigger
(
$e
)
;
}
}
}
?>