This starter allow you to create LaMetric apps easily. (Indicator App)
Fork this project or create a new repository using this link.
Declare fields you want to retrieve from your LaMetric App you designed, in file config/fields.php
.
e.g.
return [
[
'key' => 'field-1',
'type' => Field::TEXT_TYPE,
],
[
'key' => 'field-2',
'type' => Field::NUMBER_TYPE,
],
[
'key' => 'field-3',
'type' => Field::SWITCH_TYPE,
],
[
'key' => 'field-4',
'type' => Field::CHOICES_TYPE,
'choices' => [
'iron-man',
'captain-america',
'ant-man',
'thor',
]
]
];
Fields type association with https://developer.lametric.com :
- Field::TEXT_TYPE : Text field
- Field::NUMBER_TYPE : Number
- Field::SWITCH_TYPE : Switch
- Field::CHOICES_TYPE : Single choice
The src/Validator.php
object will check parameters sent by the app and manage errors.
You can also add default
key to a field. If the value is missing from app request, this valus will be use.
e.g.
return [
[
'key' => 'field-1',
'type' => Field::TEXT_TYPE,
'default' => 'hello'
],
];
Add you logic to the method fetchData()
in src/Api.php
.
Maybe you need to extract data from an API. You can inject any dependencies as needed.
You can also inject credentials like secret api-key : copy config/credentials.php.dist
to config/credentials.php
and edit content.
/**
* object $this->client (Guzzle HTTP) is available to make curl requests
* array $this->credentials contains sensitive data
* array $parameters (credentials) can contain sensitive data
*/
Adapt the method mapData()
in src/Api.php
to manage frames and data you need.
More information about frames here.
You can deploy it everywhere you want. You only need PHP and ext-json
(ext-curl
if you consume an API).
You only need to configure the docroot of your vhost to the folder public.
If you need help, create an issue or contact me on Twitter.