Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
package
money
Commits
6143c8b9
Commit
6143c8b9
authored
Apr 22, 2015
by
bussnet
Browse files
Merge pull request #1 from Petah/patch-1
Added some validation and sanity checks to CurrencyLookupRubyMoney
parents
dac8c3e4
9a3150e9
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/Money/CurrencyLookupRubyMoney.php
View file @
6143c8b9
...
...
@@ -29,15 +29,31 @@ class CurrencyLookupRubyMoney implements CurrencyLookup {
function
__construct
(
$file
=
null
,
$cache_dir
=
'/tmp/'
)
{
$file
=
$file
?
:
self
::
CURRENCY_FILE
;
// read from cache
if
(
file_exists
(
$cache_dir
.
'/'
.
basename
(
$file
)))
$file
=
$cache_dir
.
'/'
.
basename
(
$file
);
// try and read from cache
$cache_file
=
$cache_dir
.
'/'
.
basename
(
$file
);
if
(
file_exists
(
$cache_file
))
{
$content
=
file_get_contents
(
$cache_file
);
if
(
$content
)
{
$this
->
currencies
=
json_decode
(
$content
,
true
);
if
(
$this
->
currencies
)
{
return
;
}
}
}
$this
->
currencies
=
json_decode
(
file_get_contents
(
$file
),
true
);
// try and read from server
$content
=
file_get_contents
(
$file
);
if
(
!
$content
)
{
throw
new
\
Exception
(
'Could not read currencies file from cache or server.'
);
}
$this
->
currencies
=
json_decode
(
$content
,
true
);
if
(
!
$this
->
currencies
)
{
throw
new
\
Exception
(
'Could decode currencies file from server.'
);
}
// write to cache
if
(
$cache_dir
&&
file_exists
(
$cache_dir
))
{
file_put_contents
(
$cache_
dir
.
'/'
.
basename
(
$
file
)
,
file_get_contents
(
$file
)
);
if
(
$cache_dir
&&
is_dir
(
$cache_dir
))
{
file_put_contents
(
$cache_file
,
$content
);
}
}
...
...
@@ -52,4 +68,4 @@ class CurrencyLookupRubyMoney implements CurrencyLookup {
throw
new
UnknownCurrencyException
(
sprintf
(
'currency with iso-code %s not found'
,
$iso_code
));
}
}
\ No newline at end of file
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment