/class/file/xoopsfile.php

https://gitlab.com/VoyaTrax/vtCMS2 · PHP · 113 lines · 56 code · 9 blank · 48 comment · 11 complexity · 5c9400fd133616b99dd17ae515883fe8 MD5 · raw file

  1. <?php
  2. /**
  3. * File factory For XOOPS
  4. *
  5. * You may not change or alter any portion of this comment or credits
  6. * of supporting developers from this source code or any supporting source code
  7. * which is considered copyrighted (c) material of the original comment or credit authors.
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * @copyright (c) 2000-2016 XOOPS Project (www.xoops.org)
  13. * @license GNU GPL 2 (http://www.gnu.org/licenses/gpl-2.0.html)
  14. * @package class
  15. * @subpackage file
  16. * @since 2.3.0
  17. * @author Taiwen Jiang <phppp@users.sourceforge.net>
  18. */
  19. defined('XOOPS_ROOT_PATH') || exit('Restricted access');
  20. /**
  21. * XoopsFile
  22. *
  23. * @package
  24. * @author Taiwen Jiang <phppp@users.sourceforge.net>
  25. * @access public
  26. */
  27. class XoopsFile
  28. {
  29. /**
  30. * XoopsFile::__construct()
  31. */
  32. public function __construct()
  33. {
  34. }
  35. /**
  36. * XoopsFile::getInstance()
  37. *
  38. * @return
  39. */
  40. public function getInstance()
  41. {
  42. static $instance;
  43. if (!isset($instance)) {
  44. $class = __CLASS__;
  45. $instance = new $class();
  46. }
  47. return $instance;
  48. }
  49. /**
  50. * XoopsFile::load()
  51. *
  52. * @param string $name
  53. *
  54. * @return bool
  55. */
  56. public static function load($name = 'file')
  57. {
  58. switch ($name) {
  59. case 'folder':
  60. if (!class_exists('XoopsFolderHandler')) {
  61. if (file_exists($folder = __DIR__ . '/folder.php')) {
  62. include $folder;
  63. } else {
  64. trigger_error('Require Item : ' . str_replace(XOOPS_ROOT_PATH, '', $folder) . ' In File ' . __FILE__ . ' at Line ' . __LINE__, E_USER_WARNING);
  65. return false;
  66. }
  67. }
  68. break;
  69. case 'file':
  70. default:
  71. if (!class_exists('XoopsFileHandler')) {
  72. if (file_exists($file = __DIR__ . '/file.php')) {
  73. include $file;
  74. } else {
  75. trigger_error('Require File : ' . str_replace(XOOPS_ROOT_PATH, '', $file) . ' In File ' . __FILE__ . ' at Line ' . __LINE__, E_USER_WARNING);
  76. return false;
  77. }
  78. }
  79. break;
  80. }
  81. return true;
  82. }
  83. /**
  84. * XoopsFile::getHandler()
  85. *
  86. * @param string $name
  87. * @param mixed $path
  88. * @param mixed $create
  89. * @param mixed $mode
  90. * @return
  91. */
  92. public static function getHandler($name = 'file', $path = false, $create = false, $mode = null)
  93. {
  94. $handler = null;
  95. XoopsFile::load($name);
  96. $class = 'Xoops' . ucfirst($name) . 'Handler';
  97. if (class_exists($class)) {
  98. $handler = new $class($path, $create, $mode);
  99. } else {
  100. trigger_error('Class ' . $class . ' not exist in File ' . __FILE__ . ' at Line ' . __LINE__, E_USER_WARNING);
  101. }
  102. return $handler;
  103. }
  104. }