yana

phpDocumentor v 1.4.0

Class Yana

Description

«Singleton» Yana
This is a primary controller and application loader for the Yana PHP-Framework.
Example:
  1.  // create instance
  2.  $YANA new Yana("config/system.config"$_REQUEST);
  3.  // handle request
  4.  $YANA->handle($_REQUEST['action']);
  5.  // output results
  6.  $YANA->writeView();
  • access: public
Object
   |
   --Singleton
      |
      --Yana
Variable Summary
Method Summary

Variables

Language $language = null
to load language strings
This variable is «readonly».
  • access: public
PluginManager $plugins = null
to communicate with plugins
This variable is «readonly».
  • access: public
Registry $registry = null
to read and write data to the global registry
This variable is «readonly».
  • access: public
SessionManager $session = null
to read and write user data and permissions
This variable is «readonly».
  • since: 2.9
  • access: public
Skin $skin = null
to load skins and templates
This variable is «readonly».
  • access: public
SmartView $view = null
the currently selected template
This variable is «readonly».
  • since: 2.9.3
  • access: public

Methods

«Singleton» Constructor
Yana Yana (
string $filename, array $ARGS
)
List of parameters:
Name Type Description
$filename string path to system.config
$ARGS array associative array of request vars
Description:
This function creates a new instance of the framework. Note that you may only operate one instance at a time.
Examples:
If you want to use a web interface:
  1.  global $YANA;
  2.  $YANA new Yana("config/system.config"$_REQUEST);
If you want to use a command line interface:
  1.  global $YANA;
  2.  $YANA new Yana("config/system.config"$_SERVER[argv]);
  • access: public
  • uses: new - Yana("config/system.config", $_REQUEST)
clear system cache
void clearCache ()
Description:
Deletes all temporary files in the 'cache/' directory.
This includes templates and preinitialized instances of system objects. Use this function where system settings or profile systems are changed, to make sure changes are applied without delay.
  • access: public
«factory» connect()
mixed &connect (
string $source
)
List of parameters:
Name Type Description
$source string name of the database *.config file that describes the names and structure of tables within the database (see config/db/*.config)
Description:
Returns a ready-to-use database connection.
If you enter more than 1 argument, each additional database structure file will be loaded as well and merged with the others.
Example:
  1.  global $YANA;
  2.  // Connect to database using 'config/db/user.config'
  3.  $db $YANA->connect('user');
  4.  // Connect to database using multiple files
  5.  $db $YANA->connect('user','foo','bar');
  • access: public
exit the current script
void exitTo (
[string $event = '']
)
List of parameters:
Name Type Description
$event string upcoming event to route to
Description:
This will flush error messages and warnings to the screen, write all reported errors (if any) to the framework's logs and then exit the current script. After that it will call itself again to handle the event provided by the argument $event.
You may use the special event 'null' to prevent the framework from handling an event. In this case it will just exit.
If the argument $event is not provided, the default event will be used instead.
Examples:
  1.  global $YANA;
  2.  
  3.  // print an error and go to start page
  4.  $YANA->reportnew Error('404') );
  5.  $YANA->exitTo();
  6.  
  7.  // same as:
  8.  $YANA->exitTo('');
  9.  
  10.  // Use special event 'null' if you just want to
  11.  // view the error message and exit the script
  12.  // without handling another event.
  13.  // ( You may translate this to: "exit to 'nowhere'" )
  14.  $YANA->reportnew Error('500') );
  15.  $YANA->exitTo('null');
  16.  
  17.  // output message and route to 'login' page
  18.  $YANA->reportnew Error('access denied') );
  19.  $YANA->exitTo('login');
Please note: any code followed after a call to this function will never be executed.
  • since: 2.9.0 RC2
  • access: public
get default configuration value
mixed getDefault (
string $key
)
List of parameters:
Name Type Description
$key string adress of data in memory (case insensitive)
Description:
Returns the default value for a given var if any, returns NULL (not false!) if there is none.
Example 1:
  1.  $YANA->getDefault('CONTAINER1.CONTAINER2.DATA');
Example 2:
  1.  if (!isset($foo)) {
  2.      $foo $YANA->getDefault('FOO');
  3.  }
Note: system default values are typically defined in the 'default' section of the 'config/system.config' configurations file.
  • access: public
returns the current profile id
string getId ()
Description:
This is a shortcut for $YANA->getVar('ID').
However it is important to note a slight difference.
  • $YANA->getVar('ID'): The value you get via is available to all plugins and all plugins may read AND write this setting as the developer sees fit. This may mean, that this setting has been subject to changes by some plugin, e.g. to switch between profiles.
  • $YANA->getId(): Always returns the original value, regardless of changes by plugins.
You may want to decide for the behaviour you prefer and choose either one or the other.
  • access: public
get mode of current action
int getMode ()
Description:
Actions can run in two different modes. They can either be:
  • 0 = using profile settings, or
  • 1 = using default settings
Actions may use mode = 1 if they manipulate global system settings, or for security reasons, e.g. when you need global admin rights to execute a certain command.
Example:
  1.  $mode $YANA->getMode();
  2.  if ($mode === 1{
  3.      print "Global settings are active.\n";
  4.  else {
  5.      print "Local settings are active.\n";
  6.  }
  • access: public
get a value from the request vars
mixed getRequestVar (
[string $key = null], [int $method = YANA_REQUEST]
)
List of parameters:
Name Type Description
$key string adress of data in memory (case insensitive)
$method int YANA_REQUEST, YANA_POST, YANA_GET
Description:
Returns the value identified by $key from an untainted, merged copy of the $_POST and $_GET arrays. (Or the input arguments, if the framework is run via a command line interface)
In this case "untainted" means, the result is either a string with at most 50000 characters, or an array of such strings, or the constant NULL if the var does not exist.
If an input string contains a template token, or a '$' character, they are automatically escaped to HTML entities. This is done to reduce the risk of code injection.
Note that this version is case-insensitive. This means "var", "Var" and "VAR" all refer to the same input.
If you call this function without the $key parameter or you use the wildcard '*' the whole "request" array is returned.
The argument $method was added in version 2.9.5. Use this argument to choose wether you want to get vars sent via:
  • YANA_POST = post method
  • YANA_GET = get method
  • YANA_REQUEST = both
Important note: as a feature this function always returns unquoted input, regardless if "magic quotes" is turned on or off. However this does leave it to you to ensure for yourself that input is quoted where needed. If you do not want this feature to be used, this behaviour can be turned off by setting the constant YANA_AUTODEQUOTE to false.
  • access: public
  • name: Yana::getRequestVar()
  • uses: $YANA->getRequestVar('CONTAINER.DATA')
get value from registry
mixed getVar (
string $key
)
List of parameters:
Name Type Description
$key string adress of data in memory (case insensitive)
Description:
Returns var from registry (memory shared by all plugins)
Example:
  1.  $YANA->setVar('foo.bar''Hello World');
  2.  // outputs 'Hello World'
  3.  print $YANA->getVar('foo.bar');
handle an event
bool handle (
[string $event = ""], [array $ARGS = null]
)
List of parameters:
Name Type Description
$event string script action parameter
$ARGS array array of passed arguments
Description:
Resolves event and calls plugin(s), with the given arguments.
Example:
  1.  // handle current event
  2.  $YANA->handle();
  3.  // same as above
  4.  $YANA->handle($_REQUEST['action']$_REQUEST);
  5.  // handle user defined event 'test'
  6.  $myArgs array('foo' => 'bar');
  7.  $success $YANA->handle('test'$myArgs);
  8.  if ($success{
  9.      print "Success!\n";
  10.  else {
  11.      print "Encountered an error.\n";
  12.  }
  • access: public
merges value in registry
bool merge (
string $key, array $array
)
List of parameters:
Name Type Description
$key string adress of data in memory (case insensitive)
$array array associative array to merge
Description:
Merges the value at adresse $key with the provided array data. If a key already exists, it is replaced by the new data.
Example:
  1.  $bar array('foo' => 'bar');
  2.  $YANA->merge('FOO'$bar);
  3.  // outputs 'bar'
  4.  print $YANA->get('FOO.FOO');
  • access: public
  • uses: $YANA->merge('CONTAINER1.CONTAINER2.DATA', - $array)
adds an entry to the log-queue
void report (
Report $log
)
List of parameters:
Name Type Description
$log Report object containing the log entry
Description:
The entry will be printed to screen or written to log-file, depending on it's base-class.
Examples:
  1.  global $YANA;
  2.  // report an error level message
  3.  $msg new Error("Oups! Something went wrong and I can't fix it.");
  4.  $db $YANA->report($msg);
  5.  // report a warning level message
  6.  $msg new Warning("The string 'my dog ate my homework' is not a valid excuse.");
  7.  $db $YANA->report($msg);
  8.  // report an alert level message
  9.  $msg new Alert("Swimming in lava might cause your shorts to catch fire.");
  10.  $db $YANA->report($msg);
  11.  // report a status level message
  12.  $msg new Message("Thanks for your request. All is fine!");
  13.  $db $YANA->report($msg);
  14.  // report a log entry
  15.  $msg new Log("This is a note that goes to the logs.");
  16.  $db $YANA->report($msg);
  • access: public
  • uses: $YANA->report($report)
sets the type of a var on registry (memory shared by all plugins)
bool setType (
string $key, string $type
)
List of parameters:
Name Type Description
$key string adress of data in memory (case insensitive)
$type string new type of variable
Description:
  • access: public
  • uses: $YANA->setType('CONTAINER1.CONTAINER2.DATA', - 'string')
sets var on registry
bool setVar (
string $key, mixed $value
)
List of parameters:
Name Type Description
$key string adress of data in memory (case insensitive)
$value mixed new value (may be scalar value or array)
Description:
The "registry" is memory shared by all plugins.
Example:
  1.  $YANA->setVar('foo.bar''Hello World');
  2.  // outputs 'Hello World'
  3.  print $YANA->getVar('foo.bar');
sets var on registry by Reference
bool setVarByReference (
string $key, mixed &$value
)
List of parameters:
Name Type Description
$key string adress of data in memory (case insensitive)
&$value mixed new value (may be scalar value or array)
Description:
The "registry" is memory shared by all plugins.
Example:
  1.  $bar 'Hello';
  2.  $YANA->setVarByReference('foo.bar'$bar);
  3.  $bar .= ' World';
  4.  // outputs 'Hello World'
  5.  print $YANA->getVar('foo.bar');
  • see: Yana::setVar()
  • see: Yana::getVar()
  • access: public
  • name: Yana::setVarByReference()
  • uses: $YANA->setVar('CONTAINER1.CONTAINER2.DATA', - $value)
remove var from registry
bool unsetVar (
string $key
)
List of parameters:
Name Type Description
$key string adress of data in memory (case insensitive)
Description:
Removes var from registry (memory shared by all plugins). Returns bool(true) on success and bool(false) on error.
Example:
  1.  // set foo.bar
  2.  $YANA->setVar('foo.bar''Hello World');
  3.  // remove foo.bar
  4.  $YANA->unsetVar('foo.bar');
  5.  // foo.bar now is false
  6.  var_dump($YANA->getVar('foo.bar'));
  • access: public
  • uses: $YANA->unsetVar('CONTAINER1.CONTAINER2.DATA')
provides GUI from current data
void writeView ()
Description:
  • access: public
  • uses: $YANA->writeView()
inherited from base classes

Inherited From Singleton

Inherited From Object

Documentation generated on Sat, 03 Jan 2009 22:22:37 +0100 by phpDocumentor 1.4.0

yana author: Thomas MeyerHomepage: www.yanaframework.net