BxDolMinify.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. require_once(BX_DIRECTORY_PATH_PLUGINS . 'matthiasmullie/path-converter/ConverterInterface.php');
  11. require_once(BX_DIRECTORY_PATH_PLUGINS . 'matthiasmullie/path-converter/Converter.php');
  12. require_once(BX_DIRECTORY_PATH_PLUGINS . 'matthiasmullie/minify/Minify.php');
  13. require_once(BX_DIRECTORY_PATH_PLUGINS . 'matthiasmullie/minify/CSS.php');
  14. require_once(BX_DIRECTORY_PATH_PLUGINS . 'matthiasmullie/minify/JS.php');
  15. class BxDolMinify extends BxDolFactory implements iBxDolSingleton
  16. {
  17. protected function __construct()
  18. {
  19. parent::__construct();
  20. }
  21. /**
  22. * Prevent cloning the instance
  23. */
  24. public function __clone()
  25. {
  26. if (isset($GLOBALS['bxDolClasses'][get_class($this)]))
  27. trigger_error('Clone is not allowed for the class: ' . get_class($this), E_USER_ERROR);
  28. }
  29. /**
  30. * Get singleton instance of the class
  31. */
  32. public static function getInstance()
  33. {
  34. if(!isset($GLOBALS['bxDolClasses'][__CLASS__]))
  35. $GLOBALS['bxDolClasses'][__CLASS__] = new BxDolMinify();
  36. return $GLOBALS['bxDolClasses'][__CLASS__];
  37. }
  38. public function minifyJs($s)
  39. {
  40. $oMinifier = new Minify\JS();
  41. $oMinifier->add($s);
  42. return $oMinifier->minify();
  43. }
  44. public function minifyCss($s)
  45. {
  46. $oMinifier = new Minify\CSS();
  47. $oMinifier->add($s);
  48. return $oMinifier->minify();
  49. }
  50. }
  51. /** @} */