- Timestamp:
- 09/09/08 00:44:36 (2 months ago)
- Location:
- lang/php/misc/Hermit
- Files:
-
- 13 added
- 7 modified
-
example/employee/hoge.php (modified) (2 diffs)
-
example/example.php (added)
-
src/Hermit/Hermit.php (modified) (3 diffs)
-
src/Hermit/HermitAutoloader.php (modified) (1 diff)
-
src/Hermit/HermitDao.php (modified) (1 diff)
-
src/Hermit/HermitStatementBuilder.php (added)
-
src/Hermit/command (added)
-
src/Hermit/command/HermitSqlCommand.php (added)
-
src/Hermit/command/HermitSqlCommandFactory.php (added)
-
src/Hermit/creator (added)
-
src/Hermit/creator/HermitAnnotationSqlCreator.php (added)
-
src/Hermit/creator/HermitAutoInsertSqlCreator.php (added)
-
src/Hermit/creator/HermitAutoSelectSqlCreator.php (added)
-
src/Hermit/creator/HermitAutoUpdateSqlCreator.php (added)
-
src/Hermit/creator/HermitSqlCreator.php (added)
-
src/Hermit/meta (added)
-
src/Hermit/proxy/HermitClassProxy.php (added)
-
src/Hermit/proxy/HermitFutureProxy.php (modified) (1 diff)
-
src/Hermit/proxy/HermitInterfaceProxy.php (modified) (4 diffs)
-
src/Hermit/proxy/HermitProxy.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/php/misc/Hermit/example/employee/hoge.php
r18987 r19017 2 2 3 3 require dirname(__FILE__) . '/../example.php'; 4 HermitAutoloader::import(dirname(__FILE__)); 5 HermitAutoloader::import(dirname(__FILE__) . '/dao'); 4 6 5 7 class Hoge { … … 16 18 } 17 19 20 Hermit::bind('Hoge', 'EmployeeDao'); 18 21 $pdo = new PDO('sqlite:' . dirname(__FILE__) . '/resource/employee.db'); 19 22 $hoge = new Hoge; -
lang/php/misc/Hermit/src/Hermit/Hermit.php
r18988 r19017 4 4 * @author nowelium 5 5 */ 6 class Hermit { 7 public static $classMap = array( 8 'Hoge' => 'EmployeeDao' 9 ); 6 abstract class Hermit { 7 public static $classMap = array(); 8 public static function bind($targetClass, $dao){ 9 self::$classMap[$targetClass] = $dao; 10 } 10 11 public static function create(PDO $pdo, $class = null){ 11 12 if(is_null($class)){ … … 15 16 } 16 17 if(is_object($class)){ 17 return Hermit Proxy::delegateInstance($pdo, $class);18 return HermitClassProxy::delegate($pdo, new ReflectionObject($class), $class); 18 19 } 19 20 if(isset(Hermit::$classMap[$class])){ … … 27 28 protected static function createProxy(PDO $pdo, $targetClass){ 28 29 $reflector = new ReflectionClass($targetClass); 29 /*30 if($reflector->implementsInterface('HermitDao')){31 $instance = $reflector->newInstance();32 $instance->setPDO($pdo);33 return HermitProxy::delegateInstance($pdo, $instance);34 }35 */36 30 if($reflector->isInterface()){ 37 31 return HermitInterfaceProxy::delegate($pdo, $reflector); 38 32 } 39 return HermitFutureProxy::delegate($pdo, $ targetClass);33 return HermitFutureProxy::delegate($pdo, $reflector, $targetClass); 40 34 } 41 35 } -
lang/php/misc/Hermit/src/Hermit/HermitAutoloader.php
r18988 r19017 2 2 3 3 class HermitAutoloader { 4 private static $classPath = array( 5 '/', 6 '/annote', 7 '/parameter', 8 '/proxy', 9 '/meta', 10 '/creator', 11 '/command' 12 ); 13 private static $userClassPath = array(); 14 private static $unmatch = array(); 15 private static $current; 16 public static function initialize(){ 17 self::$current = dirname(__FILE__); 18 spl_autoload_register(array(__CLASS__, 'autoload')); 19 } 20 public static function import($dir){ 21 self::$userClassPath[] = $dir; 22 } 23 public static function autoload($className){ 24 if(self::classload(self::$classPath, $className, self::$current)){ 25 return true; 26 } 27 if(self::classload(self::$userClassPath, $className)){ 28 return true; 29 } 30 return false; 31 } 32 protected static function classload(array $pathes, $className, $prefix = ''){ 33 $file = $className . '.php'; 34 foreach($pathes as $path){ 35 $filePath = $prefix . $path . DIRECTORY_SEPARATOR . $file; 36 if(isset(self::$unmatch[$filePath]) && self::$unmatch[$filePath]){ 37 continue; 38 } 39 if(file_exists($filePath)){ 40 require $filePath; 41 return true; 42 } 43 self::$unmatch[$filePath] = true; 44 } 45 return false; 46 } 4 47 } 48 49 HermitAutoloader::initialize(); -
lang/php/misc/Hermit/src/Hermit/HermitDao.php
r18988 r19017 5 5 */ 6 6 interface HermitDao { 7 public function setPDO(PDO $pdo);8 7 } -
lang/php/misc/Hermit/src/Hermit/proxy/HermitFutureProxy.php
r18954 r19017 4 4 * @author nowelium 5 5 */ 6 class HermitFutureProxy { 7 protected $pdo; 8 protected $target; 9 public static function delegate(PDO $pdo, $target){ 10 $this->pdo = $pdo; 11 $this->target = $target; 6 class HermitFutureProxy implements HermitProxy { 7 public static function delegate(PDO $pdo, ReflectionClass $reflector, $target = null){ 12 8 } 13 9 } -
lang/php/misc/Hermit/src/Hermit/proxy/HermitInterfaceProxy.php
r18954 r19017 4 4 * @author nowelium 5 5 */ 6 class HermitInterfaceProxy {6 class HermitInterfaceProxy implements HermitProxy { 7 7 protected $pdo; 8 8 protected $reflector; … … 11 11 $this->pdo = $pdo; 12 12 } 13 public static function delegate(PDO $pdo, ReflectionClass $reflector ){13 public static function delegate(PDO $pdo, ReflectionClass $reflector, $instance = null){ 14 14 return new self($reflector, $pdo); 15 15 } … … 23 23 switch(true){ 24 24 case $annote->hasSql($name): 25 return $this->execute($method, $ annote->getSql($name));25 return $this->execute($method, $params, $annote->getSql($name)); 26 26 case $annote->hasQuery($name): 27 27 $sql = 'SELECT * FROM ' . $annote->getTable() . ' WHERE ' . $annote->getQuery($name); 28 return $this->execute($method, $ sql);28 return $this->execute($method, $params, $sql); 29 29 case $annote->hasFile($name): 30 return $this->execute($method, $ annote->getFile($name));30 return $this->execute($method, $params, $annote->getFile($name)); 31 31 case $annote->hasPath($name): 32 return $this->execute($method, $ annote->getPath($name));32 return $this->execute($method, $params, $annote->getPath($name)); 33 33 case $annote->hasDelegate($name); 34 34 break; … … 36 36 throw new BadMethodCallException($this->reflector->getName() . '::' . $name); 37 37 } 38 protected static function execute(ReflectionMethod $method, $sql){39 $stmt = HermitS qlBuilder::prepare($this->pdo, $method, $sql);38 protected function execute(ReflectionMethod $method, $params, $sql){ 39 $stmt = HermitStatementBuilder::prepare($this->pdo, $method, $sql); 40 40 $stmt->execute($params); 41 41 return HermitResultSet::create($stmt, $method); -
lang/php/misc/Hermit/src/Hermit/proxy/HermitProxy.php
r18954 r19017 4 4 * @author nowelium 5 5 */ 6 class HermitProxy { 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 delegateInstance(PDO $pdo, $instance){ 15 return new self(new ReflectionObject($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 switch(true){ 24 case $annote->hasSql($name): 25 break; 26 case $annote->hasQuery($name): 27 break; 28 case $annote->hasFile($name): 29 break; 30 case $annote->hasPath($name): 31 break; 32 case $annote->hasDelegate($name): 33 break; 34 } 35 throw new BadMethodCallException(get_class($this->target) . '::' . $name); 36 } 6 interface HermitProxy extends HermitDao { 7 public static function delegate(PDO $pdo, ReflectionClass $reflector, $instance = null); 37 8 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)