Created
May 15, 2012 16:10
-
-
Save dkhenry/2702947 to your computer and use it in GitHub Desktop.
Example of PHP traits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait DatabaseToObject { | |
public static function fromResultSet( $results) { | |
$retval = array(); | |
if(!$results) { | |
return $retval; | |
} | |
while( $row = $results->fetchObject() ) { | |
$retval[] = static::construct($row); | |
} | |
return $retval; | |
} | |
} | |
class FileParser { | |
use DatabaseToObject; | |
public static function construct( $object ) { | |
$fp = new FileParser(); | |
$fp->name = $object->name ; | |
$fp->code = $object->code ; | |
$fp->types = array(); | |
return $fp; | |
} | |
public static function list_full( $link ) { | |
return FileParser::fromResultSet( $link->query(static::$fpquery)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment