PageRenderTime 37ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Varien/Filter/Sprintf.php

https://bitbucket.org/andrewjleavitt/magestudy
PHP | 51 lines | 23 code | 4 blank | 24 comment | 1 complexity | 0dd85ddc3d4b737d7cc6308afc12db18 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, GPL-2.0, WTFPL
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Varien
  22. * @package Varien_Filter
  23. * @copyright Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. class Varien_Filter_Sprintf implements Zend_Filter_Interface
  27. {
  28. protected $_format = null;
  29. protected $_decimals = null;
  30. protected $_decPoint = null;
  31. protected $_thousandsSep = null;
  32. public function __construct($format, $decimals=null, $decPoint='.', $thousandsSep=',')
  33. {
  34. $this->_format = $format;
  35. $this->_decimals = $decimals;
  36. $this->_decPoint = $decPoint;
  37. $this->_thousandsSep = $thousandsSep;
  38. }
  39. public function filter($value)
  40. {
  41. if (!is_null($this->_decimals)) {
  42. $value = number_format($value, $this->_decimals, $this->_decPoint, $this->_thousandsSep);
  43. }
  44. $value = sprintf($this->_format, $value);
  45. return $value;
  46. }
  47. }