-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix setter value type with prado tpl/Page #837
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
|
||
use Prado\Prado; | ||
use Prado\TComponent; | ||
use Prado\TPropertyValue; | ||
use Prado\Web\Javascripts\TJavaScriptLiteral; | ||
use Prado\Exceptions\TConfigurationException; | ||
use Prado\Exceptions\TException; | ||
|
@@ -441,6 +442,32 @@ protected function configureProperty($component, $name, $value) | |
} | ||
} | ||
$setter = 'set' . $name; | ||
if (method_exists($component, $setter)) { | ||
if ($reflector = new \ReflectionClass($component)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The setter/property may not be in the component but in a behavior modifying the component. looping through each behavior would be needed too but that requires #826. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looping all the behaviors from here sounds time expensive (but can be fixed with some caching) but also a bit incorrect from an OOP point of view. |
||
try { | ||
$params = $reflector->getMethod($setter)->getParameters(); | ||
if ( | ||
!empty($params) && | ||
isset($params[0]) && | ||
!empty($params[0]->getType()) && | ||
$params[0]->getType() instanceof \ReflectionNamedType | ||
) { | ||
switch ($params[0]->getType()->getName()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. between getting the "new reflectionclass()" and this type-name, caching the class/property/type into a static would greatly speed things up. |
||
case 'bool': | ||
$value = TPropertyValue::ensureBoolean($value); | ||
break; | ||
case 'int': | ||
$value = TPropertyValue::ensureInteger($value); | ||
break; | ||
case 'float': | ||
$value = TPropertyValue::ensureFloat($value); | ||
break; | ||
} | ||
ctrlaltca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} catch (\ReflectionException $e) { | ||
} | ||
} | ||
} | ||
$component->$setter($value); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be updated to be behavior aware with #825
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this going to be $component->hasMethod($setter)