-
Notifications
You must be signed in to change notification settings - Fork 11
Introduction
The MABI framework is built on PHP and the Slim Framework to implement a REST based Model-Controller architecture. The framework strives to be open and adjustable by allowing overrides of all of its internal classes, but it also uses comment annotation and naming conventions to provide override shortcuts and keep code clean and readable.
In addition to the base setup for the framework, MABI bundles tools to interact directly with MongoDB, build/output documentation automatically from code, and allow developers to test their endpoints. These are explained in the detailed reference. The following are the main concepts from a coding perspective:
MABI removes the 'view' component that most frameworks have so that the Model serves as the communication and documentation vehicle to the client while the client provides the view. The controllers manage how that communication of the Model happens (rights, updates, etc.). For the most part mobile and API-driven web applications share most of the nomenclature and properties of models with the backing server/database. When we use the model as the primary communication vehicle, we can start sharing it much more easily with consumers.
Reasoning behind why to use Models as communication vehicle:
By default, MABI automatically generates controllers that implement REST (this is done via the RESTModelController
class), allowing the mobile device full control to retrieve, create, update, and delete collections and individual resources. Default controllers can be overridden to add rights and custom actions, as well as creating completely new controllers to define custom non-REST actions.
The entire framework uses overridable classes to implement its models and controllers. This way, you are always able to remove layers of abstraction as your application requires more in-depth and independent usage from framework standards.
The following is an example of typical application overrides for MABI:
For simplicity, MABI uses comment annotations to provide shortcuts for common overrides in models and controllers. The following is an example of annotations in a derived model:
namespace foodtweeks;
class Tweek extends \MABI\Model {
/**
* @var string
*/
public $instructions;
/**
* @var int
*/
public $calorieCategory;
/**
* @var float
*/
public $averageRating;
/**
* @var Food
*/
public $food;
/**
* @field external
* @var int
*/
public $myRating;
/**
* @field internal
* @var int
*/
public $ratings;
The example above shows the @var annotation, which specifies the type (this is a very common PHP annotation). There are core int, string, and float example fields, and also one of a Food class (another MABI Model), which will automatically be loaded as an object.
You can also see examples of the @field annotations which add extra field-specific functions. 'external' means that the value is only output by the API but not stored anywhere. 'internal' means that the value is stored and used by the server but not output by the API.
More information about the annotations available can be found in the Annotation Reference or in the corresponding base object (Models or Controllers).