- Timestamp:
- 10/08/08 18:17:27 (3 months ago)
- Location:
- lang/php/misc/Hermit/src/Hermit
- Files:
-
- 3 added
- 13 modified
-
Hermit.php (modified) (1 diff)
-
HermitContext.php (added)
-
HermitDataSourceManager.php (modified) (1 diff)
-
HermitEvent.php (added)
-
command/AbstractHermitSqlCommand.php (added)
-
command/HermitDeleteCommand.php (modified) (1 diff)
-
command/HermitInsertCommand.php (modified) (1 diff)
-
command/HermitProcedureCommand.php (modified) (1 diff)
-
command/HermitSelectCommand.php (modified) (1 diff)
-
command/HermitSqlCommand.php (modified) (1 diff)
-
command/HermitSqlCommandFactory.php (modified) (5 diffs)
-
command/HermitUpdateCommand.php (modified) (1 diff)
-
proxy/HermitClassProxy.php (modified) (1 diff)
-
proxy/HermitFutureProxy.php (modified) (1 diff)
-
proxy/HermitInterfaceProxy.php (modified) (2 diffs)
-
proxy/HermitObjectProxy.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/php/misc/Hermit/src/Hermit/Hermit.php
r20314 r20966 34 34 protected static function __create($targetClass){ 35 35 if(is_object($targetClass)){ 36 return HermitObjectProxy::delegate(new ReflectionObject($targetClass), $targetClass); 36 $refObject = new ReflectionObject($targetClass); 37 $ctx = new HermitContext($refObject->getName()); 38 return HermitObjectProxy::delegate($ctx, $refObject, $targetClass); 37 39 } 38 40 $reflector = new ReflectionClass($targetClass); 41 $ctx = new HermitContext($targetClass); 39 42 if($reflector->isInterface()){ 40 return HermitInterfaceProxy::delegate($ reflector);43 return HermitInterfaceProxy::delegate($ctx, $reflector); 41 44 } 42 return HermitClassProxy::delegate($ reflector);45 return HermitClassProxy::delegate($ctx, $reflector); 43 46 } 44 47 protected static function wrap(HermitProxy $proxy, $targetClass){ -
lang/php/misc/Hermit/src/Hermit/HermitDataSourceManager.php
r19775 r20966 6 6 abstract class HermitDataSourceManager { 7 7 private static $default; 8 private static $callback; 8 9 private static $datasources = array(); 9 10 private function __construct(){ 11 // mp@ 10 12 } 11 13 public static function setDefault(PDO $default){ 12 14 self::$default = $default; 13 15 } 16 public static function hasDefault(){ 17 return null !== self::$default; 18 } 19 public static function setCallback(array $callback){ 20 self::$callback = $callback; 21 } 22 public static function hasCallback(){ 23 return null !== self::$callback; 24 } 14 25 public static function set($targetClass, PDO $pdo){ 15 26 self::$datasources[$targetClass] = $pdo; 16 27 } 17 public static function get($targetClass){ 28 public static function get($targetClass, $method = null, $type = HermitEvent::UNKNOWN){ 29 if(self::hasCallback()){ 30 return call_user_func_array(self::$callback, array($targetClass, $method, $type)); 31 } 32 18 33 if(!self::has($targetClass)){ 19 34 return self::$default; -
lang/php/misc/Hermit/src/Hermit/command/HermitDeleteCommand.php
r20200 r20966 4 4 * @author nowelium 5 5 */ 6 class HermitDeleteCommand implements HermitSqlCommand { 7 public function execute(PDO $pdo, array $params){ 6 class HermitDeleteCommand extends AbstractHermitSqlCommand { 7 public function execute(array $parameters){ 8 $pdo = $this->getConnection(HermitEvent::EVT_DELETE); 9 $builder = new HermitStatementBuilder($this->method, $this->sqlCreator); 10 $stmt = $builder->build($pdo); 11 $stmt->execute($parameters); 12 $resultset = new HermitUpdateQueryResultSet; 13 return $resultset->execute($stmt, $this->type); 8 14 } 9 15 } -
lang/php/misc/Hermit/src/Hermit/command/HermitInsertCommand.php
r20200 r20966 4 4 * @author nowelium 5 5 */ 6 class HermitInsertCommand implements HermitSqlCommand { 7 public function execute(PDO $pdo, array $parameters){ 8 } 6 class HermitInsertCommand extends AbstractHermitSqlCommand { 7 public function execute(array $parameters){ 8 $pdo = $this->getConnection(HermitEvent::EVT_INSERT); 9 $builder = new HermitStatementBuilder($this->method, $this->sqlCreator); 10 $stmt = $builder->build($pdo); 11 $stmt->execute($parameters); 12 $resultset = new HermitUpdateQueryResultSet; 13 return $resultset->execute($stmt, $this->type); 14 } 9 15 } -
lang/php/misc/Hermit/src/Hermit/command/HermitProcedureCommand.php
r20492 r20966 4 4 * @author nowelium 5 5 */ 6 class HermitProcedureCommand implements HermitSqlCommand { 7 private $method; 8 private $sqlCreator; 9 private $type; 10 private $annote; 11 public function setMethod(ReflectionMethod $method){ 12 $this->method = $method; 13 } 14 public function setSqlCreator(HermitSqlCreator $sqlCreator){ 15 $this->sqlCreator = $sqlCreator; 16 } 17 public function setValueType(HermitValueType $type){ 18 $this->type = $type; 19 } 6 class HermitProcedureCommand extends AbstractHermitSqlCommand { 7 protected $annote; 20 8 public function setAnnote(HermitAnnote $annote){ 21 9 $this->annote = $annote; 22 10 } 23 public function execute(PDO $pdo, array $parameters){ 11 public function execute(array $parameters){ 12 $pdo = $this->getConnection(HermitEvent::EVT_PROCEDURE); 24 13 if($this->sqlCreator instanceof HermiSetupSqlCreator){ 25 14 if($this->sqlCreator->hasSetupSql()){ -
lang/php/misc/Hermit/src/Hermit/command/HermitSelectCommand.php
r20387 r20966 4 4 * @author nowelium 5 5 */ 6 class HermitSelectCommand implements HermitSqlCommand { 7 private $method; 8 private $sqlCreator; 9 private $type; 10 public function __construct(ReflectionMethod $method, HermitSqlCreator $sqlCreator, HermitValueType $type){ 11 $this->method = $method; 12 $this->sqlCreator = $sqlCreator; 13 $this->type = $type; 14 } 15 public function execute(PDO $pdo, array $parameters){ 6 class HermitSelectCommand extends AbstractHermitSqlCommand { 7 public function execute(array $parameters){ 8 $pdo = $this->getConnection(HermitEvent::EVT_SELECT); 16 9 $builder = new HermitStatementBuilder($this->method, $this->sqlCreator); 17 10 $stmt = $builder->build($pdo); -
lang/php/misc/Hermit/src/Hermit/command/HermitSqlCommand.php
r19682 r20966 5 5 */ 6 6 interface HermitSqlCommand { 7 public function execute( PDO $pdo,array $params);7 public function execute(array $params); 8 8 } -
lang/php/misc/Hermit/src/Hermit/command/HermitSqlCommandFactory.php
r20387 r20966 6 6 class HermitSqlCommandFactory { 7 7 8 protected $context; 8 9 protected $annote; 9 10 protected $reflector; 10 11 protected $createdCommands = array(); 11 12 12 public function __construct(ReflectionClass $reflector){ 13 public function __construct(HermitContext $ctx, ReflectionClass $reflector){ 14 $this->context = $ctx; 13 15 $this->annote = HermitAnnote::create($reflector); 14 16 $this->reflector = $reflector; … … 17 19 return $this->annote->hasMethod($methodName); 18 20 } 19 public function create( PDO $pdo,$methodName){21 public function create($methodName){ 20 22 if(isset($this->createdCommands[$methodName])){ 21 23 return $this->createdCommands[$methodName]; 22 24 } 23 25 $method = $this->annote->getMethod($methodName); 24 $command = $this->createCommand($ pdo, $method);26 $command = $this->createCommand($method); 25 27 return $this->createdCommands[$methodName] = $command; 26 28 } 27 protected function createCommand( PDO $pdo,ReflectionMethod $method){29 protected function createCommand(ReflectionMethod $method){ 28 30 $methodName = $method->getName(); 31 $pdo = HermitDataSourceManager::get($this->context->getTargetClass(), $methodName, HermitEvent::EVT_SETUP); 29 32 if($this->annote->isProcedureMethod($method)){ 30 33 return $this->createProcedureCommand($pdo, $method); … … 48 51 49 52 $command = new HermitProcedureCommand; 53 $command->setContext($this->context); 50 54 $command->setMethod($method); 51 55 $command->setSqlCreator($creator); … … 69 73 throw new BadMethodCallException('method: "' . $method->getName() . '" was not apply to Procedure command'); 70 74 } 71 protected function createInsertCommand(ReflectionMethod $method){ 72 throw new RuntimeException('T.B.D'); 75 protected function createInsertCommand(PDO $pdo, ReflectionMethod $method){ 76 $dbms = HermitDatabaseMetaFactory::getDbms($pdo); 77 $creator = $this->createInsertSqlCreator($method, $dbms); 78 $creator->initialize($pdo, $method, $this->annote); 79 $valueType = HermitValueTypeFactory::create($this->annote, $method); 80 $command = new HermitInsertCommand; 81 $command->setContext($this->context); 82 $command->setMethod($method); 83 $command->setSqlCreator($creator); 84 $command->setValueType($valueType); 85 return $command; 73 86 } 74 protected function createUpdateCommand(ReflectionMethod $method){ 75 throw new RuntimeException('T.B.D'); 87 protected function createInsertSqlCreator($method, $dbms){ 88 $sql = $this->annote->getSql($method, $dbms); 89 if(null !== $sql){ 90 return new HermitStaticSqlCreator($sql); 91 } 92 $sql = $this->annote->getFile($method, $dbms); 93 if(null !== $sql){ 94 return new HermitStaticSqlCreator($sql); 95 } 96 return new HermitAutoInsertSqlCreator; 76 97 } 77 protected function createDeleteCommand(ReflectionMethod $method){ 78 throw new RuntimeException('T.B.D'); 98 protected function createUpdateCommand(PDO $pdo, ReflectionMethod $method){ 99 $dbms = HermitDatabaseMetaFactory::getDbms($pdo); 100 $creator = $this->createUpdateSqlCreator($method, $dbms); 101 $creator->initialize($pdo, $method, $this->annote); 102 $valueType = HermitValueTypeFactory::create($this->annote, $method); 103 $command = new HermitUpdateCommand; 104 $command->setContext($this->context); 105 $command->setMethod($method); 106 $command->setSqlCreator($creator); 107 $command->setValueType($valueType); 108 return $command; 109 } 110 protected function createUpdateSqlCreator($method, $dbms){ 111 $sql = $this->annote->getSql($method, $dbms); 112 if(null !== $sql){ 113 return new HermitStaticSqlCreator($sql); 114 } 115 $sql = $this->annote->getFile($method, $dbms); 116 if(null !== $sql){ 117 return new HermitStaticSqlCreator($sql); 118 } 119 return new HermitAutoUpdateSqlCreator; 120 } 121 protected function createDeleteCommand(PDO $pdo, ReflectionMethod $method){ 122 $dbms = HermitDatabaseMetaFactory::getDbms($pdo); 123 $creator = $this->createDeleteSqlCreator($method, $dbms); 124 $creator->initialize($pdo, $method, $this->annote); 125 $valueType = HermitValueTypeFactory::create($this->annote, $method); 126 $command = new HermitDeleteCommand; 127 $command->setContext($this->context); 128 $command->setMethod($method); 129 $command->setSqlCreator($creator); 130 $command->setValueType($valueType); 131 return $command; 132 } 133 protected function createDeleteSqlCreator($method, $dbms){ 134 $sql = $this->annote->getSql($method, $dbms); 135 if(null !== $sql){ 136 return new HermitStaticSqlCreator($sql); 137 } 138 $sql = $this->annote->getFile($method, $dbms); 139 if(null !== $sql){ 140 return new HermitStaticSqlCreator($sql); 141 } 142 return new HermitAutoDeleteSqlCreator; 79 143 } 80 144 protected function createSelectCommand(PDO $pdo, ReflectionMethod $method){ … … 86 150 } 87 151 $valueType = HermitValueTypeFactory::create($this->annote, $method); 88 return new HermitSelectCommand($method, $creator, $valueType); 152 $command = new HermitSelectCommand; 153 $command->setContext($this->context); 154 $command->setMethod($method); 155 $command->setSqlCreator($creator); 156 $command->setValueType($valueType); 157 return $command; 89 158 } 90 159 protected function createSelectSqlCreator(ReflectionMethod $method, $dbms){ -
lang/php/misc/Hermit/src/Hermit/command/HermitUpdateCommand.php
r20200 r20966 4 4 * @author nowelium 5 5 */ 6 class HermitUpdateCommand implements HermitSqlCommand { 7 public function execute(PDO $pdo, array $params){ 6 class HermitUpdateCommand extends AbstractHermitSqlCommand { 7 public function execute(array $parameters){ 8 $pdo = $this->getConnection(HermitEvent::EVT_UPDATE); 9 $builder = new HermitStatementBuilder($this->method, $this->sqlCreator); 10 $stmt = $builder->build($pdo); 11 $stmt->execute($parameters); 12 $resultset = new HermitUpdateQueryResultSet; 13 return $resultset->execute($stmt, $this->type); 8 14 } 9 15 } -
lang/php/misc/Hermit/src/Hermit/proxy/HermitClassProxy.php
r20200 r20966 5 5 */ 6 6 class HermitClassProxy implements HermitFutureProxy { 7 private $context; 7 8 private $reflector; 8 protected function __construct(ReflectionClass $reflector){ 9 protected function __construct(HermitContext $ctx, ReflectionClass $reflector){ 10 $this->context = $ctx; 9 11 $this->reflector = $reflector; 10 12 } 11 public static function delegate( ReflectionClass $reflector, $instance = null){12 return new self($ reflector);13 public static function delegate(HermitContext $ctx, ReflectionClass $reflector, $instance = null){ 14 return new self($ctx, $reflector); 13 15 } 14 16 public function request($name, array $params){ 17 throw new RuntimeException('T.B.D'); 15 18 } 16 19 } -
lang/php/misc/Hermit/src/Hermit/proxy/HermitFutureProxy.php
r19682 r20966 5 5 */ 6 6 interface HermitFutureProxy extends HermitProxy { 7 public static function delegate( ReflectionClass $reflector, $instance = null);7 public static function delegate(HermitContext $ctx, ReflectionClass $reflector, $instance = null); 8 8 } -
lang/php/misc/Hermit/src/Hermit/proxy/HermitInterfaceProxy.php
r19426 r20966 5 5 */ 6 6 class HermitInterfaceProxy implements HermitFutureProxy { 7 protected $context; 7 8 protected $reflector; 8 9 protected $commandFactory; 9 protected function __construct(ReflectionClass $reflector){ 10 protected function __construct(HermitContext $ctx, ReflectionClass $reflector){ 11 $this->context = $ctx; 10 12 $this->reflector = $reflector; 11 $this->commandFactory = new HermitSqlCommandFactory($ reflector);13 $this->commandFactory = new HermitSqlCommandFactory($ctx, $reflector); 12 14 } 13 public static function delegate( ReflectionClass $reflector, $instance = null){14 return new self($ reflector);15 public static function delegate(HermitContext $ctx, ReflectionClass $reflector, $instance = null){ 16 return new self($ctx, $reflector); 15 17 } 16 18 public function request($name, array $params){ … … 18 20 throw new BadMethodCallException($this->reflector->getName() . '::' . $name); 19 21 } 20 $pdo = HermitDataSourceManager::get($this->reflector->getName()); 21 $command = $this->commandFactory->create($pdo, $name); 22 return $command->execute($pdo, $params); 22 $command = $this->commandFactory->create($this->context, $name); 23 return $command->execute($params); 23 24 } 24 25 } -
lang/php/misc/Hermit/src/Hermit/proxy/HermitObjectProxy.php
r19836 r20966 5 5 */ 6 6 class HermitObjectProxy implements HermitFutureProxy { 7 protected $context; 7 8 protected $target; 8 9 protected $annote; 9 protected function __construct(ReflectionClass $reflector, $target){ 10 protected function __construct(HermitContext $ctx, ReflectionClass $reflector, $target){ 11 $this->context = $ctx; 10 12 $this->target = $target; 11 13 $this->annote = HermitAnnote::create($reflector); 12 14 } 13 public static function delegate( ReflectionClass $reflector, $instance = null){14 return new self($ reflector, $instance);15 public static function delegate(HermitContext $ctx, ReflectionClass $reflector, $instance = null){ 16 return new self($ctx, $reflector, $instance); 15 17 } 16 18 public function request($name, array $params){
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)