Liaison
A PHP Framework and a set of components for developing webapps and websites
NOTICE: Under development
This latest version is not ready to use. It is still under dev, but should be ready soon. Should. The old versions are not worth using. v0.1
is functional, but it would be better to wait until I have a more stable version of Liaison ready.
Structure
-
Liaison
manages apis & their global aliases. -
Lia\Package
handles resources in a given directory:- load configs & manage them
- load components & manage them
- load views
- convert public files into routes
- set up autoloader
- has LifeCycle functions, which are handled by a built-in component
-
Lia\Compo
is a base class to simplify setting up components - dir
class/Object/*
are objects used by built-in components - dir
class/Utility/*
are Utility classes - dir
view/theme
provides a default theme - dir
file/mime_type_map.php
is just that
Components
Components create all the features. Lia\Package
calls upon several of these components
- Autoloader: loads classes within given directories
- Cache: caches files with given content for specified time period
- Config: Handles global configurations (used across packages) and can propagate configs to packages
- Error: Handles both internal errors & request errors. @TODO
- Event: api to schedule and emit events,
- GlobalParam: Manages variables that should be given to all parts of a Liaison server.
- LifeCycle: Manages objects that have lifecycle methods. Executes onPreMethod and onMethod when the registered lifecycle starts
- PackageList: Keeps a list of packages, accessible by name
- Redirect: Redirect requests, with content, if desired.
- 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 components work together to respond to a url
- delivers static non-php files
- View: Register views, and create View objects from given paramaters.
Directory Structure
Directory structure is COMPLETELY determined by the Package
class you're using, not by Liaison
. This structure is defined by our built in Package
class.
aPackageDir/
- config.json <- Package settings
- public/ <- Public files to be routed to. Ex: `public/contact.php` routes to `/contact/`
- view/ <- Views
- core/ <- Components (generally extending from \Lia\Compo)
- class/ <- Classes to autoload, PSR4 style. Will be converted to classmap style later
- cache/ <- Where to store cache files. Though cache files are stored in a global package dir, not a package-by-package basis
Some Awful Things
- Environment-dependent features are not built-in, but I recommend my Env php class
- There is no namespacing. But there WILL be namespacing. (of views, apis, public files)
- A file cache exists, but not a
key=>value
cache, and its horrible - The api for... adding apis is clunky (to use. performance should be fine)
Request lifecycle
-
.htaccess
routes todeliver.php
or wherever you like - Server setup: Database configuration, other non-liaison things
-
$lia = new Liaison()
<- Liaison adds its built-in package (or pass['bare'=>true]
) -
new \Lia\Package($lia, $dir, $configs)
for each package to add-
new $Component()
for each component in the package -
$Component->onCreate()
<- Called from\Lia\Compo
-
$Component->onReady()
<- Called from\Lia\Compo
-
$Component->onComponentsLoaded()
<- After all components in THIS package have calledonCreate
&onReady
. Called by\Lia\Package
-
$Component->onPackageReady()
<- After routes, views, & configs have been loaded for this package-
$Component->onPrePackageReady()
is called first, but is not recommended. If used, you must callparent::onPrePackageReady()
to keep prefix scanning enabled
-
-
-
$lia->deliver()
calls$lia->getResponse()
(the following is all called from\Lia\Compo\Server
)-
$lia->emit('PreAllPackagesReady')
- emit
AllPackagesReady
<- Handle in components by declaringonEmitAllPackagesReady()
- emit
RequestStarted($request, $response)
- emit
RoutesFound($routeList)
- emit
RoutesFiltered($finalRoute)
- resolve route
- emit
RouteResolved($route, $response)
-
if ($response->useTheme)
, load theme, emitThemeLoaded($themeView)
, then set$response->content
to(string)$themeView
- emit
ResponseReady($response)
-
-
$lia->deliver()
has a response-
$response->sendHeaders()
-
if ($response->sendContent) echo $response->content
- emit
ResponseSent($response)
- close connection (May not work in all web hosts / apache setups)
- emit
RequestFinished($response)
-
Some things that really need to be done
- Set no-cache headers for non raw-file requests
- Write docs for declaring APIs
- Review the
Api
trait & see if I can make it more intuitive
- Review the
- Add namespacing of views, public files, & other package-specific components
- Document all prefixes available & how to use them & how to change them
- Stop relying upon the funky function naming conventions (but don't get rid of prefixing alltogether)
- simple
key=>value
caching - Document both PACKAGE lifecycle AND component lifecycle
- Basically just document how to use everything