<nephtali>

A simple, flexible, fast, and security-focused PHP framework
Nephtali documentation

API documentation

n\pipe

Pipe functions. In Nephtali, Pipes are responsible for rendering dynamic regions in a page, and controlling the general flow of an application (login mechanisms can be handled by pipes without output.)

Functions

  • mixed get(mixed $names)

    Retrieve the settings for registered pipes. With no argument, all pipes are retrieved.

  • void register(string $name, mixed $function, array $opts, array $args)

    Register a pipe for the page.

    The $opts array can contain the options displayed in the example below:

    n\pipe\register(
    $name = 'workers',
    $function = function($markup, $args, $signatures) {
    // code run within function
    },
    $opts = array(
    // normally nephtali renders pipes in the order registered, but htmlfrag requests sometimes involve pipes in which other pipes are nested
    'required_pipes' => array('drop_down_menu'),
    // port signatures automatically passed into the function as the $signatures argument after being automatically checked for signature and validated
    'signatures' => array('select' => array('city', 'occupation')),
    // by default, pipes are required to have corresponding sections in markup, but you can set 'has_output' to false if the pipe truly has no output needs (e.g., authentication)
    'has_output' => false,
    // by default, registered pipes that have output must have corresponding markup present in the page, but you can set 'is_optional' to true if you want a pipe to be rendered only if the page has corresponding markup (i.e., the opening and closing pipe comments are present.)
    'is_optional' => true
    ),
    // nephtali processes the $args functions when the value in the $args array is first accessed, making it easy to keep logic in the pipe function and keep IO out;
    $args = array(
    	'sql_query_results' => function($signatures) {
    		return n\sql\source\query('SELECT * FROM listings WHERE occupation = :occupation AND city = :city', $inputs = $signatures['select']['values']);
    	}
    );
    

  • void register_action(string $name, array $actions, array $opts)

    Register a pipe that conditionally runs any one of several functions depending upon the ports present on a particular request.

  • void register_pure_display(string $name, array $pipe)

    Register a pure display pipe for the page.

    The $pipe array can contain the values displayed in the example below:

    n\pipe\register_pure_display(
    $name = 'workers',
    $rows_func = function($port_vals){
     // return the rows
    },
    $opts = array(
      // function called to render default view
      'default_func' => function($markup, $rows) {
       //return markup for default view
      },
      // function called to render empty view
      'empty_func' => function($markup) {
       //return markup for empty view
      },
      // function called to render feedback view
      'feedback_func' => function($markup, $rows) {
       //return markup for feedback view
      },
      // ports required to process the pipe
      'required_ports' => array('category_id'),
     // normally nephtali renders pipes in the order registered, but htmlfrag requests sometimes involve pipes in which other pipes are nested
     'required_pipes' => array('drop_down_menu'),
     // by default, registered pipes that have output must have corresponding markup present in the page, but you can set 'is_optional' to true if you want a pipe to be rendered only if the page has corresponding markup (i.e., the opening and closing pipe comments are present.)
     'is_optional' => true,
      // set databinding
      'databinding' => 'form',
      // set optblocks for default view (not used when you set the default_func)
      'optblocks' => array(
        'rating' => function($row){ if (strlen($row['rating'])) return true; return false; }
      ),
      // set whitelist for default view (not used when you set the default_func)
      'whitelists' => array(
        'first_name' => array('<span>','</span>')
      )
    )
    );
    

  • void register_pure_action(string $name, array $actions, array $opts)

    Register a pure action pipe for the page.

    n\pipe\register_pure_action(
    $name = 'worker',
    $actions = array(
      'update' => array(
        'io_func' => function($port_vals){
          // return value that evaluates to true for success or false for failure
        },
        'signature' => array('id','name','status'),
        'message' => 'Worker updated.'
      ),
      'insert' => array(
        'io_func' => function($port_vals){
          // return value that evaluates to true for success or false for failure
        },
        'signature' => array('name','status'),
        'message' => 'Worker inserted.',
        'preconds' => array(
          'view_name' => function($port_vals){
              // return value that evaluates to true for success or false for failure
              // when false, the view named in the associative key is displayed
          }
        )
      ),
      'delete' => array(
        'io_func' => function($port_vals){
          // return value that evaluates to true for success or false for failure
        },
        'signature' => array('did'),
        'message' => function($arg, $port_vals){ return 'Worker deleted. <a href="undo.php?udid=' . $port_vals['did'] . '">Undo</a>';},
        'whitelist' => array(n\constant\WHITELIST_A_TAG)
      )
    ));
    

Nephtali namespaces