Directory structure

MVC design pattern

Ubiquity implements MVC2 design pattern.
The directory structure makes it easy to separate views, models and controllers.
app
 ├ cache
 ├ config
 ├ controllers
 ├ models
 └ views
namespace controllers;
class Main extends ControllerBase{
	/**
	 * @route("index","methods"=>["get","post"])
	 */
	public function index(){
		//
	}
}
Controllers & routes

Pretty URLs

Ubiquity uses pretty URLs, built from the principle controller/action/{parameters...}.
It is also possible to use the @route annotations.
Models & ORM

Datas

Models are Plain Old PHP Objects, only with members and accessors to them.
Object relational mapping relies on member annotations.
A Data Access Layer (DAO class) performs bidirectional transfer of data between the relational database and the domain layer (models).
namespace models;
class Product{
	/**
	 * @id
	 * @column("name"=>"id","dbType"=>"int(11)")
	*/
	private $id;

	/**
	 * @column("name"=>"name","dbType"=>"varchar(65)")
	*/
	private $name;
}
$products=DAO::getAll("models\Product");
$product=new Product();
$product->setName("Brocolis");
$products=DAO::save($product);
class Products extends ControllerBase{

	public function index(){
		$this->loadView("index.html",["message"=>"Hello"]);
	}
{% extends "base.html" %}
{% block body %}
	{{ message }}
{% endblock %}
}
View loading & Twig templating

Views

Views are loaded from the controller, in a classic way.
The controller optionally pass them the data.

Twig is the default template engine.
PSR-4

Classes autoloading

Ubiquity use PSR-4 composer autoloader.
The root namespace of a project is anchored in the app/ folder.
namespace controllers;
class Product{
}
app
 └ controllers 
      └ Product.php

     class IndexController extends ControllerBase{
             ...
             public function isValid($action){
                     return USession::exists('activeUser');
             }

             public function onInvalidControl(){
                     $this->initialize();
                     $this->loadView("unauthorized.html");
                     $this->finalize();
             }
     }
Actions

Access control

Access control to a controller can be performed using the isValid and onInvalidControl methods.