note 62640 added to function.preg-replace-callback

From: Date: Mon, 06 Mar 2006 06:12:47 +0000
Subject: note 62640 added to function.preg-replace-callback
Groups: php.notes 
Request: Send a blank email to php-notes+get-104881@lists.php.net to get a copy of this message
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) ---- Server IP: 66.163.161.117 Probable Submitter: 200.106.56.5 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.preg-replace-callback.php Edit -- http://master.php.net/note/edit/62640 Del: integrated -- http://master.php.net/note/delete/62640/integrated Del: useless -- http://master.php.net/note/delete/62640/useless Del: bad code -- http://master.php.net/note/delete/62640/bad+code Del: spam -- http://master.php.net/note/delete/62640/spam Del: non-english -- http://master.php.net/note/delete/62640/non-english Del: in docs -- http://master.php.net/note/delete/62640/in+docs Del: other reasons-- http://master.php.net/note/delete/62640 Reject -- http://master.php.net/note/reject/62640 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#104881) next »