1: <?php
2: /*
3: You may not change or alter any portion of this comment or credits
4: of supporting developers from this source code or any supporting source code
5: which is considered copyrighted (c) material of the original comment or credit authors.
6:
7: This program is distributed in the hope that it will be useful,
8: but WITHOUT ANY WARRANTY; without even the implied warranty of
9: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10: */
11:
12: /**
13: * XoopsFile
14: *
15: * File factory For XOOPS
16: *
17: * PHP 5.3
18: *
19: * @category Xoops\Class\Cache\CacheApc
20: * @package CacheApc
21: * @author Taiwen Jiang <phppp@users.sourceforge.net>
22: * @copyright 2013 XOOPS Project (http://xoops.org)
23: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
24: * @version $Id$
25: * @link http://xoops.org
26: * @since 2.6.0
27: */
28: class XoopsFile
29: {
30: /**
31: * XoopsFile::getHandler()
32: *
33: * @param string $name name of file
34: * @param string $path path file is in
35: * @param boolean $create create file if needed
36: * @param integer $mode mode on file created
37: *
38: * @return XoopsFileHandler|XoopsFolderHandler|bool
39: */
40: public static function getHandler($name = 'file', $path = false, $create = false, $mode = null)
41: {
42: $handler = null;
43: $name = strtolower(trim($name));
44: $class = 'Xoops' . ucfirst($name) . 'Handler';
45: if (in_array($name, array('file', 'folder'))) {
46: $handler = new $class($path, $create, $mode);
47: } else {
48: trigger_error(
49: 'Class ' . $class . ' not exist in File ' . __FILE__ . ' at Line ' . __LINE__,
50: E_USER_WARNING
51: );
52: return false;
53: }
54: return $handler;
55: }
56: }
57: