I was thinking methods something like this
Code: Select all
interface FCP_ShipType
{
const FROM_ID = 1 ;
const FROM_ABBRV = 2 ;
/**
* Set the ship type
*
* @param mixed $shipType Either a ship type ID or abbreviation
*/
public function set($shipType) ;
/**
* Constructor
*
* @param mixed $shipType Either a ship type ID or abbreviation
*/
public function __construct($shipType) ;
/**
* Get the primary key of the ship type
*
* @return int
*/
public function getID() ;
/**
* Get the description for ship type
*
* @return string
*/
public function getDescription() ;
/**
* Get the abbreviation for this ship type
*
* @return string
*/
public function getAbbrv() ;
/**
* Get the carrier for this ship type
*
* @return string
*/
public function getCarrier() ;
/**
* Check if this object contains a valid ship type
*
* @return bool
*/
public function isValid() ;
}
// use
$shipType = new FCP_ShipType('PMD') ;
$otherShipType = new FCP_ShipType(3) ; // use the database ID
echo $shipType->getCarrier() ; // USPS
echo $shipType->getDescription() ; // Priority mail w/delivery confirmation
echo $otherShipType->getDescription() ; // DHL ground @home
// use as a member of another object
$order->getShipType()->getAbbrv() ;Now here is the puzzle. In order to do validation and mapping between IDs and abbreviations, I need to do a query to pull the ship types from the database and store them in a static array within this class or some other method.
Is there a clean way to do this without having to inject the db connection or a registry into this value object? I really don't want value objects to have dependencies such as that.