- Timestamp:
- 09/16/08 01:32:33 (2 months ago)
- Location:
- lang/php/misc/Hermit/src/Hermit
- Files:
-
- 21 added
- 8 modified
-
Hermit.php (modified) (1 diff)
-
HermitAutoloader.php (modified) (2 diffs)
-
HermitDao.php (modified) (1 diff)
-
HermitDaoManager.php (added)
-
HermitDataSourceManager.php (added)
-
HermitListener.php (added)
-
HermitTransactionManager.php (added)
-
command/HermitSqlCommandFactory.php (modified) (2 diffs)
-
hoge.php (added)
-
proxy/HermitClassProxy.php (modified) (1 diff)
-
proxy/HermitFutureProxy.php (modified) (1 diff)
-
proxy/HermitInterfaceProxy.php (modified) (1 diff)
-
proxy/HermitProxy.php (modified) (1 diff)
-
responder (added)
-
responder/HermitResponder.php (added)
-
resultset (added)
-
resultset/HermitProcedureResultSet.php (added)
-
resultset/HermitResultSet.php (added)
-
statement (added)
-
statement/HermitStatement.php (added)
-
statement/HermitStatementBuilder.php (added)
-
tx (added)
-
tx/AbstractHermitTx.php (added)
-
tx/HermitMandatoryTx.php (added)
-
tx/HermitNeverTx.php (added)
-
tx/HermitRequiredTx.php (added)
-
tx/HermitRequiresNewTx.php (added)
-
tx/HermitTx.php (added)
-
tx/HermitTxRule.php (added)
Legend:
- Unmodified
- Added
- Removed
-
lang/php/misc/Hermit/src/Hermit/Hermit.php
r19017 r19344 4 4 * @author nowelium 5 5 */ 6 abstract class Hermit { 7 public static $classMap = array(); 8 public static function bind($targetClass, $dao){ 9 self::$classMap[$targetClass] = $dao; 6 class Hermit { 7 protected $listeners = array(); 8 protected $delegaters = array(); 9 10 public function __construct($class){ 11 $this->proxy = self::__create($class); 10 12 } 11 public static function create(PDO $pdo, $class = null){ 12 if(is_null($class)){ 13 $e = new Exception; 14 $trace = $e->getTrace(); 15 return Hermit::create($pdo, $trace[1]['class']); 13 public function __call($name, $parameters = array()){ 14 if(isset($this->delegater[$name])){ 15 return self::__request($this->delegater[$name], $name, $parameters); 16 16 } 17 return self::__request($this->proxy, $name, $parameters); 18 } 19 protected static function __request(Hermit $hermit, $name, array $params){ 20 return $hermit->request($name, $params); 21 } 22 protected static function __create($class){ 17 23 if(is_object($class)){ 18 return Hermit ClassProxy::delegate($pdo,new ReflectionObject($class), $class);24 return HermitObjectProxy::delegate(new ReflectionObject($class), $class); 19 25 } 20 26 if(isset(Hermit::$classMap[$class])){ 21 return self:: createProxy($pdo,Hermit::$classMap[$class]);27 return self::__createProxy(Hermit::$classMap[$class]); 22 28 } 23 29 if(class_exists($class)){ 24 return self:: create($pdo,$class);30 return self::__createProxy($class); 25 31 } 26 throw new InvalidArgumentException('nosuch class: ' . $class);32 throw new RuntimeException('Hermit does not create: ' . $class); 27 33 } 28 protected static function createProxy(PDO $pdo,$targetClass){34 protected static function __createProxy($targetClass){ 29 35 $reflector = new ReflectionClass($targetClass); 30 36 if($reflector->isInterface()){ 31 return HermitInterfaceProxy::delegate($ pdo, $reflector);37 return HermitInterfaceProxy::delegate($reflector); 32 38 } 33 return Hermit FutureProxy::delegate($pdo, $reflector, $targetClass);39 return HermitClassProxy::delegate($reflector); 34 40 } 35 41 } 42 -
lang/php/misc/Hermit/src/Hermit/HermitAutoloader.php
r19017 r19344 1 1 <?php 2 2 3 /** 4 * @author nowelium 5 */ 3 6 class HermitAutoloader { 4 7 private static $classPath = array( … … 9 12 '/meta', 10 13 '/creator', 11 '/command' 14 '/command', 15 '/statement', 16 '/resultset', 17 '/responder', 18 '/tx' 12 19 ); 13 20 private static $userClassPath = array(); -
lang/php/misc/Hermit/src/Hermit/HermitDao.php
r19017 r19344 2 2 3 3 /** 4 * @auth ronowelium4 * @author nowelium 5 5 */ 6 6 interface HermitDao { -
lang/php/misc/Hermit/src/Hermit/command/HermitSqlCommandFactory.php
r19017 r19344 1 1 <?php 2 2 3 /** 4 * @author nowelium 5 */ 3 6 class HermitSqlCommandFactory { 4 7 protected $annote; 5 8 protected $reflector; 6 protected $ hasCommand= array();9 protected $createdCommands = array(); 7 10 public function __construct(ReflectionClass $reflector){ 8 11 $this->annote = HermitAnnote::create($reflector); … … 13 16 } 14 17 public function getCommand($methodName){ 15 $command = new HermitSqlCommand; 16 17 return $command; 18 $method = $this->annote->getMethod($methodName); 19 $methodId = spl_object_hash($method); 20 if(isset($this->createdCommands[$methodId])){ 21 return $this->createdCommands[$methodId]; 22 } 23 $command = $this->createCommand($method); 24 return $this->createdCommands[$methodId] = $command; 25 } 26 protected function createCommand(ReflectionMethod $method){ 27 if($this->annote->isInsertMethod($methodName)){ 28 return $this->createInsertCommand($method); 29 } 30 if($this->annote->isUpdateMethod($methodName)){ 31 return $this->createUpdateCommand($method); 32 } 33 if($this->annote->isDeleteMethod($methodName)){ 34 return $this->createDeleteCommand($method); 35 } 36 return $this->createSelectCommand($method); 37 } 38 protected function createInsertCommand(ReflectionMethod $method){ 39 } 40 protected function createUpdateCommand(ReflectionMethod $method){ 41 } 42 protected function createSelectCommand(ReflectionMethod $method){ 43 $creator = $this->createSelectSqlCreator($method->getName()); 44 return new HermitSelectCommand($method, $creator); 45 } 46 protected function createSelectSqlCreator($name){ 47 switch(true){ 48 case $this->annote->hasSql($name): 49 return new HermitStaticSqlCreator($this->annote->getSql($name)); 50 case $this->annote->hasFile($name): 51 return new HermitStaticSqlCreator($this->annote->getFile($name)); 52 case $this->annote->hasPath($name): 53 return new HermitStaticSqlCreator($this->annote->getPath($name)); 54 case $this->annote->hasQuery($name): 55 $creator = new HermitAutoSelectCreator; 56 $creator->addQuery($this->annote->getQuery()); 57 return $creator; 58 } 59 throw new BadMethodCallException('invalid method:' . $name); 18 60 } 19 61 } -
lang/php/misc/Hermit/src/Hermit/proxy/HermitClassProxy.php
r19017 r19344 4 4 * @author nowelium 5 5 */ 6 class HermitClassProxy implements HermitDao { 7 protected $target; 8 protected $pdo; 9 protected function __construct(ReflectionClass $reflector, $targetClass, PDO $pdo = null){ 10 $this->target = $targetClass; 11 $this->reflector = $reflector; 12 $this->pdo = $pdo; 13 } 14 public static function delegate(PDO $pdo, ReflectionClass $reflector, $instance = null){ 15 return new self($reflector, $instance, $pdo); 16 } 17 public function __call($name, $params = array()){ 18 $annote = HermitAnnote::create($this->reflector); 19 if($annote->hasMethod($name, true)){ 20 $method = $annote->getMethod($name); 21 return $method->invokeArgs($this->target, $params); 22 } 23 throw new BadMethodCallException(get_class($this->target) . '::' . $name); 6 class HermitClassProxy implements HermitProxy { 7 public function request($name, array $params){ 24 8 } 25 9 } -
lang/php/misc/Hermit/src/Hermit/proxy/HermitFutureProxy.php
r19017 r19344 4 4 * @author nowelium 5 5 */ 6 class HermitFutureProxy implements HermitProxy { 7 public static function delegate(PDO $pdo, ReflectionClass $reflector, $target = null){ 8 } 6 interface HermitFutureProxy extends HermitProxy { 7 public static function delegate(PDO $pdo, ReflectionClass $reflector, $instance = null); 9 8 } -
lang/php/misc/Hermit/src/Hermit/proxy/HermitInterfaceProxy.php
r19017 r19344 4 4 * @author nowelium 5 5 */ 6 class HermitInterfaceProxy implements HermitProxy { 7 protected $pdo; 6 class HermitInterfaceProxy implements HermitFutureProxy { 8 7 protected $reflector; 9 protected function __construct(ReflectionClass $reflector, $pdo){ 8 protected $commandFactory; 9 protected function __construct(ReflectionClass $reflector){ 10 10 $this->reflector = $reflector; 11 $this-> pdo = $pdo;11 $this->commandFactory = new HermitSqlCommandFactory($reflector); 12 12 } 13 public static function delegate( PDO $pdo,ReflectionClass $reflector, $instance = null){14 return new self($reflector , $pdo);13 public static function delegate(ReflectionClass $reflector, $instance = null){ 14 return new self($reflector); 15 15 } 16 public function __call($name, $params = array()){ 17 $annote = HermitAnnote::create($this->reflector); 18 if(!$annote->hasMethod($name)){ 16 public function request($name, array $params){ 17 if(!$this->commandFactory->hasCommand($name)){ 19 18 throw new BadMethodCallException($this->reflector->getName() . '::' . $name); 20 19 } 21 22 $method = $annote->getMethod($name); 23 switch(true){ 24 case $annote->hasSql($name): 25 return $this->execute($method, $params, $annote->getSql($name)); 26 case $annote->hasQuery($name): 27 $sql = 'SELECT * FROM ' . $annote->getTable() . ' WHERE ' . $annote->getQuery($name); 28 return $this->execute($method, $params, $sql); 29 case $annote->hasFile($name): 30 return $this->execute($method, $params, $annote->getFile($name)); 31 case $annote->hasPath($name): 32 return $this->execute($method, $params, $annote->getPath($name)); 33 case $annote->hasDelegate($name); 34 break; 35 } 36 throw new BadMethodCallException($this->reflector->getName() . '::' . $name); 37 } 38 protected function execute(ReflectionMethod $method, $params, $sql){ 39 $stmt = HermitStatementBuilder::prepare($this->pdo, $method, $sql); 40 $stmt->execute($params); 41 return HermitResultSet::create($stmt, $method); 20 $command = $this->commandFactory->getCommand($name); 21 return $command->execute($pdo, $params); 42 22 } 43 23 } -
lang/php/misc/Hermit/src/Hermit/proxy/HermitProxy.php
r19017 r19344 5 5 */ 6 6 interface HermitProxy extends HermitDao { 7 public static function delegate(PDO $pdo, ReflectionClass $reflector, $instance = null);7 public function request($name, array $parameters); 8 8 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)