Procedural File: sonic.inc

Source Location: /sonic.inc



Classes:

Page Details:

main library

generic functions for CLI, utility, curl, http, etc...

Tags:




SONIC_VERSION

[line 17]

SONIC_VERSION = '0.2.23'

[ Top ]


file_mode_contents

boolean file_mode_contents( string $file_name, string $string, [string $mode = 'w'])

[line 223]

file_put_contents() (reserved alias)

write string to filename

Tags:

  • return - true if successful or false at first fail
  • see - file_puts_contents()

Parameters

  • string $file_name - full location to file to be written/appended
  • string $string - data string to write to file
  • string $mode - file write mode, eg. w, a, x

[ Top ]

file_put_contents

boolean file_put_contents( string $file_name, string $string)

[line 206]

Tags:

  • return - see file_put_contents()
  • see - file_puts_contents()

Parameters

  • string $file_name - target path to the data file
  • string $string - the data to write

[ Top ]

sonic_args

array sonic_args( [boolean $argv_shift_opts = false])

[line 1525]

get argv

custom argv manipulator function

Tags:

  • return - array of re-arranged/styled runtime arguments

Parameters

  • boolean $argv_shift_opts - if set to true will overwrite $_SERVER['argv'] with return value

[ Top ]

sonic_args_qsf

array sonic_args_qsf( array $argv)

[line 1490]

argv escaped/quoted string fix

will process standard argv type array and concat/implode where needed eg. escaped characters or quoted strings

Tags:

  • return - array of quoted space corrected runtime style arguments

Parameters

  • array $argv - runtime style arguments with escaped quotes and spaces

[ Top ]

sonic_byte_longhand

integer sonic_byte_longhand( string $size)

[line 1630]

byte, string to integer conversion

reverse map string representation into actual byte amount

Tags:

  • return - byte size as an integer

Parameters

  • string $size - byte size eg. 101K

[ Top ]

sonic_checksum

string sonic_checksum( string $data, [integer $bit_amt = 32])

[line 375]

buffer/string/packet/data checksum

no and den...

Tags:

Parameters

  • string $data - raw data to check+sum
  • integer $bit_amt - checksum of bit amount in size eg. 8, 16, 32, etc

[ Top ]

sonic_datef

string sonic_datef( [string $format = SONIC_DATEF])

[line 1620]

date time

current time by default or supplied date format

Tags:

  • return - time by date formatted string

Parameters

  • string $format - date format string

[ Top ]

sonic_define

array sonic_define( [array $sonic_ini = array()])

[line 66]

environment init. (define defaults)

sets defined constants and sets missing defaults in supplied sonic_ini() array

Tags:

  • return - array of type sonic_ini()

Parameters

  • array $sonic_ini - array of type sonic_ini()

[ Top ]

sonic_ext_check

array sonic_ext_check( array $exts, [boolean $fatal = true])

[line 29]

PHP extension check (core requirement checker)

checks for loaded .dll or .so, will echo on error

Tags:

  • return - array of loaded extensions in list

Parameters

  • array $exts - list of PHP extensions load check
  • boolean $fatal - if set true will exit on failure

[ Top ]

sonic_file_mode_contents

boolean sonic_file_mode_contents( string $file_name, string $string, [string $mode = 'w'], [string $lock_dir = SONIC_TMP_PATH])

[line 168]

file_mode_contents() (lock safe)

write string to filename

Tags:

  • return - true if successful or false at first fail

Parameters

  • string $file_name - full location to file to be written/appended
  • string $string - data string to write to file
  • string $mode - file write mode, eg. w, a, x
  • string $lock_dir - path to directory used for locking

[ Top ]

sonic_header2array

array sonic_header2array( string $header)

[line 1602]

HTTP string to array conversion (header tag filter)

filters all HTTP type header key-paired tags from any given string into array

Tags:

  • return - array of header tags with their respective values

Parameters

  • string $header - string to ciphen HTTP headers from

[ Top ]

sonic_http_env

interger sonic_http_env( string $header_raw, [array $default_index = array('index.php', 'index.html')], [string $tmp_dir = SONIC_TMP_PATH])

[line 442]

sonic_http_env_engine() wrapper

Tags:

  • return - see sonic_http_env_engine()

Parameters

  • string $header_raw - see sonic_http_env_engine()
  • array $default_index - see sonic_http_env_engine()
  • string $tmp_dir - see sonic_http_env_engine()

[ Top ]

sonic_http_env_engine

integer sonic_http_env_engine( string $header_raw, array &$opts)

[line 484]

setup PHP HTTP/CGI Environment

will process given HTTP header key-paired tag formatted string (eg. usually a HTTP request) and prepare and/or set PHP type superglobals for HTTP/CGI type environment

where possible return values can be..

1+: OK

0+: not get|post aka unknown method

-1: bad get|post aka invalid syntax

-2: bad post

-3: script filename does not exist

-4: bad script aka invalid syntax

-5: no default index found

Tags:

  • return - integer where greater than zero equates to true and zero or less false
  • global - array $_GET: the PHP $_GET superglobal
  • global - array $_POST: the PHP $_POST superglobal
  • global - array $_FILES: the PHP $_FILES superglobal
  • global - array $_COOKIE: the PHP $_COOKIE superglobal
  • global - array $_REQUEST: the PHP $_REQUEST superglobal
  • global - array $_SERVER: the PHP $_SERVER superglobal

Parameters

  • string $header_raw - HTTP data (usually a HTTP request) containing header key-paired values
  • array &$opts - option flags, (boolean) set_globals, (boolean) get_globals, (array) default_index, string default_scheme

[ Top ]

sonic_http_env_get

integer sonic_http_env_get( string $header_raw, array &$get_globals, [array $default_index = array('index.php', 'index.html')], [string $tmp_dir = SONIC_TMP_PATH])

[line 422]

sonic_http_env_engine() wrapper

Tags:

  • return - see sonic_http_env_engine()

Parameters

  • string $header_raw - see sonic_http_env_engine()
  • array &$get_globals - see sonic_http_env_engine()
  • array $default_index - see sonic_http_env_engine()
  • string $tmp_dir - see sonic_http_env_engine()

[ Top ]

sonic_http_header_check

array sonic_http_header_check( [array $http_headers_a = array()])

[line 849]

HTTP header check

will make sure that essential header parts are of standard word casing to prevent double hashing of same header via mismatch case indexing

Tags:

  • return - array of HTTP headers of type sonic_header2array()

Parameters

  • array $http_headers_a - HTTP header array, see sonic_header2array()

[ Top ]

sonic_http_header_split

array sonic_http_header_split( string $hresp, array &$hresp_headers, [array $opts = array('header_max' => 5)])

[line 1446]

split HTTP header from body

NB, this function is untested, mainly for sonic_http_request() as CURLOPT_HEADER=1

this function will _not_ return the split of the _first_ HTTP header from its body. WARN, you do not want use this function to prevent HTTP smuggling.

this function will take the last header as the real, final and only header associated with the body. usually you should split the first header and the body will contain any other remaining/smuggled headers (and not be treated as such). however when processing a response from cURL with headers returned, all headers cURL encountered to reach the final header will be returned (and you will probably want to filter them out).

this function will return the split of the _last_ HTTP header from its body.

Tags:

  • return - array with index pair of header and body

Parameters

  • string $hresp - HTTP response
  • array &$hresp_headers - HTTP response header array
  • array $opts - option flags, header_max

[ Top ]

sonic_http_request

mixed sonic_http_request( string $http_request, [array $curl_opt = array('tmp' => SONIC_TMP_PATH, 'default_scheme' => 'http://')])

[line 1288]

HTTP request (via cURL)

NB, HTTP header request must contain the 'Host' tag as the destination

Tags:

  • return - see curl_exec()

Parameters

  • string $http_request - HTTP request to be sent
  • array $curl_opt - option flags, (string) tmp, (string) default_scheme

[ Top ]

sonic_http_request_post

array sonic_http_request_post( string $http_request, &$_FILES_PHP &$_FILES_PHP, [ $tmp_dir = SONIC_TMP_PATH])

[line 1109]

setup $_FILES from HTTP request

process HTTP request and setup PHP superglobal $_FILES type array

Tags:

  • return - array of post data ready to cURL useage

Parameters

  • string $http_request - HTTP request data to process post data from
  • &$_FILES_PHP &$_FILES_PHP - array of PHP type superglobal $_FILES
  • $tmp_dir -

[ Top ]

sonic_http_response

string sonic_http_response( integer $http_response_code, string $http_body, [array $http_headers_a = array()])

[line 899]

form HTTP response from parts

will merge the supplied parts given and fill-in any gaps that are missing to form a single compliant reponse

Tags:

  • return - HTTP compliant response

Parameters

  • integer $http_response_code - response code to merge with response, eg. 200
  • string $http_body - HTTP body data to merge with response
  • array $http_headers_a - array of HTTP headers of type sonic_header2array() to merge with response

[ Top ]

sonic_ini

array sonic_ini( string $filename, [boolean $process_sections = false])

[line 134]

parse_ini_file() SONIC

sets global $_SONIC['SONIC_INI'] from SONIC section of ini file

Tags:

  • return - array of type parse_ini_file()
  • global - array $_SONIC: will set $_SONIC['SONIC_INI'] array

Parameters

  • string $filename - full location to ini file to be parsed
  • boolean $process_sections - see parse_ini_file()

[ Top ]

sonic_mimetype

string sonic_mimetype( string $file)

[line 801]

mimetype

will attempt to use any inbuilt mime_content_type() function first before loading its own

Tags:

  • return - mime type for $file or NULL on any failure

Parameters

  • string $file - location to file requiring mime definition lookup (via filename extension)

[ Top ]

sonic_socket_set_options

ANDed sonic_socket_set_options( resource &$socket, integer $level, [mixed $so_options = SONIC_SOCK_OPTIONS])

[line 268]

socket_set_option()'s

iterate list of socket set options and return summation NB, scalar lists key-paired values will first be cast to their constant equivilant (if it has one) before being assigned as a value

Tags:

  • return - return values from iterated socket_set_option() calls

Parameters

  • resource &$socket - stock socket resource, see PHP sockets
  • integer $level - see socket_set_option()
  • mixed $so_options - string as scalar list or array of key-paired socket options, see socket_set_option()

[ Top ]

sonic_socket_write

integer sonic_socket_write( resource $socket, string $buffer, integer $length, [string $lock_dir = SONIC_TMP_PATH])

[line 323]

socket_write()

socket_write() with write lock wait management

Tags:

  • return - see socket_write()

Parameters

  • resource $socket - see PHP sockets
  • string $buffer - see socket_write()
  • integer $length - see socket_write()
  • string $lock_dir - full path to scratch directory to be used

[ Top ]


Documentation generated on Fri, 12 Sep 2008 19:19:01 +1000 by phpDocumentor 1.4.1