Liaison: WebApp framework
Create agnostic web-apps that can be used across many frameworks like Wordpress, Laravel, Joomla, Drupal, and others. You can make a full website with it too.
Under Development
Liaison is under development. It is pretty stable, but some core features are planned to change. Please keep your eye on this. I've been building it for over a year and I think it will be a great addition to open source and web-app development. I'm not sure it will add much value in web-site development, beyond providing, essentially, agnostic full featured gui-web-apps that you can plug into any setup (so is the goal).
Installing
composer require taeluf/liaison dev-version_1
or
{
"require": {
"taeluf/liaison": "dev-version_1"
}
}
Liaison
Liaison ties everything together. Packages & their components, view lookups, config values, routing, events, and more??
Basic Usage
$lia = new \Liaison();
$lia->addPackage(
['dir'=>__DIR__.'/my-package/',
'name'=>'MyPackage'
]
);
$lia->deliver();
This will load files from your package and route appropriately.
$lia, Methods to know
- deliver($url=null)
- uses the requested url by default, but you can pass in a url, which may include a get string like
?cats=cute
- uses the requested url by default, but you can pass in a url, which may include a get string like
- addPackage($options): $options is an array
- dir: The root directory of your package
- name: The name to be used for retrieving your package. -Each package must have a unique name
- package($name): retrieve a package by name
- packages(): A list of packages
- compo($name): For each package, get any components named
$name.- 0 components found, return null, 1 component found, return the component, 2+ components found, throw an exception
- set($key, $value) & get($key,$valueIfNotFound): Store & retrieve values across the $lia instance
- view($name, $passthru): Get a view (from any package) by $name, passing $passthru to the view.
- See Views for more information
- register($eventName, $object, $method=null): Register the event to be executed
- send($eventName,$arg1, $arg2, $arg3, ....): Execute the given event, passing the list of args along.
- See Events
Views
Each package can set up it's own view system. Currently, we support the built-in \Lia\View and the Fresh Package lib I created. \Lia\View is... basic, but it works. Fresh Package is cool, but needs a lot of work.
Retrieve a view
Call $lia->view($name,$data) or $lia->compo('ViewHandler')->view(...)
- Get a view (from any package) by $name, passing $data to the view.
- 0 views found, return null. 1 view found, return it. 2+ views found, throw an exception
- Uses the
ViewHandlercomponent of the liaison base package to retrieve view objects
Route Types
New route types can be added, but these are built in.
PHP
Routed files ending in '.php' will be executed, with variable components of the route exposed as variables.
Example: For file public/cat/$name.php, url /cat/zander/ will expose $name = 'zander' to the php file.
Markdown
Routed files ending in '.md' will be parsed into html, using PHP League's CommonMark
Everything else
Routed files not otherwise handled will be sent, with the correct headers, including browser caching headers.
Example: For file public/funny/kitty.png, url /funny/kitty.png will deliver the image file, as you would expect.
Mimetypes (for headers) are derived from a PHP file internal to Liaison. It's not particularly efficient.
Autoloading
Files in your Package's class dir will be auto-loaded. The class dir varies by package, but the built-in package uses yourpackagedir/class
It's uhh. It's dumb. It's 1 to 1 relationship of namespace to directory. This will be improved, but we're not sure how. Thus \My\Glass must be at class/My/Glass.php
The autoloader is setup during the Package_Added event
See Audoloader docs for more information.
Events
Events are the primary way that different packages and different parts of a package communicate with one another.
Any component (using the base package) may declare onNamespace_EventName($event,$arg1,$arg2,....) to automatically have the event registered when the package is added.
Namespaces aren't entirely required, but it's better that way.
Each Event callable will receive an $event object. This object is always the same \Lia\Event component object. This needs to be improved.
See Event docs for more information.
Resources files (js, css)
See Extra Docs to learn how to add javascript & css code, files, and urls to a request.