I think purists argue that if you do currency conversions in your controller code, you are probably doing something wrong, as there should be no business logic there. However, sometimes practical considerations outweigh the problems of purism. Suppose this is one such case. :-)
If your currency class is a fairly simple utility type class, I would tend to create a new directory under "application" called "utils", and then add this directory to the resource loader in the boot application:
protected function _initResourceLoader() { $this->_resourceLoader->addResourceType( 'utility', 'utils', 'Utility' ); }
Then you can create a class called Application_Utility_Currency stored in a file called Currency.php in this directory and call static methods such as:
Application_Utilility_Currency::convert( $from_currency, $to_currency, $amount );
This approach would be especially useful if you had other utility classes that were also looking for a home.
However, if your currency class contains richer functionalities (for example, connecting to external services to receive exchange rate data, etc.), then IMO would be better to consider it as a βServiceβ rather than a βUtilityβ, My definition is β the model is rather weak and includes all the services related to the data, regardless of whether this data is in the application database or elsewhere, therefore, if the class has a more complex variety, I will simply bind it to another model.
source share