Class phery

Description

Main class

Located in /phery.php (line 31)


	
			
Variable Summary
array $config
Method Summary
static string args (mixed $data, [ $encoding = 'UTF-8'])
static void coalesce ()
static phery factory ([ $config = null])
static string form_for (string $action, string $function, [ $attributes = array()], [phery $phery = null])
static phery instance ([ $config = null])
static bool is_ajax ()
static string link_to (string $title, string $function, [ $attributes = array()], [phery $phery = null])
static string select_for (string $function,  $items, [ $attributes = array()], [phery $phery = null])
phery __construct ([ $config = null])
mixed answer_for (string $alias, [mixed $default = NULL])
phery callback ( $callbacks)
phery config ( $config)
phery data ( $args, mixed $args,...)
void process ([bool $last_call = true])
phery set ( $functions)
void __get ( $name)
void __set ( $name,  $value)
Variables
array $config = null (line 76)

Config

  1.  'exit_allowed',
  2.  'no_stripslashes',
  3.  'exceptions',
  4.  'unobstructive',

array $unobstructive = array() (line 58)

Will call the functions defined in this variable even

if it wasn't sent by AJAX, use it wisely. (good for SEO though)

  • access: public
Methods
static method args (line 220)

Encode PHP code to put inside data-args, usually for updating the data there

  • return: Return json_encode'd and htmlentities'd string
static string args (mixed $data, [ $encoding = 'UTF-8'])
  • mixed $data: Any data that can be converted using json_encode
  • $encoding
static method coalesce (line 809)

Utility function taken from MYSQL

  • access: public
static void coalesce ()
static method factory (line 512)

Create a new instance of phery that can be chained, without the need of assigning it to a variable

static phery factory ([ $config = null])
  • array $config: Associative config array
static method form_for (line 632)

Create a <form> tag with ajax enabled. Must be closed manually with </form>

  • return: The mounted <form> HTML tag
static string form_for (string $action, string $function, [ $attributes = array()], [phery $phery = null])
  • string $action: where to go, can be empty
  • string $function: Registered function name
  • array $attributes:
    1.  array(
    2.  // Confirmation dialog
    3.  'confirm' => 'Are you sure?',
    4.  // Type of call, defaults to JSON (to use phery_response)
    5.  'data-type' => 'json',
    6.  // 'all' submits all elements on the form, even
    7.  // if empty or not checked, disabled also submit disabled elements
    8.  'submit' => array('all' => true'disabled' => true)
    9.  // Set the encoding of the data, defaults to UTF-8
    10.  'encoding' => 'UTF-8',
    11.  );
  • phery $phery: Pass the current instance of phery, so it can check if the functions are defined, and throw exceptions
static method instance (line 447)

Generates just one instance. Useful to use in many included files. Chainable

static phery instance ([ $config = null])
  • array $config: Associative config array
static method is_ajax (line 230)

Check if the current call is an ajax call

static bool is_ajax ()
static method link_to (line 547)

Helper function that generates an ajax link, defaults to "A" tag

  • return: The mounted HTML tag
static string link_to (string $title, string $function, [ $attributes = array()], [phery $phery = null])
  • string $title: The content of the link
  • string $function: The PHP function assigned name on phery::set()
  • array $attributes: Extra attributes that can be passed to the link, like class, style, etc
    1.  array(
    2.  // Display confirmation on click
    3.  'confirm' => 'Are you sure?',
    4.  // The tag for the item, defaults to a
    5.  'tag' => 'a',
    6.  // Define another URI for the AJAX call, this defines the HREF of A
    7.  'href' => '/path/to/url',
    8.  // Extra arguments to pass to the AJAX function, will be stored
    9.  // in the args attribute as a JSON notation
    10.  'args' => array(1"a"),
    11.  // Set the "href" attriute for non-anchor (a) AJAX tags (like buttons or spans).
    12.  // Works for A links too, it won't function without javascript
    13.  'target' => '/default/ajax/controller',
    14.  // Define the data-type for the communication
    15.  'data-type' => 'json'
    16.  // Set the encoding of the data, defaults to UTF-8
    17.  'encoding' => 'UTF-8',
    18.  );
  • phery $phery: Pass the current instance of phery, so it can check if the functions are defined, and throw exceptions
static method select_for (line 712)

Create a <select> element with ajax enabled on "change" event.

  • return: The mounted <select> with <option>s inside
static string select_for (string $function,  $items, [ $attributes = array()], [phery $phery = null])
  • string $function: Registered function name
  • array $items: Options for the select, 'value' => 'text' representation
  • array $attributes:
    1.  array(
    2.  // Confirmation dialog
    3.  'confirm' => 'Are you sure?',
    4.  // Type of call, defaults to JSON (to use phery_response)
    5.  'data-type' => 'json',
    6.  // The URL where it should call
    7.  'target' => '/path/to/php',
    8.  // Extra arguments to pass to the AJAX function, will be stored
    9.  // in the args attribute as a JSON notation
    10.  'args' => array(1"a"),
    11.  // Set the encoding of the data, defaults to UTF-8
    12.  'encoding' => 'UTF-8',
    13.  // The current selected value, or array(1,2) for multiple
    14.  'selected' => 1
    15.  );
  • phery $phery: Pass the current instance of phery, so it can check if the functions are defined, and throw exceptions
Constructor __construct (line 81)

Construct the new phery instance

phery __construct ([ $config = null])
  • $config
answer_for (line 261)

Return the data associatated with a processed unobstructive POST call

  • return: Return $default if no data available, defaults to NULL
mixed answer_for (string $alias, [mixed $default = NULL])
  • string $alias: The name of the alias for the process function
  • mixed $default: Any data that should be returned if there's no answer, defaults to null
callback (line 141)

Set callbacks for pre and post filters.

Callbacks are useful for example, if you have 2 or more AJAX functions, and you need to perform the same data manipulation, like removing an 'id' from the $_POST['args'], or to check for potential CSRF or SQL injection attempts on all the functions, clean data or perform START TRANSACTION for database, etc

phery callback ( $callbacks)
  • array $callbacks:
    1.  array(
    2.  // Set a function to be called BEFORE
    3.  // processing the request, if it's an
    4.  // AJAX to be processed request, can be
    5.  // an array of callbacks
    6.  'pre' => array|function,
    7.  // Set a function to be called AFTER
    8.  // processing the request, if it's an AJAX
    9.  // processed request, can be an array of
    10.  // callbacks
    11.  'post' => array|function
    12.  );
    The callback function should be
    1.  // $additional_args is passed using the callback_data() function, in this case, a pre callback
    2.  function pre_callback($ajax_data$internal_data){
    3.    // Do stuff
    4.    $_POST['args']['id'$additional_args['id'];
    5.    return true;
    6.  }
    7.  // post callback would be to save the data perhaps? Just to keep the code D.R.Y.
    8.  function post_callback($ajax_data$internal_data){
    9.    $this->database->save();
    10.    return true;
    11.  }
    Returning false on the callback will make the process() phase to RETURN, but won't exit. You may manually exit on the post callback if desired Any data that should be modified will be inside $_POST['args'] (can be accessed freely on 'pre', will be passed to the AJAX function)
config (line 412)

Config the current instance of phery

phery config ( $config)
  • array $config: Associative array containing the following options
    1.  array(
    2.  // Defaults to true, stop further script execution
    3.  'exit_allowed' => true/false,
    4.  // Don't apply stripslashes on the args
    5.  'no_stripslashes' => true/false,
    6.  // Throw exceptions on errors
    7.  'exceptions' => true/false,
    8.  // Set the functions that will be called even if is a
    9.  // POST but not an AJAX call
    10.  'unobstructive' => array('function-alias-1','function-alias-2')
    11.  );
data (line 209)

Set any data to pass to the callbacks

phery data ( $args, mixed $args,...)
  • mixed $args,...: Parameters, can be anything
  • $args
process (line 378)

Process the AJAX requests if any

void process ([bool $last_call = true])
  • bool $last_call: Set this to false if any other further calls to process() will happen, otherwise it will exit
set (line 475)

Sets the functions to respond to the ajax call.

For security reasons, these functions should not be available for direct POST/GET requests. These will be set only for AJAX requests as it will only be called in case of an ajax request, to save resources. The answer/process function, must necessarily have the following structure:

  1.  function func($ajax_data$callback_data){
  2.    $r new phery_response// or phery_response::factory();
  3.    // Sometimes the $callback_data will have an item called 'submit_id',
  4.    // is the ID of the calling DOM element.
  5.    // if (isset($callback_data['submit_id'])) {  }
  6.    $r->jquery('#id')->animate(...);
  7.       return $r;
  8.  }

phery set ( $functions)
  • array $functions: An array of functions to register to the instance.
__get (line 797)
  • access: public
void __get ( $name)
  • $name
__set (line 792)
  • access: public
void __set ( $name,  $value)
  • $name
  • $value

Documentation generated on Fri, 08 Jul 2011 23:01:35 -0300 by phpDocumentor 1.4.3