1: <?php
2: 3: 4: 5: 6: 7: 8: 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: 20: 21: 22: 23: 24: 25: 26: 27:
28: class Kernel implements SchemeInterface
29: {
30: private $lookupTable = [
31: 'block' => 'Block',
32: 'blockmodulelink' => 'BlockModuleLink',
33: 'config' => 'Config',
34: 'configitem' => 'ConfigItem',
35: 'configoption' => 'ConfigOption',
36: 'group' => 'Group',
37: 'groupperm' => 'GroupPerm',
38: 'member' => 'Member',
39: 'membership' => 'Membership',
40: 'module' => 'Module',
41: 'online' => 'Online',
42: 'privmessage' => 'PrivateMessage',
43: 'ranks' => 'Ranks',
44: 'tplfile' => 'TplFile',
45: 'tplset' => 'TplSet',
46: 'user' => 'User',
47: ];
48:
49: 50: 51: 52: 53: 54: 55:
56: public function build(FactorySpec $spec)
57: {
58: $handler = null;
59: $specName = strtolower($spec->getName());
60: if (!isset($this->lookupTable[$specName])) {
61: if (false === $spec->getOptional()) {
62: throw new NoHandlerException(sprintf('Unknown handler %s', $specName));
63: }
64: return $handler;
65: }
66:
67: $name = $this->lookupTable[$specName];
68: $class = '\Xoops\Core\Kernel\Handlers\Xoops' . $name . 'Handler';
69: if (class_exists($class)) {
70: $handler = new $class($spec->getFactory()->db());
71: }
72: if ($handler === null) {
73: if (false === $spec->getOptional()) {
74: throw new NoHandlerException(sprintf('Class not found %s', $class));
75: }
76: }
77: return $handler;
78: }
79: }
80: