Skip to content

Commit 8802c70

Browse files
committed
Support abstract methods
1 parent 31d1a0a commit 8802c70

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

.idea/dbpp.iml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dbpp/Dao.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,15 @@ final public function __call(string $name, array $arguments) {
2323
$response = false;
2424
try {
2525
$method = $this->class->getMethod($name);
26+
if($method->getPrototype()->isAbstract())
27+
$method = $method->getPrototype();
28+
2629
foreach($method->getAttributes() as $attribute){
2730
if(class_exists($attribute->getName())){
2831
$attribute = $attribute->newInstance();
2932
if($attribute instanceof Query) {
3033
$args = [];
34+
3135
for($i = 0, $iMax = count($arguments); $i < $iMax; $i++) {
3236
$args[$method->getParameters()[$i]->getName()] = $arguments[$i];
3337
}
@@ -38,9 +42,8 @@ final public function __call(string $name, array $arguments) {
3842
}
3943
}
4044

41-
return Utils::getValueByType($method->getReturnType(), $response);
4245
} catch (ReflectionException) {}
4346

44-
return $response;
47+
return Utils::getValueByType($method->getReturnType(), $response);
4548
}
4649
}

src/dbpp/Database.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ private function createDao(PDO $pdo, ReflectionClass $class): Dao {
3838
$argsDefArray = [];
3939
foreach ($method->getParameters() as $parameter) {
4040
$argsDef[] = ($parameter->getType() ?: "") . "$" .$parameter->name;
41-
$argsDefArray[] = "\"$parameter->name\"=>\$$parameter->name";
41+
$argsDefArray[] = "\$$parameter->name";
4242
}
4343

44+
4445
$classDef .= "public function $method->name(".implode(",", $argsDef)."):{$method->getReturnType()}{".
4546
"return \$this->__call(\"$method->name\", [".implode(",", $argsDefArray)."]);}";
4647
}

0 commit comments

Comments
 (0)