-
Notifications
You must be signed in to change notification settings - Fork 9
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
Bug fixation of ODM\MongoDB\Types\CurrencyType #21
Conversation
olekhy
commented
May 18, 2015
- shouldn't use stringtype
* shouldn't use stringtype
@olekhy why? Currency actually implements __toString(). |
I definitly expect a currency object returned and not a string. Second argument for Money constructor is a Currency instance, not any string is allowed. A currency type returning a string (that is not a currency) is pointless. |
@danizord
after on /**
* @return \Money\Currency
*/
public function getCurrency()
{ var_dump(gettype($this->currency));
return $this->currency;
} when calling in: class MoneyHydrator implements HydratorInterface
{
/**
* {@inheritDoc}
*/
public function extract($object)
{ var_dump(gettype($object->getCurrency())); die;
return [
'amount' => $object->getAmount(),
'currency' => $object->getCurrency()->getName()
];
} output: string 'string' (length=6) string 'string' (length=6) |
👏 wakeup here we needed a worked module... or w'll use my branch for composer installation. ;) temporary. |
Fixation bug currency type
Fixed money hydrator
* at mongo persistence should nor a instance only string
@olekhy Sorry for the delay. Ill review that ASAP. |
@fabiocarneiro Thank you, we will gladly wait for. |
@@ -22,4 +31,9 @@ public function convertToPHPValue($value) | |||
|
|||
return new Currency($value); | |||
} | |||
|
|||
public function closureToPHP() |
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.
@olekhy Can you explain the purpose of this method? I'm not familiarized with this conversion.
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.
As we already discussed in #22. There is no reason to the conversion to be done in the Hydrator and it would also break BC. If you want to properly display it in you form and it's not working, you should do a Form View Helper instead. |
use Money\Currency; | ||
|
||
class CurrencyType extends StringType | ||
class CurrencyType extends Type |
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.
Can you revert this one? We still can inherit convertToDatabaseValue()
and closureToMongo()
from StringType
since Currency
implements __toString()
method.
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.
sry no, this is an falsely behavior Currency isn't a string type, BTW doctrine2 and proxy manager (we used) doesn't automatically cast to string. Not useabale with u proposed __toString
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.
Well, in DB side it is a string, so I think it's ok to inherit VO -> string conversions from StringType
. Just a suggestion, though. Result still the same :)
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.
almost all data mapped to string on database side, is more interesting PHP side. because we speak from ODM (ORM) here. Look at times http://doctrine-dbal.readthedocs.org/en/lates/reference/types.html#custom-mapping-types for u should be a float type :). (may better way ObjectType -> serializing of money inclusive currency as one field)
@danizord @fabiocarneiro i'll close my pr's and hope u implements:
ok so? |
@danizord yeah. Currency type I'll make a separate PR. |