suki / ohara
SMF 模块辅助类
v1.0.6
2016-02-16 00:48 UTC
Requires
- php: >=5.3.0
- composer/installers: ~1.0
README
SMF 修改(Mods)使用的辅助类。
要使用此辅助类,您需要遵循一些要求
- 需要 PHP 7.0 或更高版本。SMF 2.1。
- 将其包含或require到您自己的文件中。您也可以使用composer
$ composer require suki/ohara
- Ohara 使用 composer/installers,这意味着类将被自动放置在 SMF 的 Sources 文件夹中,除非您在自己的 composer.json 文件中覆盖它。
要使用此辅助类,只需使用 Suki\Ohara 命名空间扩展父类 Ohara
class YourClass extends Suki\Ohara { ...
-
您需要定义 $name 属性,理想情况下从声明中获取
public static $name = CLASS;
$name is the unique identifier for your main class. Can be any name but usually "__CLASS__" fits quite well.
- You need to call $this->setRegistry(), ideally on your construct method to register your class, have access to several SMF's global variables, create Pimple's service and execute any "on-the-fly" hook declarations.
Thats it, you now have all the power of Ohara. All services are stored as keys in your $this var:
$parsedText = $this['tools']->parser($text, $replacements);
- The class can largely be used as it is but some methods expects info provided by the mod author.
- All your settings ($modSettings) and text strings ($txt) must follow the same pattern:
```php
$txt['Mod_something'];
$modSetting['Mod_something'];
其中 Mod 是您在 $name 属性中使用的任何内容。
要使用设置,只需调用 $this->setting('something'); 或 $this->text('something');(对于文本字符串)。如果与之相关的 $modSetting 或 $txt 不存在,两者都返回 false。
$this->setting('something') 接受第二个参数作为回退,以防 $modSetting 不存在
$something = $this->setting('something', 'not found!');
- Ohara 以《海贼王》岛屿命名: 大原。