Package lia:server
- Class:
Lia\Package\Server
- Class File: /src/class/Server.php
- FQN:
lia:server
- Package Directory: /src
Addons
Addons are loaded by calling Addon\\ClassName::from(\Lia $lia)
Configurable properties are set by calling $lia->configure(array $configs)
before instantiating any packages. See Liaison Documentation for more information.
This package contains the following addons.
Lia\Addon\Autoload
DO NOT USE. While this class should work, composer is a better choice for autoloading.
Addon Name: autoload
Class File: /src/addon/Autoload.php
Configurable Properties:
-
$dirs
:array<string directory, array namespaces>
directory=>namespace lists for PSR4 autoloading.
Public Methods:
-
public function enable()
: no-description -
public function addDir($dir,...$baseNamespaces)
: add a directory to be autoloaded, psr4-ish - ``: no-description
Lia\Addon\Cache
Cache key=>value
pairs with a max age to auto-expire. Each pair is stored in its own file.
Addon Name: cache
Class File: /src/addon/Cache.php
Configurable Properties:
-
$dir
: Absolute path to directory to store cache files in. -
$enabled
: setfalse
to disable cache. -
$stale_check_frequency
: int minutes between stale cache checks. Ifvendor/bin/lia clear-cache --stale
is run a second time before this amount of minutes has passed, then nothing will happen. Same fordelete_stale_files()
method call. Methodrun_delete_stale_files()
does not check this setting.
Public Methods:
-
public function main_file_path(): string
: no-description -
public function read()
: reads main key=>value pairs from disk into memory -
public function write()
: Write main key=>value pairs to disk from memory -
public function is_cache_file_valid($key): bool
: Check if: cache is enabled, cached file exists, cached file is NOT expired -
public function get_cache_file_content($key): stringbool
: Get content of a cached file, if cache is valid -
public function get_cache_file_path($key): stringbool
: Get path to cached file if cache is valid -
public function cache_file_path($key): stringbool
: Get the path for a cached file -
public function cache_meta_file_path($key): string bool
: get the path to a meta file, which contains expiration time of cached files -
public function cache_file($key, $value, $maxAge=60*60*24*5): stringbool
: Store $value to file by identified by $key -
public function delete_stale_files()
: Delete stale cache files IF a stale cache check is required -
public function run_delete_stale_files()
: Delete stale cache files (unconditional) -
public function delete_all_cache_files()
: Deletes ALL cache files, whether expired or not -
public function is_stale_cache_check_required()
: check if stale cache check is required -
protected function deleteStaleCacheFiles()
: no-description -
public function create_dir($dir)
: Creates directory if it does not exist. -
public function set($key, $value)
: no-description -
public function get($key)
: no-description -
public function __set($key,$value)
: no-description -
public function __get($key)
: no-description -
public function onParentReady(\Lia\Package $package)
: no-description
Lia\Addon\Error
DO NOT USE. An addon for displaying and logging errors, and redirecting in the process. This addon may be removed, and it may not even work right now.
Addon Name: error
Class File: /src/addon/Error.php
Configurable Properties:
Public Methods:
Lia\Addon\Hook
Register and call hooks.
Addon Name: hook
Class File: /src/addon/Hook.php
Configurable Properties:
Public Methods:
-
public function prefix_method_added($obj, $method, $hook_name)
: Add an object's method as a hook. -
public function add($name, $callable)
: no-description -
public function call($name, ...$args)
: no-description
Lia\Addon\Http
Handles requests, processes routes, sends responses, and compiles content into a theme view.
Addon Name: http
Class File: /src/addon/Http.php
Configurable Properties:
-
$useTheme
: booltrue
(default) to use theme, false to disable theme.$response->useTheme
must also betrue
for theme to be displayed. -
$themeName
: string name of view to be used as the page-layout.
Public Methods:
-
public function setTheme($name)
: Set theme to use in a web response -
public function protocol()
: no-description -
public function urlWithDomain($relativeUrl)
: no-description -
public function getResponse($url=null, $methodnull)
: no-description -
public function apply_theme(\Lia\Obj\Route $route,\Lia\Obj\Response $response)
: Applies the theme (if response->useTheme & server->useTheme are true) -
public function process_route(\Lia\Obj\Route $route,\Lia\Obj\Response $response)
: Process a route & setup the response's content & headers -
public function try_redirect_to_corrected_url($url, $method)
: This is a sloppy bad function that needs rewritten -
public function send_response($response)
: no-description -
public function deliver($url=null, $methodnull)
: no-description -
protected function closeConnection()
: Close the connection with client. May not work on all hosts, due to apache/server configuration, I'm pretty sure. -
public function requirePhpFileRoute(\Lia\Obj\Route $route,\Lia\Obj\Response $response)
: no-description -
public function getDistinctRoute(array $routeList): \Lia\Obj\Route
: For a list of multiple routes, select one....
Lia\Addon\Redirect
DO NOT USE. It is better to just use PHP's built-in header()
function. This addon may be removed in the future.
Addon Name: redirect
Class File: /src/addon/Redirect.php
Configurable Properties:
Public Methods:
-
public function goto($url, $statusCode=302)
: no-description -
public function gotoSetMessage($message)
: no-description -
public function gotoWithMessage($url, $message, $statusCode=302)
: no-description -
public function getGotoMessage()
: Get the redirect message associated with$_GET['message_id']
-
public function get_url()
: get the url withmessage_id
set in query params.... -
public function go()
: no-description
Lia\Addon\ResourceSorter
Convenience class for sorting css & js files before they are concatenated together.
Addon Name: resourcesorter
Class File: /src/addon/ResourceSorter.php
Configurable Properties:
Public Methods:
Lia\Addon\Resources
Manages CSS & JS Files, prints tags in <head>
and concatenates files together.
Addon Name: resources
Class File: /src/addon/Resources.php
Configurable Properties:
-
$files
:array<string css|js, array file_list>
css & js files to concatenate together and deliver as a single<script>
and<link>
tag in the<head>
-
$urls
:array<string css|js, array url_list>
URLs to print as<script>
and<link>
tags in<head>
-
$useCache
: booltrue
(default) to use cache,false
to disable cache (for development).true
is recommended in production. Note: This addon uses a separate cache directory from the main cache addon's cache directory.
Public Methods:
-
public function onParentReady(\Lia\Package $package)
: no-description -
protected function cleanExt($ext)
: no-description -
protected function cacheMapName($ext)
: no-description -
public function setSorter(string $ext, mixed $sorter)
: Set a function/callable to be used for sorting resource files before they are output to a batch file. You can also use this to remove files from the list. -
public function addFile(string $file)
: Add a css or js file to be added to the final output -
public function addUrl($url)
: no-description -
public function getHtml(): string
: Get<head>
html with javascript and css tags, and seo-related meta tags. -
public function getFileTag($ext)
: no-description -
public function getUrlTag($ext)
: no-description -
public function getSortedFiles($ext)
: no-description -
public function concatenateFiles($ext)
: no-description -
public function concatenateFileNames($ext)
: no-description -
public function compileFilesToCache($ext)
: no-description -
public function getCompiledFilesUrl($ext)
: no-description -
public function minifyFiles(string $fileContent, string $ext)
: no-description
Lia\Addon\Router
Routes /requests/
to files or callables based on provided static /patterns/
or dynamic /{patterns}/
. Manages GET
and POST
requests.
Addon Name: router
Class File: /src/addon/Router.php
Configurable Properties:
Public Methods:
-
public function dir_to_patterns($dir, $prefix='')
: Get an array of patterns from files in a directory. -
public function fileToPattern($relFile)
: Convert a relative file path into a pattern -
public function clean_url($dirty_url)
: Clean a url (without domain): replace space with '+', single quote with '%27', and replace multiple slashes with a single slash -
public function handle_route_prefix_method($object, $m, $dot_name)
: Get routes by calling the object's method & use the method as the router. -
public function addRoute($pattern, $callbackOrFile,$package=null)
: Add a route -
public function removeRoute(string $pattern): int
: Remove all routes matching the target pattern. -
public function has_static_route(string $path,string $method="GET"):bool
: This method is not tested at all. does not check dynamic routes. -
public function separate_optional_from_decoded_pattern($original_parsed)
: Facilitates optional paramaters... -
public function addRouter(callable $router)
: add a callable as a router. It will be called with a\Lia\Obj\Request
object as the only paramater -
public function route(\Lia\Obj\Request $request)
: get a route for the given request -
public function addDirectoryRoutes(\Lia\Package $package, string $directory, string $base_url = '/', array $exts_to_remove[".php"])
: no-description -
public function decode_pattern($pattern)
: Convert a pattern into a decoded array of information about that pattern... -
public function extract_url_paramaters($decoded_pattern, $url)
: Given a url and array of paramaters, -
public function url_to_regex($url)
: convert an actual url into regex that can be used to match the test regs.
Lia\Addon\Seo
Convenience class for turning SEO information like page title, description, image url, and others into correct tags in the <head>
.
Resources for needed seo data/
https://developer.twitter.com/en/docs/twitter-for-websites/cards/guides/getting-started
https://ogp.me/
https://www.w3schools.com/tags/tag_meta.asp
NOT USED https://schema.org
Addon Name: seo
Class File: /src/addon/Seo.php
Configurable Properties:
Public Methods:
-
public function addHeadHtml($html)
: no-description -
public function seo($params)
: Shorthand to set seo paramaters from an array. -
public function title($title)
: no-description -
public function description($description)
: no-description -
public function meta(string $name, string $content)
: Add any meta tag -
public function image($url, $altText)
: no-description -
public function url($url)
: no-description -
public function site_name($siteName)
: no-description -
public function keywords($keywords)
: no-description -
public function get_html()
: no-description
Lia\Addon\View
Single interface for accessing all views across a liaison instance. Views can be files or callables and accept array arguments.
Addon Name: view
Class File: /src/addon/View.php
Configurable Properties:
Public Methods:
-
public function getHeadHtml()
: no-description -
public function addDir(string $dir, \Lia\Package $package)
: no-description -
public function addView(string $view_name,string $dir)
: no-description -
public function addViewFile(string $view_name, string $file)
: no-description -
public function addViewCallable(string $view_name, mixed $callable)
: no-description -
public function view(string $name, array $args=[])
: no-description -
public function show_file($view, $args)
: no-description -
public function show_callable($view, $args)
: no-description -
public function show_main($view, $args)
: no-description -
public function addFiles(string $dir)
: add resource files in the given directory -
public function get_resource_file_list(string $base_dir, string $view_name): array
: Get array of absolute path to all files associated with the named view. -
public function change_namespace(string $original_namespace, string $new_namespace, bool $allow_overrides = false)
: Rename the original_namespace to the new_namespace. The old namespace is removed.... -
public function onPackageAdded(\Lia\Package $package)
: no-description