note 62640 deleted from function.preg-replace-callback by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 18:45:43 +0000 |
| Subject: | note 62640 deleted from function.preg-replace-callback by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127658@lists.php.net to get a copy of this message | ||
Note Submitter: mplescano at gmail dot com
----
class User {
var $id;
var $usuario;
var $clave;
function setId ($id) {
$this->id = $id;
}
function getId () {
return $this->id;
}
function setUsuario ($usuario) {
$this->usuario = $usuario;
}
function getUsuario () {
return $this->usuario;
}
function setClave ($clave) {
$this->clave = $clave;
}
function getClave () {
return $this->clave;
}
function User () {
}
}
class PropertyUtils
{
...
/**
* Get the value of the specified property on the subject bean using
* the standard notation for getter methods from the JavaBean spec.
*
* @return Object
*/
function &getSimpleProperty(&$bean, $name)
{
if (is_null($bean)) {
return null;
}
$method = 'get' . ucfirst($name);
if (!method_exists($bean, $method)) {
$method = 'is' . ucfirst($name);
}
if (!method_exists($bean, $method)) {
$method = null;
}
if (is_null($method)) {
return null;
}
$return =& $bean->$method();
return $return;
}
...
}
$statement['user.insert'][] = array('sentence'=>"INSERT INTO tb01 (id,
usuario, clave) VALUES (#id#, #usuario#, #clave#)",
'parameter'=>'User');
class Mapper {
...
function insert ($clazzName, $newBean, $order = 0) {
global $statement;
$statementStr =
$statement[$clazzName.'.'.'insert'][$order]['sentence'];
if (get_class($newBean) !== false && $clazzName == get_class($newBean)) {
$statementParsed = Mapper::parseStatementBeanParameter($newBean, $statementStr);
}
else if (is_array($newBean) && count($newBean) > 0) {
$statementParsed = Mapper::parseStatementArrayParameter($newBean, $statementStr);
}
return $statementParsed;
}
...
function parseStatementBeanParameter (&$bean, $statement) {
$parsedStatement =
preg_replace("/#([^#\s]+)#/e","Mapper::searchParameterBean('\\1',
\$bean)", $statement);
return $parsedStatement;
}
...
function searchParameterBean ($index, $bean) {
$clazzName = get_class($bean);
$propertyValue = '';
if (!($clazzName == '' || $clazzName === false)) {
$propertyValue = PropertyUtils::getSimpleProperty($bean, $index);
}
return $propertyValue;
}
}
$user =& new User();
$user->setId(1);
$user->setUsuario("antonio");
$user->setClave("aguiero");
echo Mapper::insert (get_class($user), $user);
Print:
INSERT INTO tb01 (id, usuario, clave) VALUES (1, antonio, aguiero)