BxDolMinify.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php defined('BX_DOL') or die('hack attempt');
  2. /**
  3. * Copyright (c) UNA, Inc - https://una.io
  4. * MIT License - https://opensource.org/licenses/MIT
  5. *
  6. * @defgroup UnaCore UNA Core
  7. * @{
  8. */
  9. use MatthiasMullie\Minify;
  10. class BxDolMinify extends BxDolFactory implements iBxDolSingleton
  11. {
  12. protected function __construct()
  13. {
  14. parent::__construct();
  15. }
  16. /**
  17. * Prevent cloning the instance
  18. */
  19. public function __clone()
  20. {
  21. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  22. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  23. }
  24. /**
  25. * Get singleton instance of the class
  26. */
  27. public static function getInstance()
  28. {
  29. if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
  30. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolMinify();
  31. return $GLOBALS['bxDolClasses'][__CLASS__];
  32. }
  33. public function minifyJs($s)
  34. {
  35. $oMinifier = new Minify\JS();
  36. $oMinifier->add($s);
  37. return $oMinifier->minify();
  38. }
  39. public function minifyCss($s)
  40. {
  41. $oMinifier = new Minify\CSS();
  42. $oMinifier->add($s);
  43. return $oMinifier->minify();
  44. }
  45. }
  46. /** @} */