[ Index ]

PHP Cross Reference of Akelos Framework

title

Body

[close]

/ -> Ak.php (summary)

(no description)

Author: Bermi Ferrer
Copyright: Copyright (c) 2002-2006, Akelos Media, S.L. http://www.akelos.org
License: GNU Lesser General Public License
File Size: 2004 lines (71 kb)
Included or required: 17 times
Referenced: 0 times
Includes or requires: 16 files
 AkZip.php
 AkActionMailer.php
 AkRouter.php
 utils/mime_types.php
 AkPlugin.php
 AkActiveRecord/AkDbAdapter.php
 AkLocaleManager.php
 AkFtp.php
 AkActionWebService/AkActionWebServiceClient.php
 AkLogger.php
 AkConverters/AkRemoteConverter.php
 AkHttpClient.php
 AkConfig.php
 AkCharset.php
 AkProfiler.php
 AkCache.php

Defines 1 class

Ak:: (93 methods):
  db()
  deprecateWarning()
  cache()
  toUrl()
  t()
  locale()
  lang()
  get_url_locale()
  langs()
  base_lang()
  dir()
  file_put_contents()
  file_get_contents()
  file_add_contents()
  file_delete()
  directory_delete()
  make_dir()
  copy()
  _getRestrictedPath()
  url_get_contents()
  trace()
  debug()
  get_object_info()
  get_this_object_methods()
  get_this_object_attributes()
  getLogger()
  get_constants()
  time()
  gmt_time()
  getTimestamp()
  getDate()
  mail()
  profile()
  size()
  select()
  collect()
  delete()
  singleton()
  xml_to_array()
  array_to_xml()
  encrypt()
  decrypt()
  blowfishEncrypt()
  blowfishDecrypt()
  randomString()
  compress()
  uncompress()
  unzip()
  decompress()
  handleStaticCall()
  import()
  import_mailer()
  uses()
  stringToArray()
  toArray()
  pick()
  first()
  last()
  compat()
  convert()
  utf8()
  recode()
  encoding()
  userEncoding()
  strlen_utf8()
  toJson()
  fromJson()
  memory_cache()
  getStatusKey()
  logObjectForModifications()
  resetObjectModificationsWacther()
  objectHasBeenModified()
  call_user_func_array()
  array_sort_by()
  mime_content_type()
  stream()
  _nextPermutation()
  permute()
  uuid()
  test()
  sanitize_include()
  client_api()
  html_entity_decode()
  loadPlugins()
  setStaticVar()
  getStaticVar()
  unsetStaticVar()
  _staticVar()
  parseOptions()
  getSettings()
  getSetting()
  _parseSettingsConstants()
  _getConstant()


Class: Ak  - X-Ref

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

db($dsn = null)   X-Ref
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/

param: string    $dns    A string containing Data Source Name (information
return: resource Php AdoDb instance.

deprecateWarning($message, $fatal=false)   X-Ref

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

cache()   X-Ref
Gets a cache object singleton instance


toUrl($options, $set_routes = false)   X-Ref
No description

t($string, $args = null, $controller = null)   X-Ref
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:

param: string    $string    A string containing the English string to
param: array    $args    An associative array of replacements to make after
return: string The translated string.

locale($locale_setting, $locale = null)   X-Ref
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';

lang($set_language = null)   X-Ref
No description

get_url_locale($set_locale = null)   X-Ref
No description

langs()   X-Ref
No description

base_lang()   X-Ref
No description

dir($path, $options = array()   X-Ref
No description

file_put_contents($file_name, $content, $options = array()   X-Ref
No description

file_get_contents($file_name, $options = array()   X-Ref
No description

file_add_contents($file_name, $content, $options = array()   X-Ref


file_delete($file_name, $options = array()   X-Ref
No description

directory_delete($dir_name, $options = array()   X-Ref
No description

make_dir($path, $options = array()   X-Ref
No description

copy($origin, $target, $options = array()   X-Ref
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

_getRestrictedPath($path, $options = array()   X-Ref
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.

url_get_contents($url, $options = array()   X-Ref
Perform a web request

param: string $url URL we are going to request.
param: array $options Options for current request.
return: string

trace($text = null, $line = null, $file = null)   X-Ref
Trace helper function for development purposes

param: string    $text    Helper text
param: string    $line    Helper line
param: string    $file    Helper file
return: echoes result to screen

debug($data, $_functions=0)   X-Ref
Outputs debug info given a PHP resource (vars, objects,
arrays...)

param: mixed    $data    Data to debug. It can be an object, array,
return: void Prints debug info.

get_object_info($object, $include_inherited_info = false)   X-Ref
Gets information about given object

param: object    &$object    Object to get info from
param: boolean    $include_inherited_info    By setting this to true, parent Object properties
return: string html output with Object info

get_this_object_methods($object)   X-Ref
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

param: object    &$object    Object to inspect
return: array Returns an array with selected object methods. It

get_this_object_attributes($object)   X-Ref
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

param: object    &$object    Object to inspect
return: void Returns an array with selected object attributes.

getLogger()   X-Ref
No description

get_constants()   X-Ref
No description

time()   X-Ref


gmt_time()   X-Ref
No description

getTimestamp($iso_date_or_hour = null)   X-Ref
Gets a timestamp for input date provided in one of this formats: "year-month-day hour:min:sec", "year-month-day", "hour:min:sec"


getDate($timestamp = null, $format = null)   X-Ref
Return formatted date.

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

Default date is in ISO format

mail($from, $to, $subject, $body, $additional_headers = array()   X-Ref
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.


param: $from
param: $to
param: $subject
param: $body
param: additional_headers (optional)   
return: boolean whether message has been sent or not.

profile($message = '')   X-Ref


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


select(&$source_array)   X-Ref
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')
);

collect(&$source_array, $key_index, $value_index)   X-Ref
No description

delete($source_array, $attributes_to_delete_from_array)   X-Ref
No description

singleton($class_name, &$arguments)   X-Ref
No description

xml_to_array($xml_data)   X-Ref
No description

array_to_xml($array, $header = "<?xml version=\"1.0\"?>\r\n", $parent = 'EMPTY_TAG')   X-Ref
No description

encrypt($data, $key = null)   X-Ref
No description

decrypt($encrypted_data, $key = null)   X-Ref
No description

blowfishEncrypt($data, $key = null)   X-Ref
No description

blowfishDecrypt($encrypted_data, $key = null)   X-Ref
No description

randomString($max_length = 8)   X-Ref
No description

compress($data, $format = 'gzip')   X-Ref
No description

uncompress($compressed_data, $format = 'gzip')   X-Ref
No description

unzip($file_to_unzip, $destination_folder)   X-Ref
No description

decompress($compressed_data, $format = 'gzip')   X-Ref
No description

handleStaticCall()   X-Ref
No description

import()   X-Ref
Gets an array or a comma separated list of models. Then it includes its
respective files and returns an array of available models.

return: array available models

import_mailer()   X-Ref
No description

uses()   X-Ref
No description

stringToArray($string)   X-Ref
No description

toArray()   X-Ref
No description

pick($keys, $source_array)   X-Ref
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']));


first()   X-Ref
Gets a copy of the first element of an array. Similar to array_shift but it does not modify the original array


last()   X-Ref
Gets a copy of the last element of an array. Similar to array_pop but it does not modify the original array


compat($function_name)   X-Ref
Includes PHP functions that are not available on current PHP version


convert()   X-Ref
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

utf8($text, $input_string_encoding = null)   X-Ref
Converts given string to UTF-8

param: string $text
param: string $input_string_encoding
return: string UTF-8 encoded string

recode($text, $output_string_encoding = null, $input_string_encoding = null, $recoding_engine = null)   X-Ref
No description

encoding()   X-Ref
No description

userEncoding()   X-Ref
Get the encoding in which current user is sending the request


strlen_utf8($str)   X-Ref
strlen for UTF-8 strings
Taken from anpaza at mail dot ru post at http://php.net/strlen


toJson($php_value)   X-Ref
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.

fromJson($json_string)   X-Ref
Converts a JSON representation string into a PHP value.


memory_cache($key, &$value)   X-Ref
No description

getStatusKey($element)   X-Ref
No description

logObjectForModifications(&$object)   X-Ref
No description

resetObjectModificationsWacther(&$object)   X-Ref
No description

objectHasBeenModified(&$object)   X-Ref
No description

call_user_func_array($function_name, $parameters)   X-Ref
No description

array_sort_by($array, $key = null, $direction = 'asc')   X-Ref
No description

mime_content_type($file)   X-Ref
No description

stream($path, $buffer_size = 4096)   X-Ref
No description

_nextPermutation($p, $size)   X-Ref
No description

permute($array, $join_with = false)   X-Ref
Returns all the possible permutations of given array


uuid()   X-Ref
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.

author: David Holmes <dholmes@cfdsoftware.net>
return: string  A UUID, made up of 32 hex digits and 4 hyphens.

test($test_case_name, $use_sessions = false)   X-Ref
No description

sanitize_include($include, $mode = 'normal')   X-Ref
Use this function for securing includes. This way you can prevent file inclusion attacks


client_api($resource, $options = array()   X-Ref
Returns a PHP Object from an API resource


html_entity_decode($html, $translation_table_or_quote_style = null)   X-Ref
Cross PHP version replacement for html_entity_decode. Emulates PHP5 behaviour on PHP4 on UTF-8 entities


loadPlugins()   X-Ref
Loads the plugins found at app/vendor/plugins


setStaticVar($name,&$value)   X-Ref
No description

getStaticVar($name)   X-Ref
Strategy for unifying in-function static vars used mainly for performance improvements framework-wide.

Before we had

class A{
function b($var){
static $chache;
if(!isset($cache[$var])){
$cache[$var] = some_heavy_function($var);
}
return $cache[$var];
}
}

Now imagine we want to create an application server which handles multiple requests on a single instantiation, with the showcased implementation this is not possible as we can't reset $cache, unless we hack badly every single method that uses this strategy.

We can refresh this static values the new Ak::getStaticVar method. So from previous example we will have to replace

static $chache;

unsetStaticVar($name)   X-Ref
No description

_staticVar($name, &$value, $destruct = false)   X-Ref
No description

parseOptions(&$options, $default_options = array()   X-Ref

param: array $options
param: array $default_options
param: array $available_options
param: boolean $walk_keys

getSettings($namespace, $raise_error_if_config_file_not_found = true, $environment = AK_ENVIRONMENT)   X-Ref
Returns YAML settings from config/$namespace.yml


getSetting($namespace, $variable, $default_value = null)   X-Ref
No description

_parseSettingsConstants($settingsStr)   X-Ref
No description

_getConstant($name)   X-Ref
No description



Generated: Mon Oct 27 12:43:49 2008 Cross-referenced by PHPXref 0.6