Improvements to WPSC_Country
A few things here on my mind:
- Currently, our unit tests are failing, I believe it is specifically because it relies on the database existing and being populated with countries. We should have a better country registration mechanism. This registry should populate the database and be used as our test mocks.
- Currently, we have the two-letter ISOCODE for countries, but not the three-letter ISOCODE. Some APIs (Like ProPay) require the three letter code.
I'm curious, what is the benefit/reasoning to have the countries in the database vs in-memory?
Good question!
Couldn't speak to the reasoning (decision was made ~2006). It's not a terrible amount of memory it would take.
The file that has all the data is ~66Kb for about 250 entries.
The following (quick+dirty) memory check shows ~17Kb/WPSC_Country object.
$start = memory_get_usage();
$us = new WPSC_Country( 'US' );
var_dump( $us->get_name() );
var_dump( $us->get_id() );
$end = memory_get_usage();
var_dump( ( $end - $start ) / 1024 );
That reflects about .31Kb per object, so maybe 75-80Kb of memory.
To that point - there's basically no reason to keep it in the DB for core usage. That said, for back compat, we'd always have to have it there, even if we stopped using it as the core storage mechanism.