PHP library for easily and consistently scaffolding REST API endpoints for Modo Labs' XModule feature.
This library provides a suite of PHP classes that directly mirror Modo's collection of XModule elements. It aids in the creation of complex XModule layouts by removing the need for boilerplate JSON and ensuring all XModule pieces fit together seamlessly using object-oriented workflows and strongly-typed parameters.
After being built, scaffolded XModules can have their contents output in fully compliant JSON using only the json_encode
result of a call to $xmodule->render()
.
- PHP >= 7.0.0
$ composer require ontariotechu/xmodule:dev-master
Don't forget to include Composer's autoloader once at the beginning of your application:
require __DIR__ . '/vendor/autoload.php';
Import the needed components into your server application:
use \XModule\Base\XModule;
use \XModule\Shared\Link;
use \XModule\Constants\LinkType;
use \XModule\ButtonContainer;
use \XModule\LinkButton;
Use the components to build XModule structures:
/**
* Create a new XModule
*/
$xmodule = new XModule();
/**
* Create XModule elements
*/
$buttonContainer = new ButtonContainer(['id' => 'link_buttons']);
$link = new Link('./', LinkType::RELATIVE_PATH);
$button = new LinkButton('Click here', ['link' => $link]);
/**
* Attach your elements to each other and the XModule
*/
$buttonContainer->addButton($button)
$xmodule->addContent($buttonContainer);
/**
* Render the output
*/
echo json_encode($xmodule->render());
{
"metadata": {
"version": "1"
},
"content": [
{
"elementType": "buttonContainer",
"id": "link_buttons",
"buttons": [
{
"elementType": "linkButton",
"title": "Click here",
"link": {
"relativePath": "./"
}
}
]
}
]
}
General usage how-tos can be found in the wiki of this repository. The pages of the wiki are also presented in a single document inside usage.md for quick access.
Full class documentation is still pending, but in the meantime there are some very basic auto-generated docs that can be found in the /docs
folder of this repository. Documentation can be regenerated or viewed using the included Composer scripts:
# regenerate
$ composer run-script build-docs
# view docs (http://0.0.0.0:8080)
$ composer run-script docs
- Modo Labs created XModule and the mobile application software it is used in. All trademarks belong to them.