Liaison

A PHP Framework and a set of components for developing webapps and websites

Next Version (release TBD)

This version is planned for the future & as of Apr 12, 2022 development has not begun. Just notes. See Status.md

v0.6 will be the next version & will come with major internal changes but likely will not have any significant changes to the API. The current version has Package & Addon as sub-classes of Lia. Also, there are MANY properties by-reference. These complexities are slow & confusing. In the new version, Packages & Addons will likely not extend from Liaison any further. And by-reference properties will be removed.

Beta Version (April 5, 2021)

v0.5 marks the official beta. Software-wise, it's basically ready to go. Documentation wise, it's pretty poor. There are some weird things in here that will make it hard for you to use to it's full ability until I finish writing proper documentation. There's also some minor code issues in Liaison that I do need to fix.

My advice: Admire what it could be, keep an eye on it, and use it when it is a little more mature.

Quick Start

  1. Write a deliver script, such as deliver.php. Comment out the require add-route.php line
@file(test/ServerMinimal/deliver.php)
  1. Write a home page. Create a file public/index.php
@file(test/ServerMinimal/public/index.php)
  1. Start the server: php -S localhost:3000 deliver.php. Visit http://localhost:3000/ in your browser

Ideally, write tests to ensure your site works as expected. See @see_file(test/run/ServerMinimal.php) for simple examples. I use @easy_link(tlf, php/tester), but Php Unit is the popular go-to for php testing

  1. Write a view file at view/ArticlePreview.php
@file(test/ServerMinimal/view/ArticlePreview.php)
  1. Write a stylesheet at view/ArticlePreview.css You can also write view/ArticlePreview.js and view/ArticlePreview/*.css|*.js files to add more styling and scripting
@file(test/ServerMinimal/view/ArticlePreview.css)
  1. Write a route in your deliver.php file. Alternatively, make a public file public/{slug}.php and echo $view instead of $response->content = $view;
@file(test/ServerMinimal/add-route.php)
  1. Write a theme at view/theme.php: Call $lia->setTheme('theme/name') to change the theme.
@file(test/ServerMinimal/view/theme.php)

Lia\Simple

A class for more easily setting up a Liaison instance with several integrations. Notes:

  • Sets user_has_role handler on phad to a function that returns $this->user->has_role($role) or true if $this->user is not set.

Older Documentation

I believe the remaining docs are still accurate, but I have not reviewed them recently for accuracy or clarity.

Structure

  • Lia manages methods, addons, and properties
  • Lia\Package is a base class for packaging addons together
  • Lia\Addon is a base class for writing addons
  • Lia\Package\Server helps deliver websites by tying together main addons (public files, views, cache, autoloading, and more)
  • dir code/class/Object/* are objects used by built-in components
  • dir code/class/Utility/* are Utility classes
  • dir view/theme provides a default theme
  • dir file/mime_type_map.php is just that

Components

Addons create all the features. Lia\Package calls upon several of these components

  • Autoloader: loads classes within given directories
  • Cache: cache key/value pairs & files
  • Error: Report errors to users
  • Hook: register & call hooks (very generic form of extensibility)
  • Redirect: Redirect requests
  • Resources:
    • Add css & js files, urls, and/or code blocks to a request
    • Sorting api to set order of resource files in compiled output
    • Routes to compiled resource files
    • Manages seo information (this should go in a new component)
    • Outputs headHtml (must be called)
    • Passes compiled files to cache component
  • ResourceSorter: A wrapper around the Resources sorting api, to make it easier
  • Router: Set pattern & static routes. Parse paramaters from urls. Process url for route target (package, callable, file)
  • Server: Handles request delivery
    • Helps all the addons work together to respond to a url
    • delivers static non-php files
  • View: Display re-usable scripts/templates

Directory Structure

The Package decides the structure, so this can be changed. Default is:

App/
    - config.json <- Package settings
    - public/ <- Public files to be routed to. Ex: `public/contact.php` routes to `/contact/`
    - view/ <- Views
    - addon/ <- Addons (generally extending from \Lia\Addon)
    - class/ <- Classes to autoload, PSR4 style. Will be converted to classmap style later
    - cache/ <- Dir to store cache files. Only one cache dir is used (each app does not get its own)

Other Stuff

  • Environment-dependent features are not built-in, but I recommend my @easy_link(tlf, php/env)
  • set $_SERVER['DO_NOT_RESPOND'] = true; to stop Simple->respond() from doing anything.
  • \Lia\Simple->get_all_sitemap_routes() is a useful method to know
  • send $_GET['theme'] = 'json' to return a response as json with keys content, scripts, and stylesheets.