protected function createCommand(ReflectionMethod $method) { $methodName = $method->getName(); $pdo = HermitDataSourceManager::get($this->context->getName(), $methodName, HermitEvent::EVT_SETUP); if (null === $pdo) { throw new RuntimeException('setup connection fail. pdo: ' . $pdo); } if (HermitNamingUtils::isProcedure($methodName)) { $factory = new HermitProcedureSqlCommandFactory(); } else { if (HermitNamingUtils::isInsert($methodName)) { $factory = new HermitInsertSqlCommandFactory(); } else { if (HermitNamingUtils::isUpdate($methodName)) { $factory = new HermitUpdateSqlCommandFactory(); } else { if (HermitNamingUtils::isDelete($methodName)) { $factory = new HermitDeleteSqlCommandFactory(); } else { $factory = new HermitSelectSqlCommandFactory(); } } } } $factory->setAnnote($this->annote); $factory->setMethod($method); return $factory->create($pdo, $this->context); }
protected function getConnection($event = HermitEvent::UNKNOWN) { return HermitDataSourceManager::get($this->context->getName(), $this->method->getName(), $event); }
public function callIN_OUT_MULTI(HermitParam $param); const callINOUT_MULTI_PROCEDURE = 'PROC_INOUT_MULTIRESULT'; const callINOUT_MULTI_VALUE_TYPE = 'OBJ'; public function callINOUT_MULTI(HermitParam $param); const callOUT_MULTI_PROCEDURE = 'PROC_OUT_MULTIRESULT'; const callOUT_MULTI_VALUE_TYPE = 'OBJ'; public function callOUT_MULTI(HermitParam $param); const callNOSPEC_PARAM_PROCEDURE = 'PROC_NOSPEC_PARAM'; const callNOSPEC_PARAM_VALUE_TYPE = 'OBJ'; public function callNOSPEC_PARAM(HermitParam $param); } $pdo = new PDO('mysql:host=localhost; dbname=hermit_test', 'root', 'password'); db_init($pdo); $test = new lime_test(); $test->diag(basename(__FILE__)); HermitDataSourceManager::setDefault($pdo); $hermit = new Hermit('PROC'); $param = new HermitParam(); $param->sales = 1000; $param->tax = -1; $result = $hermit->callIN_OUT($param); $test->ok($param->tax !== -1); $test->is($param->tax, 200); $test->ok($result === null); $param = new HermitParam(); $param->sales = 5000; $result = $hermit->callINOUT($param); $test->ok($result === null); $test->is($param->sales, 1000); $result2 = $hermit->callINOUT($param); $test->ok($result === null);
protected function getDataSource($methodName, $type) { $target = $this->context->getName(); return HermitDataSourceManager::get($target, $methodName, $type); }
class Hoge { private $dao; public function __construct() { //HermitDaoManager::set(__CLASS__, 'EmployeeDao'); $this->dao = new Hermit('EmployeeDao'); } public function getAll() { return $this->dao->getAllEmployeeList(); } public function getOne() { return $this->dao->getEmployeeByEmpNo(7698); } public function getEmp() { $emp = new Employee(); $emp->empno = 7566; $emp->ename = 'JONES'; return $this->dao->getEmployee($emp); } } $pdo = new PDO('sqlite:' . dirname(__FILE__) . '/resource/employee.db'); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); HermitDataSourceManager::set('EmployeeDao', $pdo); $hoge = new Hoge(); echo '[getAll] -----------------', var_export($hoge->getAll(), true), PHP_EOL; echo '[getOne] -----------------', var_export($hoge->getOne(), true), PHP_EOL; echo '[getEmp] -----------------', var_export($hoge->getEmp(), true), PHP_EOL;
public static function setCallback(array $callback) { self::$callback = $callback; }