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: * This program is distributed in the hope that it will be useful,
7: * but WITHOUT ANY WARRANTY; without even the implied warranty of
8: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9: */
10:
11: namespace Xoops\Core\Handler\Scheme;
12:
13: use Xoops\Core\Exception\NoHandlerException;
14: use Xoops\Core\Handler\FactorySpec;
15: use Xoops\Core\Kernel\XoopsObjectHandler;
16:
17:
18: /**
19: * LegacyModule - build a handler using legacy module rules
20: *
21: * @category Xoops\Core\Handler\Scheme
22: * @package Xoops\Core
23: * @author Richard Griffith <richard@geekwright.com>
24: * @copyright 2015 XOOPS Project (http://xoops.org)
25: * @license GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
26: * @link http://xoops.org
27: */
28: class LegacyModule implements SchemeInterface
29: {
30: /**
31: * build a module handler for legacy module
32: *
33: * @param FactorySpec $spec specification for requested handler
34: *
35: * @return XoopsObjectHandler|null
36: */
37: public function build(FactorySpec $spec)
38: {
39: $handler = null;
40: $name = strtolower($spec->getName());
41: $dirname = strtolower($spec->getDirname());
42:
43: $handlerFile = \XoopsBaseConfig::get('root-path') . "/modules/{$dirname}/class/{$name}.php";
44: if (\XoopsLoad::fileExists($handlerFile)) {
45: include_once $handlerFile;
46: }
47: $class = ucfirst($dirname) . ucfirst($name) . 'Handler';
48: if (class_exists($class, false)) {
49: $handler = new $class($spec->getFactory()->db());
50: }
51: if ($handler === null) {
52: if (false === $spec->getOptional()) {
53: throw new NoHandlerException(sprintf('Class not found %s', $class));
54: }
55: }
56: return $handler;
57: }
58: }
59: