-
Notifications
You must be signed in to change notification settings - Fork 51
Topics
Joe Huss edited this page Sep 15, 2021
·
3 revisions
Topics function as additional help pages that would otherwise be too much to all output on the main help page.
Create a class that extends from CLIFramework\BaseTopic
. The following fields and methods are available to be overridden.
Field/Method | Description |
---|---|
public string $title |
Appears under the TOPIC header. |
public function getContent(): string |
Appears under the DESCRIPTION header. |
public string $url |
If getFooter() is not overridden and an url is specified, a "You may view this topic at $url" footer is generated. |
public function getFooter(): string |
Appears under the MORE header. |
You register topics in an application in the init(): void
method.
$this->topic('key', MyTopic::class);
$this->topics([
['key2' => MyTopic2::class]
['key3' => MyTopic3::class]
]);
Instead of providing a class you can also provide a string identifier. The conversion from id to class is illustrated as follows:
$this->topic('testing');
$this->topic('gettingStarted');
Assuming the application is at the App\ namespace.
testing -> App\Topic\TestingTopic
gettingStarted -> App\Topic\GettingStartedTopic
Note that topic ids should be camelCase. Using 'getting-started' as id would not work, although you could still use it as key like this:
$this->topic('getting-started', 'gettingStarted')
Use the key with the help command to show the topic.
php program.php help gettingStarted