Show
Ignore:
Timestamp:
09/17/08 13:55:47 (4 months ago)
Author:
nowelium
Message:
 
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/php/misc/Hermit/src/Hermit/command/HermitSqlCommandFactory.php

    r19344 r19426  
    1212        $this->reflector = $reflector; 
    1313    } 
    14     public function hasCommand($methodName){ 
     14    public function has($methodName){ 
    1515        return $this->annote->hasMethod($methodName); 
    1616    } 
    17     public function getCommand($methodName){ 
     17    public function create(PDO $pdo, $methodName){ 
    1818        $method = $this->annote->getMethod($methodName); 
    1919        $methodId = spl_object_hash($method); 
     
    2525    } 
    2626    protected function createCommand(ReflectionMethod $method){ 
     27        $methodName = $method->getName(); 
     28        if($this->annote->isProcedureMethod($methodName)){ 
     29            return $this->createProcedureCommand($method); 
     30        } 
    2731        if($this->annote->isInsertMethod($methodName)){ 
    2832            return $this->createInsertCommand($method); 
     
    3640        return $this->createSelectCommand($method); 
    3741    } 
     42    protected function createProcedureCommand(ReflectionMethod $method){ 
     43        $creator = $this->createProcedureSqlCreator($method); 
     44        return new HermitProcedureCommand($method, $creator); 
     45    } 
     46    protected function createProcedureSqlCreator(ReflectionMethod $method){ 
     47        $sql = $this->annote->getProcedure($method); 
     48        if(null !== $sql){ 
     49            return new HermitStaticSqlCreator($sql); 
     50        } 
     51        $sql = $this->annote->getSql($method); 
     52        if(null !== $sql){ 
     53            return new HermitStaticSqlCreator($sql); 
     54        } 
     55        $sql = $this->annote->getFile($method); 
     56        if(null !== $sql){ 
     57            return new HermitStaticSqlCreator($sql); 
     58        } 
     59        throw new BadMethodCallException('method: "' . $method->getName() . '" was not apply to Procedure command'); 
     60    } 
    3861    protected function createInsertCommand(ReflectionMethod $method){ 
     62        throw new RuntimeException('T.B.D'); 
    3963    } 
    4064    protected function createUpdateCommand(ReflectionMethod $method){ 
     65        throw new RuntimeException('T.B.D'); 
     66    } 
     67    protected function createDeleteCommand(ReflectionMethod $method){ 
     68        throw new RuntimeException('T.B.D'); 
    4169    } 
    4270    protected function createSelectCommand(ReflectionMethod $method){ 
    43         $creator = $this->createSelectSqlCreator($method->getName()); 
     71        $creator = $this->createSelectSqlCreator($method); 
     72        $query = $this->annote->getQuery($method); 
     73        if(null !== $query){ 
     74            $creator->addQuery($query); 
     75        } 
    4476        return new HermitSelectCommand($method, $creator); 
    4577    } 
    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; 
     78    protected function createSelectSqlCreator(ReflectionMethod $method){ 
     79        $sql = $this->annote->getSql($method); 
     80        if(null !== $sql){ 
     81            return new HermitStaticSqlCreator($sql); 
    5882        } 
    59         throw new BadMethodCallException('invalid method:' . $name); 
     83        $sql = $this->annote->getFile($method); 
     84        if(null !== $sql){ 
     85            return new HermitStaticSqlCreator($sql); 
     86        } 
     87        return new HermitAutoSelectCreator; 
    6088    } 
    6189} 
     90