AccessInterface.php

<?php

namespace Phad;

interface AccessInterface {

    /**
     * Called after the ItemInfo object is initialized, and allows you to modify it if you choose.
     */
    public function item_initialized(\Phad\ItemInfo $ItemInfo): void;


    /**
     * When `call:something` is added to the `access` attribute of a node, this method is called and must return true or false.
     *
     * @param $caller \Phad\Caller tells you where `call()` is being called from, like did_delete() or can_submit(), etc.
     * @param $what string the thing being called - the string to the right of the colon. In `call:something`, this would be `"something"`
     *
     */
    public function call(\Phad\Caller $caller, string $what, ?\Phad\ItemInfo $ItemInfo, ...$args): bool;

    /**
     * When a template's data is being loaded, either via a query (*default*) or a custom data_loader, every row is passed to this method. For each row that returns `true`, it will be included in the final resultset. 
     *
     * You may wish to always `return true;` from this method and provide access controls on the entire template.
     *
     * If data is passed to your template (*rather than loaded by the template*), then this method will not be called.
     *
     * @param $ItemRow the data being accessed
     * @param $ItemInfo info info about the item
     * @param $ItemName ... the item's name
     *
     * @return bool true to allow the row to be returned. false otherwise.
     */
    public function can_read_row(array $ItemRow, \Phad\ItemInfo $ItemInfo, string $ItemName): bool;


    /**
     * Check if the currently logged-in user has the given role. You may use this to check multiple roles, like `role:a&b&c` or you can use multiple separate role checks like `role:a;role:b;role:c`
     *
     * @param $role string There is no required format for `$role`. In access declarations like `role:whatever`, `$role` is whatever's to the right of the colon.
     */
    public function user_has_role(string $role): bool;

    

}