本文整理汇总了PHP中Money\Money::stringToUnits方法的典型用法代码示例。如果您正苦于以下问题:PHP Money::stringToUnits方法的具体用法?PHP Money::stringToUnits怎么用?PHP Money::stringToUnits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Money\Money
的用法示例。
在下文中一共展示了Money::stringToUnits方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filter
/**
* {@inheritdoc}
*
* @throws InvalidArgumentException
*
* @return int|null
*/
public function filter($value)
{
if (null === $value || is_string($value) && strlen($value) === 0) {
return null;
}
return Money::stringToUnits($value);
}
示例2: addEntriesToStatement
/**
* @param SimpleXMLElement $statementXml
* @param Statement $statement
*/
private function addEntriesToStatement(SimpleXMLElement $statementXml, Statement $statement)
{
$index = 0;
$entriesXml = $statementXml->Ntry;
foreach ($entriesXml as $entryXml) {
$amount = Money::stringToUnits((string) $entryXml->Amt);
$currency = (string) $entryXml->Amt['Ccy'];
$bookingDate = (string) $entryXml->BookgDt->Dt;
$valueDate = (string) $entryXml->ValDt->Dt;
if ((string) $entryXml->CdtDbtInd === 'DBIT') {
$amount = $amount * -1;
}
$entry = new Entry($statement, $index, new Money($amount, new Currency($currency)), new DateTimeImmutable($bookingDate), new DateTimeImmutable($valueDate));
if (isset($entryXml->RvslInd) && (string) $entryXml->RvslInd === 'true') {
$entry->setReversalIndicator(true);
}
if (isset($entryXml->NtryRef) && (string) $entryXml->NtryRef) {
$entry->setReference((string) $entryXml->NtryRef);
}
if (isset($entryXml->NtryDtls->Btch->PmtInfId) && (string) $entryXml->NtryDtls->Btch->PmtInfId) {
$entry->setBatchPaymentId((string) $entryXml->NtryDtls->Btch->PmtInfId);
}
$this->addTransactionDetailsToEntry($entryXml, $entry);
$statement->addEntry($entry);
$index++;
}
}
示例3: convert
/**
* @param \Money\Money|string $amount
* @param \Money\Currency|string $from
* @param \Money\Currency|string $to
* @return \Money\Money
*/
public function convert($amount, $from, $to)
{
if ($from instanceof Currency == false) {
$from = new Currency(strtoupper($from));
}
if ($to instanceof Currency == false) {
$to = new Currency(strtoupper($to));
}
if ($amount instanceof Money == false) {
$money = new Money(Money::stringToUnits($amount), $from);
} else {
$money = $amount;
}
$pair = $this->fetchCached($from, $to);
if ($pair == null) {
$pair = $this->provider->getCurrencyPair($from, $to);
$this->saveCached($pair);
}
$converted = $pair->convert($money);
return $converted;
}
示例4: testStringToUnits
/**
* @dataProvider provideStrings
*/
public function testStringToUnits($string, $units)
{
$this->assertEquals($units, Money::stringToUnits($string));
}
示例5: testInvalidStringToUnit
/**
* @expectedException \Money\InvalidArgumentException
*/
public function testInvalidStringToUnit()
{
Money::stringToUnits('This should be an invalid string');
}
示例6: testStringToUnits
public function testStringToUnits()
{
foreach ($this->moneystrings() as $array) {
$this->assertEquals($array[1], Money::stringToUnits($array[0]));
}
}
示例7: testInvalidStringToUnits
/**
* @expectedException InvalidArgumentException
*/
public function testInvalidStringToUnits()
{
Money::stringToUnits('invalid units');
}