| 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); |