Class Ak

(line 44)

Description


Located in File: /Ak.php

Akelos Framework static functions

Ak contains all the Akelos Framework static functions. This class acts like a name space to avoid naming collisions when PHP gets new functions into its core. And also to provide additional functionality to existing PHP functions mantaining the same interface



Class Variables

Summary:

Class Constants

Summary:

Method Detail

Summary:
static resource &db ([ $dsn = null], string $dns)
static void debug (mixed $data, [ $_functions = 0])
static string get_object_info ( $object, [boolean $include_inherited_info = false], object &$object)
static void get_this_object_attributes ( $object, object &$object)
static array get_this_object_methods ( $object, object &$object)
static string t (string $string, [array $args = null], [ $controller = null])
static echoes trace ([string $text = null], [string $line = null], [string $file = null])
void &array_sort_by ( $array, [ $key = null], [ $direction = 'asc'])
void array_to_xml ( $array, [ $header = "<?xml version=\"1.0\"?>\r\n"], [ $parent = 'EMPTY_TAG'])
void base_lang ()
void blowfishDecrypt ( $encrypted_data, [ $key = 'Ak3los-m3D1a'])
void blowfishEncrypt ( $data, [ $key = 'Ak3los-m3D1a'])
void &cache ()
void &call_user_func_array ( $function_name,  $parameters)
void client_api ( $resource, [ $options = array()])
void collect ( &$source_array,  $key_index,  $value_index)
void compat ( $function_name)
void compress ( $data, [ $format = 'gzip'])
void convert ()
void copy ( $origin,  $target, [ $options = array()])
void decompress ( $compressed_data, [ $format = 'gzip'])
void decrypt ( $encrypted_data, [ $key = 'Ak3los-m3D1a'])
void delete ( $source_array,  $attributes_to_delete_from_array)
void deprecateWarning (string $message, [[OPTIONAL] $fatal = false])
void dir ( $path, [ $options = array()])
void directory_delete ( $dir_name, [ $options = array()])
void encoding ()
void encrypt ( $data, [ $key = 'Ak3los-m3D1a'])
void file_add_contents ( $file_name,  $content, [ $options = array()])
void file_delete ( $file_name, [ $options = array()])
void file_get_contents ( $file_name, [ $options = array()])
void file_put_contents ( $file_name,  $content, [ $options = array()])
void fromJson ( $json_string)
void getDate ([ $timestamp = null], [ $format = null])
void &getLogger ()
void getStatusKey ( $element)
void getTimestamp ([ $iso_date_or_hour = null])
void get_constants ()
void get_url_locale ([ $set_locale = null])
void gmt_time ()
void html_entity_decode ( $html, [ $translation_table_or_quote_style = null])
array import ()
void lang ([ $set_language = null])
void langs ()
void &loadPlugins ()
void locale ( $locale_setting, [ $locale = null])
void logObjectForModifications ( &$object)
boolean mail ($from $from, $to $to, $subject $subject, $body $body, [additional_headers $additional_headers = array()])
void make_dir ( $path, [ $options = array()])
void &memory_cache ( $key,  &$value)
void mime_content_type ( $file)
void objectHasBeenModified ( &$object)
void permute ( $array, [ $join_with = false])
void pick ( $keys,  $source_array)
void profile ([ $message = ''])
void randomString ([ $max_length = 8])
void recode ( $text, [ $output_string_encoding = null], [ $input_string_encoding = null])
void sanitize_include ( $include, [ $mode = 'normal'])
void select ( &$source_array)
void &singleton ( $class_name,  &$arguments)
void size ( $element)
void stream ( $path, [ $buffer_size = 4096])
void stringToArray ( $string)
void strlen_utf8 ( $str)
void test ( $test_case_name, [ $use_sessions = false])
void time ()
void toArray ()
void toJson ( $php_value)
void toUrl ( $options, [ $set_routes = false])
void uncompress ( $compressed_data, [ $format = 'gzip'])
void unzip ( $file_to_unzip,  $destination_folder)
string url_get_contents (string $url, [array $options = array()])
void userEncoding ()
void uses ()
string utf8 (string $text, [string $input_string_encoding = null])
string uuid ()
void xml_to_array ( $xml_data)
void _getRestrictedPath ( $path, [ $options = array()])
void _nextPermutation ( $p,  $size)

Static Method db (line 64)

resource &db( [ $dsn = null], string $dns)

Gets an instance of AkDbAdapter

Whenever a database connection is required you can get a reference to the default database connection by doing:

$db =& Ak::db(); // get an adodb instance

AdoDB manual can be found at http://phplens.com/adodb/

Parameters

  • string $dns: A string containing Data Source Name (information regarding database connection) http://phplens.com/adodb/code.initialization.html#dsnsupport
  • $dsn:

Info

  • return - Php AdoDb instance.
  • access - public

Static Method debug (line 618)

void debug( mixed $data, [ $_functions = 0])

Outputs debug info given a PHP resource (vars, objects, arrays...)

Parameters

  • mixed $data: Data to debug. It can be an object, array, resource..
  • $_functions:

Info

  • return - Prints debug info.
  • access - public

Static Method get_object_info (line 690)

string get_object_info( $object, [boolean $include_inherited_info = false], object &$object)

Gets information about given object

Parameters

  • object &$object: Object to get info from
  • boolean $include_inherited_info: By setting this to true, parent Object properties and methods will be included.
  • $object:

Info

  • return - html output with Object info
  • access - public
  • uses - Ak::get_this_object_methods
  • uses - Ak::get_this_object_attributes

Static Method get_this_object_attributes (line 754)

void get_this_object_attributes( $object, object &$object)

Get selected objects default attributes

WARNING: Inherited attributes are not returned by this function. You can fetch them by using PHP native function get_class_vars

Parameters

  • object &$object: Object to inspect
  • $object:

Info

Static Method get_this_object_methods (line 724)

array get_this_object_methods( $object, object &$object)

Gets selected object methods.

WARNING: Inherited methods are not returned by this function. You can fetch them by using PHP native function get_class_methods

Parameters

  • object &$object: Object to inspect
  • $object:

Info

Static Method t (line 139)

string t( string $string, [array $args = null], [ $controller = null])

Translate strings to the current locale.

When using Ak::t(), try to put entire sentences and strings in one Ak::t() call. This makes it easier for translators. HTML markup within translation strings is acceptable, if necessary. The suggested syntax for a link embedded within a translation string is:

Parameters

  • string $string: A string containing the English string to translate.
  • array $args: An associative array of replacements to make after translation. Incidences of any key in this array are replaced with the corresponding value.
  • $controller:

Info

  • return - The translated string.
  • access - public

Static Method trace (line 584)

echoes trace( [string $text = null], [string $line = null], [string $file = null])

Trace helper function for development purposes

Parameters

  • string $text: Helper text
  • string $line: Helper line
  • string $file: Helper file

Info

  • return - result to screen
  • access - public

Method array_sort_by (line 1633)

void &array_sort_by( $array, [ $key = null], [ $direction = 'asc'])

Parameters

  • $array:
  • $key:
  • $direction:

Info

Method array_to_xml (line 1123)

void array_to_xml( $array, [ $header = "<?xml version=\"1.0\"?>\r\n"], [ $parent = 'EMPTY_TAG'])

Parameters

  • $array:
  • $header:
  • $parent:

Info

Method base_lang (line 285)

void base_lang( )

Info

Method blowfishDecrypt (line 1197)

void blowfishDecrypt( $encrypted_data, [ $key = 'Ak3los-m3D1a'])

Parameters

  • $encrypted_data:
  • $key:

Info

Method blowfishEncrypt (line 1188)

void blowfishEncrypt( $data, [ $key = 'Ak3los-m3D1a'])

Parameters

  • $data:
  • $key:

Info

Method cache (line 89)

void &cache( )

Gets a cache object singleton instance

Info

Method call_user_func_array (line 1614)

void &call_user_func_array( $function_name, $parameters)

Parameters

  • $function_name:
  • $parameters:

Info

Method client_api (line 1774)

void client_api( $resource, [ $options = array()])

Returns a PHP Object from an API resource

Parameters

  • $resource:
  • $options:

Info

Method collect (line 1053)

void collect( &$source_array, $key_index, $value_index)

Parameters

  • &$source_array:
  • $key_index:
  • $value_index:

Info

Method compat (line 1373)

void compat( $function_name)

Includes PHP functions that are not available on current PHP version

Parameters

  • $function_name:

Info

Method compress (line 1222)

void compress( $data, [ $format = 'gzip'])

Parameters

  • $data:
  • $format:

Info

Method convert (line 1399)

void convert( )

The Akelos Framework has an standardized way to convert between formats.

You can find available converters on AkConverters

Usage Example: In order to convert from HTML to RTF you just need to call. $rtf = Ak::convert('html','rtf', $my_html_file, array('font_size'=> 24));

Where the last option is an array of options for selected converter.

Previous example is the same as.

$rtf = Ak::convert(array('from'=>'html','to'=>'rtf', 'source' => $my_html_file, 'font_size'=> 24));

In order to create converters, you just need to name them "SourceFormatName + To + DestinationFormatName". Whenever you need to call the, you need to specify the "path" option where your converter is located. The only thing you converter must implement is a convert function. Passes options will be made available as attributes on the converter. If your converter needs to prepare something before the convert method is called, you just need to implement a "init" method. You can avoid this by inspecting passed attributes to your constructor

Info

Method copy (line 484)

void copy( $origin, $target, [ $options = array()])

This static method will copy recursively all the files or directories from one path within an Akelos application to another.

It uses current installation settings, so it can perform copies via the filesystem or via FTP

Parameters

  • $origin:
  • $target:
  • $options:

Info

Method decompress (line 1274)

void decompress( $compressed_data, [ $format = 'gzip'])

Parameters

  • $compressed_data:
  • $format:

Info

Method decrypt (line 1166)

void decrypt( $encrypted_data, [ $key = 'Ak3los-m3D1a'])

Parameters

  • $encrypted_data:
  • $key:

Info

Method delete (line 1068)

void delete( $source_array, $attributes_to_delete_from_array)

Parameters

  • $source_array:
  • $attributes_to_delete_from_array:

Info

Method deprecateWarning (line 74)

void deprecateWarning( string $message, [[OPTIONAL] $fatal = false])

Parameters

  • string $message:
  • [OPTIONAL] $fatal: triggers even in production-mode

Info

Method dir (line 292)

void dir( $path, [ $options = array()])

Parameters

  • $path:
  • $options:

Info

Method directory_delete (line 415)

void directory_delete( $dir_name, [ $options = array()])

Parameters

  • $dir_name:
  • $options:

Info

Method encoding (line 1474)

void encoding( )

Info

Method encrypt (line 1141)

void encrypt( $data, [ $key = 'Ak3los-m3D1a'])

Parameters

  • $data:
  • $key:

Info

Method file_add_contents (line 391)

void file_add_contents( $file_name, $content, [ $options = array()])

Parameters

  • $file_name:
  • $content:
  • $options:

Info

  • todo - Optimize this code (dirty add-on to log command line interpreter results)

Method file_delete (line 397)

void file_delete( $file_name, [ $options = array()])

Parameters

  • $file_name:
  • $options:

Info

Method file_get_contents (line 370)

void file_get_contents( $file_name, [ $options = array()])

Parameters

  • $file_name:
  • $options:

Info

Method file_put_contents (line 326)

void file_put_contents( $file_name, $content, [ $options = array()])

Parameters

  • $file_name:
  • $content:
  • $options:

Info

Method fromJson (line 1548)

void fromJson( $json_string)

Converts a JSON representation string into a PHP value.

Parameters

  • $json_string:

Info

Method getDate (line 847)

void getDate( [ $timestamp = null], [ $format = null])

Return formatted date.

You can supply a format as defined at http://php.net/date

Default date is in ISO format

Parameters

  • $timestamp:
  • $format:

Info

Method getLogger (line 769)

void &getLogger( )

Info

Method getStatusKey (line 1579)

void getStatusKey( $element)

Parameters

  • $element:

Info

Method getTimestamp (line 811)

void getTimestamp( [ $iso_date_or_hour = null])

Gets a timestamp for input date provided in one of this formats: "year-month-day hour:min:sec", "year-month-day", "hour:min:sec"

Parameters

  • $iso_date_or_hour:

Info

Method get_constants (line 781)

void get_constants( )

Info

Method get_url_locale (line 259)

void get_url_locale( [ $set_locale = null])

Parameters

  • $set_locale:

Info

Method gmt_time (line 802)

void gmt_time( )

Info

Method handleStaticCall (line 1280)

void handleStaticCall( )

Info

Method html_entity_decode (line 1792)

void html_entity_decode( $html, [ $translation_table_or_quote_style = null])

Cross PHP version replacement for html_entity_decode. Emulates PHP5 behaviour on PHP4 on UTF-8 entities

Parameters

  • $html:
  • $translation_table_or_quote_style:

Info

Method import (line 1297)

array import( )

Gets an array or a comma separated list of models. Then it includes its respective files and returns an array of available models.

Info

  • return - available models

Method lang (line 251)

void lang( [ $set_language = null])

Parameters

  • $set_language:

Info

Method langs (line 271)

void langs( )

Info

Method loadPlugins (line 1810)

void &loadPlugins( )

Loads the plugins found at app/vendor/plugins

Info

Method locale (line 222)

void locale( $locale_setting, [ $locale = null])

Gets information about current locale from the locale settings on config/locales/LOCALE.php

This are common settings on the locale file: 'description' // Locale description Example. Spanish 'charset' // 'ISO-8859-1'; 'date_time_format' // '%d/%m/%Y %H:%i:%s'; 'date_format' // '%d/%m/%Y'; 'long_date_format' // '%d/%m/%Y'; 'time_format' // '%H:%i'; 'long_time_format' // '%H:%i:%s';

Parameters

  • $locale_setting:
  • $locale:

Info

Method logObjectForModifications (line 1590)

void logObjectForModifications( &$object)

Parameters

  • &$object:

Info

Method mail (line 920)

boolean mail( $from $from, $to $to, $subject $subject, $body $body, [additional_headers $additional_headers = array()])

mail function substitute. Uses the PEAR::Mail() function API.

Messaging subsystem for user communication. See PEAR::Mail() function in PHP documentation for information.

User must declare any of these variables for specify the outgoing method. Currently, only Sendmail and STMP methods are available . Variables for using any of these methods are:

AK_SENDMAIL = 0 AK_SMTP = 1

For future upgrades, you must define which constants must be declared and add the functionality.

NOTE: If messaging method is SMTP, you must declare in config file (/config/config.php) the outgoing SMTP server and the authentication pair user/password as constants AK_SMTP_SERVER, AK_SMTP_USER and AK_SMTP_PASSWORD, respectively.

Parameters

  • $from $from: User who sends the mail.
  • $to $to:

    Receiver, or receivers of the mail.

    The formatting of this string must comply with RFC 2822. Some examples are:

    user@example.com user@example.com, anotheruser@example.com User <user@example.com> User <user@example.com>, Another User <anotheruser@example.com>

  • $subject $subject: Subject of the email to be sent. This must not contain any newline characters, or the mail may not be sent properly.
  • $body $body: Message to be sent.
  • additional_headers $additional_headers:

    (optional)

    Array to be inserted at the end of the email header.

    This is typically used to add extra headers (Bcc) in an associative array, where the array key is the header name (i.e., 'Bcc'), and the array value is the header value (i.e., 'test'). The header produced from those values would be 'Bcc: test'.

Info

  • return - whether message has been sent or not.

Method make_dir (line 455)

void make_dir( $path, [ $options = array()])

Parameters

  • $path:
  • $options:

Info

Method memory_cache (line 1556)

void &memory_cache( $key, &$value)

Parameters

  • $key:
  • &$value:

Info

Method mime_content_type (line 1652)

void mime_content_type( $file)

Parameters

  • $file:

Info

Method objectHasBeenModified (line 1601)

void objectHasBeenModified( &$object)

Parameters

  • &$object:

Info

Method permute (line 1686)

void permute( $array, [ $join_with = false])

Returns all the possible permutations of given array

Parameters

  • $array:
  • $join_with:

Info

Method pick (line 1360)

void pick( $keys, $source_array)

Returns an array including only the elements with provided keys.

This is useful to limit the parameters of an array used by a method.

This utility can be used for modifying arrays which is useful for securing record creation/updating.

If you have this code on a controller

$this->user->setAttributes($this->params['user']);

and your users table has a column named is_admin. All it would take to a malicious user is to modify the page html to add the need field and gain admin privileges.

You could avoid by using the new Ak::pick method which will return and array with desired keys.

$this->user->setAttributes(Ak::pick('name,email', $this->params['user']));

Parameters

  • $keys:
  • $source_array:

Info

Method profile (line 973)

void profile( [ $message = ''])

Parameters

  • $message:

Info

  • todo - move this out of here and use Pear Benchmark instead

Method randomString (line 1207)

void randomString( [ $max_length = 8])

Parameters

  • $max_length:

Info

Method recode (line 1466)

void recode( $text, [ $output_string_encoding = null], [ $input_string_encoding = null])

Parameters

  • $text:
  • $output_string_encoding:
  • $input_string_encoding:

Info

Method resetObjectModificationsWacther (line 1596)

void resetObjectModificationsWacther( &$object)

Parameters

  • &$object:

Info

Method sanitize_include (line 1759)

void sanitize_include( $include, [ $mode = 'normal'])

Use this function for securing includes. This way you can prevent file inclusion attacks

Parameters

  • $include:
  • $mode:

Info

Method select (line 1031)

void select( &$source_array)

Select is a function for selecting items from double depth array.

This is useful when you just need some fields for generating tables, select lists with only desired fields.

$People = array( array('name'=>'Jose','email'=>'jose@example.com','address'=>'Colon, 52'), array('name'=>'Alicia','email'=>'alicia@example.com','address'=>'Mayor, 45'), array('name'=>'Hilario','email'=>'hilario@example.com','address'=>'Carlet, 78'), array('name'=>'Bermi','email'=>'bermi@example.com','address'=>'Vilanova, 33'), );

$people_for_table_generation = Ak::select($People,'name','email');

Now $people_for_table_generation will hold an array with array ( array ('name' => 'Jose','email' => 'jose@example.com'), array ('name' => 'Alicia','email' => 'alicia@example.com'), array ('name' => 'Hilario','email' => 'hilario@example.com'), array ('name' => 'Bermi','email' => 'bermi@example.com') );

Parameters

  • &$source_array:

Info

Method singleton (line 1079)

void &singleton( $class_name, &$arguments)

Parameters

  • $class_name:
  • &$arguments:

Info

Method size (line 992)

void size( $element)

Gets the size of given element. Counts arrays, returns numbers, string length or executes size() method on given object

Parameters

  • $element:

Info

Method stream (line 1661)

void stream( $path, [ $buffer_size = 4096])

Parameters

  • $path:
  • $buffer_size:

Info

Method stringToArray (line 1326)

void stringToArray( $string)

Parameters

  • $string:

Info

Method strlen_utf8 (line 1509)

void strlen_utf8( $str)

strlen for UTF-8 strings

Taken from anpaza at mail dot ru post at http://php.net/strlen

Parameters

  • $str:

Info

Method test (line 1751)

void test( $test_case_name, [ $use_sessions = false])

Parameters

  • $test_case_name:
  • $use_sessions:

Info

Method time (line 797)

void time( )

Info

  • todo - Use timezone time

Method toArray (line 1336)

void toArray( )

Info

Method toJson (line 1537)

void toJson( $php_value)

Convert an arbitrary PHP value into a JSON representation string.

For AJAX driven pages, JSON can come in handy – you can return send JavaScript objects directly from your actions.

Parameters

  • $php_value:

Info

Method toUrl (line 100)

void toUrl( $options, [ $set_routes = false])

Parameters

  • $options:
  • $set_routes:

Info

Method uncompress (line 1243)

void uncompress( $compressed_data, [ $format = 'gzip'])

Parameters

  • $compressed_data:
  • $format:

Info

Method unzip (line 1266)

void unzip( $file_to_unzip, $destination_folder)

Parameters

  • $file_to_unzip:
  • $destination_folder:

Info

Method url_get_contents (line 562)

string url_get_contents( string $url, [array $options = array()])

Perform a web request

Parameters

  • string $url: URL we are going to request.
  • array $options: Options for current request. Options are: * referer: URL that will be set as referer url. Default is current url * params: Parameter for the request. Can be an array of key=>values or a url params string like key=value&key2=value2 * method: In case params are given the will be requested using get method by default. Specify post if get is not what you need.

Info

Method userEncoding (line 1489)

void userEncoding( )

Get the encoding in which current user is sending the request

Info

Method uses (line 1320)

void uses( )

Info

Method utf8 (line 1458)

string utf8( string $text, [string $input_string_encoding = null])

Converts given string to UTF-8

Parameters

  • string $text:
  • string $input_string_encoding:

Info

  • return - UTF-8 encoded string

Method uuid (line 1734)

string uuid( )

Generates a Universally Unique IDentifier, version 4.

RFC 4122 (http://www.ietf.org/rfc/rfc4122.txt) defines a special type of Globally Unique IDentifiers (GUID), as well as several methods for producing them. One such method, described in section 4.4, is based on truly random or pseudo-random number generators, and is therefore implementable in a language like PHP.

We choose to produce pseudo-random numbers with the Mersenne Twister, and to always limit single generated numbers to 16 bits (ie. the decimal value 65535). That is because, even on 32-bit systems, PHP's RAND_MAX will often be the maximum *signed* value, with only the equivalent of 31 significant bits. Producing two 16-bit random numbers to make up a 32-bit one is less efficient, but guarantees that all 32 bits are random.

The algorithm for version 4 UUIDs (ie. those based on random number generators) states that all 128 bits separated into the various fields (32 bits, 16 bits, 16 bits, 8 bits and 8 bits, 48 bits) should be random, except : (a) the version number should be the last 4 bits in the 3rd field, and (b) bits 6 and 7 of the 4th field should be 01. We try to conform to that definition as efficiently as possible, generating smaller values where possible, and minimizing the number of base conversions.

Info

  • return - A UUID, made up of 32 hex digits and 4 hyphens.
  • author - David Holmes <dholmes@cfdsoftware.net>
  • copyright - Copyright (c) CFD Labs, 2006. This function may be used freely for any purpose ; it is distributed without any form of warranty whatsoever.

Method xml_to_array (line 1098)

void xml_to_array( $xml_data)

Parameters

  • $xml_data:

Info

Method _getRestrictedPath (line 532)

void _getRestrictedPath( $path, [ $options = array()])

Returns a path restricting it to a base location

This is used by Akelos to prevent functions namespaced under Ak from writing out of the Akelos base directory for security reasons.

Parameters

  • $path:
  • $options:

Info

Method _nextPermutation (line 1671)

void _nextPermutation( $p, $size)

Parameters

  • $p:
  • $size:

Info

Inherited Variables

Inherited Class Variable Summary

Inherited Methods

Inherited Method Summary


Documentation generated on Tue, 17 Jun 2008 14:22:41 +0200 by phpDocumentor 1.3.2