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 from exiting when calling ->redirect()
    You can custom handle the header() call by creating a header() function in the Phad namespace.

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=>value array of filters where key is the filter you write in the html & value is 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): array Process a data node, perform a query if required, check AccessInterface::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 by class 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): array Return rows when $item->rows() is called. The rows have already been loaded into $ItemInfo->rows, and can_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 []): static Create a PHAD instance using the default integrations with taeluf/liaison and taeluf/user-gui. Configs are optional. Use vendor/bin/phad setup to 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(): string Make a sitemap file from all views

  • public function compile_all_items()

  • public function parse_functions(string $call_string) parse a string like print: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 $value with htmlspecialchars($value)

  • static public function fill_pattern(string $pattern, array $values): string Fill a url pattern like /blog/{slug}/ from an array of values like ['slug'=>'some-post']

  • static public function get_url_params(string $url_pattern): array Parse a pattern like /blog/{slug}/ and return params in the pattern like ['slug']