File src/Phad.php
class Phad
See source code at /src/Phad.php
Constants
Properties
-
public \PDO $pdo = null; -
public $route_prefix = ''; -
public array $configs = [];array of configs, typically from an on-disk json file. These are not directly used by Phad, but may be useful to subclasses or integrations. -
public \Phad\SitemapBuilder $sitemap;sitemap builder instance -
public \Phad\RouterInterface $router;a router instance -
public \Phad\AccessInterface $access;Handles all access checks, such as user-role checking and per-row checking -
public $data_loaders = [];array of callables that return an array of rows.
Each callable should accept args(DomNode, ItemInfo)& return an array of rows. -
public bool $exit_on_redirect = true;set false to stop phad fromexiting when calling->redirect()
You can custom handle theheader()call by creating aheader()function in thePhadnamespace.
See https://akrabat.com/replacing-a-built-in-php-function-when-testing-a-component/ to understand the Phad\header() thing
-
public bool $force_compile = false;true to always re-compile views -
public $global_phad_args = [];args to pass to every phad view -
public $filters = [ ];key=>valuearray of filters wherekeyis the filter you write in the html &valueis a callable -
public $item_dir;Absolute path to a directory that contains phad items -
public $cache_dir;Absolute path to a directory to store cached files -
public $sitemap_dir;Dir to write sitemap.xml file to -
public bool $throw_on_query_failure = false;true to throw exception when query failes. false to silently fail & return false -
public $sitemap_handlers = [];array of handlers for sitemap building -
public $validators = [];array of validation functions
Methods
-
public function __construct() -
public function read_data(array $data_node_info, object $ItemInfo): arrayProcess a data node, perform a query if required, checkAccessInterface::can_read_row()for each, and return an array of allowed rows. If rows were explicitly passed into the item, then these will be returned instead of any data nodes being processed or queries being performed. Nodes are processed and queries are performed byclass Phad\DataReader -
public function modify_query_info(array $query_info)Modify a query before getting rows -
public function object_from_row(array $row, $ItemInfo)Converts an array row (loaded via a data node) into an object. -
public function object_from_submission(array $row, $ItemInfo)When a form is submitted, convert submitted POST data into an object, so that it can be displayed in the form.
Set $this->enable_filtering = true to re-enable filtering on input nodes. (Within your template, $this refers to the Item class, not to Phad)
-
public function has_item($name) -
public function item($name, $args=[]) -
public function item_from_file(string $file_path, array $args=[])get an item instance from a file
This does not set up any routing
-
public function filter(string $filterName, $value) -
public function filter_markdown($markdown)Apply commonmark conversion to the value, turning markdown into html -
public function get_rows($ItemInfo): arrayReturn rows when$item->rows()is called. The rows have already been loaded into$ItemInfo->rows, andcan_read_row()has already been checked for each one. -
public function setup_routes() -
static public function main(\PDO $pdo, string $root_dir, \Lia $liaison, \Tlf\User\Package $user_package=null, array $configs []): staticCreate a PHAD instance using the default integrations withtaeluf/liaisonandtaeluf/user-gui. Configs are optional. Usevendor/bin/phad setupto generate a config file. -
static public function custom(\PDO $pdo, string $root_dir, \Phad\RouterInterface $router, \Phad\AccessInterface $access_controller = null, array $configs []): static -
public function create_sitemap_file(): stringMake a sitemap file from all views -
public function compile_all_items() -
public function parse_functions(string $call_string)parse a string likeprint:woohoo;call:somethin;role:admin; -
public function no_rows_loaded(stdClass $ItemInfo)Handle when no rows were loaded. This method is for overriding and does literally nothing otherwise. -
public function read_node_failed(array $node)Handle when a node cannot be read -
public function sanitize_user_row(array $row)replace each$valuewithhtmlspecialchars($value) -
static public function fill_pattern(string $pattern, array $values): stringFill a url pattern like/blog/{slug}/from an array of values like['slug'=>'some-post'] -
static public function get_url_params(string $url_pattern): arrayParse a pattern like/blog/{slug}/and return params in the pattern like['slug']