phpDocumentor PluginSonots
[ class tree: PluginSonots ] [ index: PluginSonots ] [ all elements ]

Class: PluginSonotsOption

Source Location: /sonots/option.class.php

Class PluginSonotsOption

Class Overview

Advanced Option Parser for PukiWiki Plugin

Example1)

  1.   function plugin_hoge_convert()
  2.   {
  3.       $conf_options array(
  4.           'num' => array('number'100),
  5.           'prefix' => array('string''Hoge/'),
  6.       );
  7.       $args func_get_args();
  8.       $line csv_implode(','$args);
  9.       $options PluginSonotsOption::parse_option_line($line);
  10.       list($options$unknowns)
  11.           = PluginSonotsOption::evaluate_options($options$conf_options);
  12.   }

Example2)

  1.   function plugin_hoge_inline()
  2.   {
  3.       $args func_get_args();
  4.       array_pop($args)// drop {}
  5.       $line csv_implode(','$args);
  6.       $options PluginSonotsOption::parse_option_line($line);
  7.       // no $conf_options is also useful
  8.   }

Example3)

  1.   function plugin_hoge_action()
  2.   {
  3.       global $vars;
  4.       $conf_options array(
  5.           'num' => array('number'100),
  6.           'prefix' => array('string''Hoge/'),
  7.       );
  8.       $options $vars;
  9.       list($options$unknowns)
  10.           = PluginSonotsOption::evaluate_options($options$conf_options);
  11.   }

Located in /sonots/option.class.php [line 56]



		
				Author(s):
		
		
		
Information Tags:
Version:  $Id: option.class.php,v 1.10 2008-07-30 11:14:46 sonots $
License:  GPL v2

Methods

[ Top ]
Method Summary
static array   boolean_to_numeric()   Reverse numeric_to_boolean
static array   conv_interval()   Convert ($offset, $length) interval form to ($start, $end) interval form.
static array   evaluate_option()   Evaluate an option
static array   evaluate_options()   Evaluate options
static string   glue_option_line()   Recover option line.
static string   glue_uri_option_line()   Recover option line, but into GET argument style such as
static array   numeric_to_boolean()   Convert numeric key element to boolean value element.
static mixed   parse_interval()   Parse an interval num string
static array   parse_option_line()   Parse option line as followings:
static array   parse_uri_option_line()   Parse option arguments given by GET.

[ Top ]
Methods
static method boolean_to_numeric  [line 236]

  static array boolean_to_numeric( array $options  )

Reverse numeric_to_boolean

Parameters:
array   $options: 

API Tags:
See:  PluginSonotsOption::numeric_to_boolean()
Access:  private
Usedby:  PluginSonotsOption::glue_option_line()

Information Tags:
Version:  $Id: v 1.0 2008-06-07 11:14:46 sonots $
Since:  v 1.4

[ Top ]
static method conv_interval  [line 681]

  static array conv_interval( array $interval, [array $entire = array(1, PHP_INT_MAX)]  )

Convert ($offset, $length) interval form to ($start, $end) interval form.

Example)

  1.   Assume min = 1max = 10
  2.   array(05to array(15)
  3.   array(1nullto array(210)
  4.   array(31to array(44)
  5.   array(-5nullto array(610)
  6.   array(0-4to array(16)

Parameters:
array   $interval:  array(int $offset, int $length)
array   $entire:  array(int $min, int $max)

API Tags:
Return:  array(int $start, int $end)
See:  PluginSonotsOption::parse_interval()
See:  range
Access:  public

Information Tags:
Version:  $Id: v 1.1 2008-07-17 11:14:46 sonots $
Since:  v 1.0

[ Top ]
static method evaluate_option  [line 378]

  static array evaluate_option( mixed $val, string $type, [mixed $conf = null]  )

Evaluate an option

Lists of Supported Types)

  • bool : boolean true or false
  • string : string
  • array : array
  • enum : take only one element of possible values
  • enumarray : take only elements in possible values
  • number : number
  • interval : interval string. See parse_interval for details
  • options : options

Parameters:
mixed   $val:  option value.
string   $type:  option type
mixed   $conf:  config. See evaluate_options.

API Tags:
Return:  array(evaluated value, invalid value)
Access:  private
Usedby:  PluginSonotsOption::evaluate_options()
Uses:  PluginSonotsOption::parse_interval()
Uses:  PluginSonotsOption::evaluate_options()

Information Tags:
Version:  $Id: v 1.7 2008-07-30 11:14:46 sonots $
Since:  v 1.0

[ Top ]
static method evaluate_options  [line 332]

  static array evaluate_options( array $options, array $conf_options  )

Evaluate options

An Example:

  1.   $conf_options array(
  2.          // option  => array(Type, Default, Conf)
  3.         'hierarchy' => array('bool'true),
  4.         'num'       => array('interval'null),
  5.         'filter'    => array('string'null),
  6.         'sort'      => array('enum''name'array('name''reading''date')),
  7.   );
  8.   $options array('filter'=>'AAA');
  9.   list($options$unknownsPluginSonotsOption::evaluate_options($options$conf_options);
  10.   var_export($options)// array('hierarchy'=>true,'num'=>null,'filter'=>'AAA','sort'=>'name')

Another Example with parse_option_line:

  1.   $conf_options array(
  2.          // option  => array(Type, Default, Conf)
  3.         'hierarchy' => array('bool'true),
  4.         'num'       => array('interval'null),
  5.         'filter'    => array('string'null'default'),
  6.         'sort'      => array('enum''name'array('name''reading''date')),
  7.   );
  8.   $optline 'Hoge/,filter,sort=reading';
  9.   $options PluginSonotsOption::parse_option_line($optline);
  10.   var_export($options)// array('Hoge/'=>true,'filter'=>true,'sort'=>'reading')
  11.   list($options$unknownsPluginSonotsOption::evaluate_options($options$conf_options);
  12.   var_export($options)// array('hierarchy'=>true,'num'=>null,'filter'=>'default','sort'=>'reading')
  13.   var_export($unknowns)// array('Hoge/'=>true)

How to Write $conf_options:

   $conf_options is an array of array(Type, Default, Conf)

   Role of Type)
     Specify one of the following types as a string:
     - bool      : boolean true or false
     - string    : string
     - array     : array
     - enum      : take only one element of possible values
     - enumarray : take only elements in possible values
     - number    : number
     - interval  : interval string. @see parse_interval for details
     - options   : options (will be recursively evaluated inside)

   Role of Default)
     It is the default value when the option was not specified by users.

   Role of Conf)
     Basically, the conf also means a default value, but it is for
     when the option was given but the option argument was not given, i.e.,
     the case no "=value" in the option line. Let me call it as default2.
     Concurrently, the conf has a different meaning for following types
     and this was the original main role of conf.
     - enum      : list possible values as an array. As default2,
                   the first element of array is used.
     - enumarray : list possible values as an array. As default2,
                   the entire array is used.
     - options   : $conf_options recursively. As default2, 'options'
                   are recursively configured by $conf_options for this
                   options, thus, defaults in $conf_options are used.

Parameters:
array   $options:  $options[$name] = $value
array   $conf_options:  $conf_options[$name] = array(type, default, conf)

API Tags:
Return:  array($options, $unknowns)
  • $options[$name] = $evaluated_value
  • $unknowns[$unknown_name] = $value
Access:  public
Usedby:  PluginSonotsOption::evaluate_option()
Uses:  PluginSonotsOption::parse_interval()
Uses:  PluginSonotsOption::evaluate_option()

Information Tags:
Version:  $Id: v 1.6 2008-06-12 11:14:46 sonots $
Since:  v 1.0

[ Top ]
static method glue_option_line  [line 127]

  static string glue_option_line( array $options, [boolean $encode = true]  )

Recover option line.

FYI) Encoding is required especially when key/val values include delimiter characters, '=', ',', '(', and ')'. Usually use true.

Parameters:
array   $options: 
boolean   $encode:  perform encode key/val

API Tags:
See:  PluginSonotsOption::parse_option_line()
Access:  public
Uses:  sonots::array_to_string
Uses:  PluginSonotsOption::boolean_to_numeric()

Information Tags:
Version:  $Id: v 1.0 2008-06-07 11:14:46 sonots $
Since:  v 1.4

[ Top ]
static method glue_uri_option_line  [line 149]

  static string glue_uri_option_line( array $options  )

Recover option line, but into GET argument style such as

opt1=val1&opt2=val2&opt3=(a&b) Note that this is not inverse of parse_uri_option_line exactly because parse_uri_option_line assumes input variables are already rawurldecoded, but this performs rawurlencode.

Parameters:
array   $options: 

API Tags:
See:  PluginSonotsOption::parse_uri_option_line()
See:  PluginSonotsOption::glue_option_line()
Access:  public

Information Tags:
Version:  $Id: v 1.0 2008-07-16 11:14:46 sonots $
Since:  v 1.8

[ Top ]
static method numeric_to_boolean  [line 210]

  static array numeric_to_boolean( array $array  )

Convert numeric key element to boolean value element.

By string_to_array,

  1. $string 'foo,bar' => array(0=>'foo',1=>'bar').
Want options as,
  1. $string 'foo,bar' => array('foo'=>true,'bar'=>true).
Perform this conversion.

Parameters:
array   $array: 

API Tags:
See:  PluginSonotsOption::boolean_to_numeric()
Access:  private
Usedby:  PluginSonotsOption::parse_option_line()

Information Tags:
Version:  $Id: v 1.0 2008-06-07 11:14:46 sonots $
Since:  v 1.4

[ Top ]
static method parse_interval  [line 613]

  static mixed parse_interval( string $interval, [int $start = 1]  )

Parse an interval num string

Example)

  1.  1:5   means 1st to 5th returns array(05)
  2.  2:3   means 2nd to 3rd returns array(12)
  3.  2:    means 2nd to end returns array(1null)
  4.  :3    means 1st to 2rd returns array(03)
  5.  4     means 4th returns array(31)
  6.  -5:   means last 5th to end returns array(-5null)
  7.  :-5   means 1st to last 5th returns array(0-4)
  8.  1+2   means 1st to 3rd returns array(03)

Parameters:
string   $interval: 
int   $start:  0|1. Tell where is the offset 0. Default is 1 as example.

API Tags:
Return:  array($offset, $length) or null
See:  array_splice
See:  PluginSonotsOption::conv_interval()
See:  array_slice
Access:  public
Usedby:  PluginSonotsOption::evaluate_option()
Usedby:  PluginSonotsOption::evaluate_options()

Information Tags:
Version:  $Id: v 1.1 2008-07-17 11:14:46 sonots $
Since:  v 1.0

[ Top ]
static method parse_option_line  [line 100]

  static array parse_option_line( string $line, [boolean $trim = false], [boolean $decode = true]  )

Parse option line as followings:

Rule)

  1.  is used to separate options.
  2.  = is used to separate option key (nameand option value.
  3.  (is used if element is an array.

Example)

  1.   $line 'prefix=Hoge/,num=1:5,contents=(num=1,depth=1),hoge';
  2.   $options PluginSonotsOption::parse_option_line($line);
  3.   var_export();
  4.   // array('prefix'=>'Hoge/','num'=>'1:5',
  5.   // 'contents'=>array('num'=>'1','depth'=>'1'),'hoge'=>true);
  6.   // () becomes an array()
  7.   // Option which does not have "=[value]" is set to TRUE anyway.

parse_option_line is upper version of the simple sonots::parse_options($args). parse_options does not support array arguments, but parse_option_line does. Except array arguments, both should be able to generate the same results.

FYI) Decoding is required especially when key/val values include delimiter characters, '=', ',', '(', and ')'. Usually use true.

Parameters:
string   $line: 
boolean   $trim:  trim option key/val
boolean   $decode:  perform decode key/val

API Tags:
Return:  array of options
See:  sonots::parse_options
See:  PluginSonotsOption::glue_option_line()
Access:  public
Uses:  sonots::string_to_array
Uses:  PluginSonotsOption::numeric_to_boolean()

Information Tags:
Version:  $Id: v 1.5 2008-06-07 11:14:46 sonots $
Since:  v 1.0

[ Top ]
static method parse_uri_option_line  [line 182]

  static array parse_uri_option_line( array $vars  )

Parse option arguments given by GET.

1) Assume that the GET argument line was as opt1=val1&opt2=val2&opt3=(a&b) Thus, now you should have in $vars array('opt1'=>'val1','opt2'=>'val2','opt3'=>'(a','b)'=>'') or 2) Assume that the GET argument line was as opt1=val1&opt2=val2&opt3=(a,b) Thus, now you should have in $vars array('opt1'=>'val1','opt2'=>'val2','opt3'=>'(a,b)')

Parameters:
array   $vars: 

API Tags:
See:  PluginSonotsOption::glue_uri_option_line()
See:  PluginSonotsOption::parse_option_line()
Access:  public

Information Tags:
Version:  $Id: v 1.0 2008-07-16 11:14:46 sonots $
Since:  v 1.8

[ Top ]

Documentation generated on Sat, 16 Aug 2008 15:27:31 -0400 by phpDocumentor 1.3.2