«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:
global $YANA;
$YANA =
new Yana("config/system.config", $_REQUEST);
If you want to use a command line interface:
global $YANA;
$YANA =
new Yana("config/system.config", $_SERVER[argv]);
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.
«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:
global $YANA;
// Connect to database using 'config/db/user.config'
// Connect to database using multiple files
$db =
$YANA->connect('user','foo','bar');
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:
global $YANA;
// print an error and go to start page
// same as:
// Use special event 'null' if you just want to
// view the error message and exit the script
// without handling another event.
// ( You may translate this to: "exit to 'nowhere'" )
// output message and route to 'login' page
Please note: any code followed after a call to this function will never be executed.
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.
Note: system default values are typically defined in the 'default' section of the 'config/system.config' configurations file.
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.
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:
if ($mode === 1) {
print "Global settings are active.\n";
} else {
print "Local settings are active.\n";
}
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.
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:
$YANA->setVar('foo.bar', 'Hello World');
// outputs 'Hello World'
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:
// handle current event
// same as above
$YANA->handle($_REQUEST['action'], $_REQUEST);
// handle user defined event 'test'
$myArgs = array('foo' => 'bar');
$success =
$YANA->handle('test', $myArgs);
if ($success) {
print "Success!\n";
} else {
print "Encountered an error.\n";
}
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:
$bar = array('foo' => 'bar');
$YANA->merge('FOO', $bar);
// outputs 'bar'
print $YANA->get('FOO.FOO');
adds an entry to the log-queue
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:
global $YANA;
// report an error level message
$msg =
new Error("Oups! Something went wrong and I can't fix it.");
// report a warning level message
$msg =
new Warning("The string 'my dog ate my homework' is not a valid excuse.");
// report an alert level message
$msg =
new Alert("Swimming in lava might cause your shorts to catch fire.");
// report a status level message
$msg =
new Message("Thanks for your request. All is fine!");
// report a log entry
$msg =
new Log("This is a note that goes to the logs.");
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:
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:
$YANA->setVar('foo.bar', 'Hello World');
// outputs 'Hello World'
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:
$bar = 'Hello';
$bar .= ' World';
// outputs 'Hello World'
print
$YANA->getVar('foo.bar');
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:
// set foo.bar
$YANA->setVar('foo.bar', 'Hello World');
// remove foo.bar
// foo.bar now is false
provides GUI from current data
void
writeView
()
Description:
inherited from base classes
Inherited From Singleton
Inherited From Object