Welcome, Guest Log In

Class Krai

Class Overview

This is the framework configuration and initialization functionality class.

This class is responsible for configuring and initializing the rest of the framework. Applications should include this file in the first script. Then the application should call Krai::Setup() with the name of the config file to use, followed by Krai::Run().

Located in /Krai.php [line 26]



		
		
		
		

Properties

Methods

[ Top ]
Descendants
Child Class Description
Krai_Module_Action Action base class
Krai_Module Module base class

[ Top ]
Constant Summary
LOG_ALERT   Logger level constant. These are used with Krai_Log.
LOG_CRITICAL   Logger level constant. These are used with Krai_Log.
LOG_DEBUG   Logger level constant. These are used with Krai_Log.
LOG_EMERG   Logger level constant. These are used with Krai_Log.
LOG_ERROR   Logger level constant. These are used with Krai_Log.
LOG_INFO   Logger level constant. These are used with Krai_Log.
LOG_NOTICE   Logger level constant. These are used with Krai_Log.
LOG_WARNING   Logger level constant. These are used with Krai_Log.

[ Top ]
Property Summary
static string   $APPDIR   Application filesystem root directory variable
static mixed   $DB   Holds the database connections
static Krai_Db   $DB_DEFAULT   Holds the default database connection by reference
static string   $FRAMEWORK   Framwork filesystem directory variable
static array   $GET   Cleaned $_GET copy
static string   $INCLUDES   Application includes directory variable
static Krai_Lib_Inflector   $INFLECTOR   Inflector instance
static string   $LAYOUTS   Application layouts directory variable
static string   $MODULES   Application modules directory variable
static array   $PARAMS   Holds a merger of self::$GET, self::$POST, and some things the router finds
static array   $POST   Cleaned $_POST copy
static string   $REQUEST   The page requested
static Krai_Router   $ROUTER   The router instance
static float   $STARTTIME   Starting micro timestamp
static array   $_BACKLOGS   Framework log message cache
static array   $_CONFIG   Holds the application configuration
static boolean   $_LOGGING   Framework logging flag
static array   $_MESSAGES   Holds the errors and notices
static boolean   $_MIMESET   Flag for whether a MIME type has been set or not
static Nakor   $_NAKOR_CORE   Input scrubbing class instance
static boolean   $_SETUP   Whether or not the application was set up
static boolean   $_STARTED   Whether or not the application was run

[ Top ]
Method Summary
static string   AssocImplode()   A function to implode an associative array preserving keys
static boolean   AutoLoad()   Loads the file for a module or action name
static string   DetermineRequest()   Determines the request to be used from server variables.
static void   EndRun()   Ends the application run after cleaning up
static void   Error()   Save an error message
static mixed   GetConfig()   Gets information from the configuration array Krai::$_CONFIG.
static array   GetErrors()   Returns the logged errors
static array   GetNotices()   Returns the logged notices
static boolean   IsErrors()   Determine whether there are errors or not
static boolean   IsNotices()   Determine whether there are notices or not
static boolean   LoadActionFile()   Tries to load the file for an action
static boolean   LoadModuleFile()   Tries to load the file for a module
static void   Notice()   Save a notice message
static void   ReloadMessages()   Reloads messages from session if available
static void   Run()   Makes everything start up and work
static void   SaveMessages()   Saves messages to the session
static void   SetMime()   Sets the mime-type header for the response
static void   Setup()   This is the configuration function for the framework.
static boolean   Uses()   A wrapper for including files and logging such. Uses http://www.php.net/func_get_args() for variable argument number.
static void   WriteBackLogs()   Writes the back logs to the logger
static void   WriteLog()   Provides an interface to the loghandler, whatever that might be.

[ Top ]
Properties
static string   $APPDIR [line 51]

Application filesystem root directory variable

This variable holds the value of the path to the application root directory. It can be in the config file which is passed to Krai::Setup(). If it is not set, it defaults to the directory holding Krai.php.

API Tags:
Access:  public


[ Top ]
static mixed   $DB = null [line 246]

Holds the database connections

This is either an associative array of database connections as defined in the config file and initialized in Krai::Run(), or a single database if only one was defined.

API Tags:
Access:  public


[ Top ]
static Krai_Db   $DB_DEFAULT = null [line 256]

Holds the default database connection by reference

This variable holds the instance of the first defined database connection in Krai::$DB.

API Tags:
Access:  public


[ Top ]
static string   $FRAMEWORK [line 64]

Framwork filesystem directory variable

This variable holds the value of the path to the framework root directory. The value defaults to to the directory Krai within the directory holding Krai.php. There is currently not a way to alter this, but there is also no expectation that it should need to be altered. The value has no trailing slash.

API Tags:
Access:  public


[ Top ]
static array   $GET = array() [line 224]

Cleaned $_GET copy

This is a copy of the $_GET data having been run through the input scrubber.

API Tags:
Access:  public


[ Top ]
static string   $INCLUDES [line 75]

Application includes directory variable

This variable holds the value of the path to the application includes directory. It gets set to Krai::$APPDIR/includes. The value has no trailing slash.

API Tags:
Access:  public


[ Top ]
static Krai_Lib_Inflector   $INFLECTOR = null [line 118]

Inflector instance

This variable holds an instance of Krai_Lib_Inflector, which can be used to convert from WordsWithUnderscores |-> words_with_underscores and back, among other functionality.

API Tags:
Access:  public


[ Top ]
static string   $LAYOUTS [line 97]

Application layouts directory variable

This variable holds the value of the path to the application layouts directory. It gets set to Krai::$INCLUDES/layouts. The value has no trailing slash.

API Tags:
Access:  public


[ Top ]
static string   $MODULES [line 86]

Application modules directory variable

This variable holds the value of the path to the application modules directory. It gets set to Krai::$INCLUDES/modules. The value has no trailing slash.

API Tags:
Access:  public


[ Top ]
static array   $PARAMS = array() [line 235]

Holds a merger of self::$GET, self::$POST, and some things the router finds

This is a merger of Krai::$GET, Krai::$POST, and some other values as may be determined by Krai_Router in routing a request.

API Tags:
Access:  public


[ Top ]
static array   $POST = array() [line 214]

Cleaned $_POST copy

This is a copy of the $_POST data having been run through the input scrubber.

API Tags:
Access:  public


[ Top ]
static string   $REQUEST [line 130]

The page requested

This variable holds the string of the page that was requested. It is determined either by passing a string to Krai::Run(), or else automatically set by the call to Krai::DetermineRequest() from within Krai::Run().

API Tags:
Access:  public


[ Top ]
static Krai_Router   $ROUTER [line 279]

The router instance

This variable holds the instance of the router to be used for this instance of the application.

API Tags:
Access:  public


[ Top ]
static float   $STARTTIME [line 107]

Starting micro timestamp

This is the http://www.php.net/microtime of more-or-less the start of the framework execution.

API Tags:
Access:  public


[ Top ]
static array   $_BACKLOGS = array() [line 162]

Framework log message cache

This is an array in which to hold log messages that are attempted to be sent to the logger for writing when the logger is not ready.

API Tags:
Access:  private


[ Top ]
static array   $_CONFIG = array() [line 194]

Holds the application configuration

This is an array holding the data that was gleaned from a YAML file when Krai::Setup() was run.

API Tags:
Access:  private


[ Top ]
static boolean   $_LOGGING [line 152]

Framework logging flag

This is a flag representing whether or not application-level logging has been enabled and initialized in the framework. It is used by Krai::WriteLog() to determine whether to try writing the log message or whether to store it for writing when the logger is initialized.

API Tags:
Access:  private


[ Top ]
static array   $_MESSAGES = array(
"errors" => array(),"notices"=>array())
[line 266]

Holds the errors and notices

This array holds the error and notice messages reported by the framework and application.

API Tags:
Access:  private


[ Top ]
static boolean   $_MIMESET = false [line 140]

Flag for whether a MIME type has been set or not

This is a flag representing whether or not a Content-Type header has been sent yet in the script. It is manipulated through Krai::SetMime().

API Tags:
Access:  private


[ Top ]
static Nakor   $_NAKOR_CORE [line 204]

Input scrubbing class instance

This variable holds an instance of the input scrubber. It is used in the Krai::Run() method.

API Tags:
Access:  private


[ Top ]
static boolean   $_SETUP = false [line 183]

Whether or not the application was set up

This is a flag representing whether or not Krai::Setup() has yet been called. This prevents things from being set up twice.

API Tags:
Access:  private


[ Top ]
static boolean   $_STARTED = false [line 172]

Whether or not the application was run

This is a flag representing whether or not Krai::Run() has yet been called. This prevents things from being run twice.

API Tags:
Access:  private


[ Top ]
Methods
static method AssocImplode  [line 740]

  static string AssocImplode( string $majorglue, string $minorglue, $array  )

A function to implode an associative array preserving keys

This function is an extension of http://www.php.net/implode for use when you want to preserve the keys of the array as well.

Parameters:
string   $majorglue:  The glue for between the array entries
string   $minorglue:  The glue for between key => value pairs
array   $array:  The array to implode

API Tags:
Access:  public


[ Top ]
static method AutoLoad  [line 826]

  static boolean AutoLoad( string $_class  )

Loads the file for a module or action name

This function attempts to load the file containing the class named by the parameter. It is configured to have success with modules and actions placed in the usual places.

Parameters:
string   $_class:  The name of the class

API Tags:
Return:  The success of the loading
Access:  public

Information Tags:
Throws:  Exception

[ Top ]
static method DetermineRequest  [line 662]

  static string DetermineRequest( )

Determines the request to be used from server variables.

This function parses the http://www.php.net/$_SERVER REQUEST_URI variable in order to determine what request was actually made (taking into account the BASEURI set in the configuration file). It is called in Krai::Run() unless an overriding request is passed to that function


API Tags:
Return:  The actual request to parse.
Access:  private


[ Top ]
static method EndRun  [line 634]

  static void EndRun( )

Ends the application run after cleaning up

This function cleans everything up, including closing logs, commiting the php session, and setting a Content-type if one was not set in the processed request. Additionally, it flushes the output buffer, and exits the program.


API Tags:
Access:  private


[ Top ]
static method Error  [line 932]

  static void Error( string $message  )

Save an error message

This function records an error message to the message queue

Parameters:
string   $message:  Message to save

API Tags:
Access:  public


[ Top ]
static method GetConfig  [line 314]

  static mixed GetConfig( string $_key  )

Gets information from the configuration array Krai::$_CONFIG.

This method retrieves the values set in the configuration file passed to Krai::Setup(). For instance, if the configuration file had the line

  1.  # snippet from the config file
  2.  BASEURImyapp
Then you can do the following:
  1.  print Krai::GetConfig("BASEURI");
  2.  # => myapp

You can only retrieve the first level of information from the configuration file in this manner. To get lower levels, do the following:

  1.  # snippet from the config file
  2.  CONFIG_CACHE:
  3.    DIR: /some/path
  4.    TIMEOUT3600
  5.  
  6.  # Getting those configuration settings
  7.  $config_cache Krai::GetConfig("CONFIG_CACHE");
  8.  print $config_cache["DIR"];
  9.  # => /some/path

Parameters:
string   $_key:  The name of the configuration key to get

API Tags:
Return:  The value of the key
Access:  public

Information Tags:
Throws:  Exception When the key is not found

[ Top ]
static method GetErrors  [line 981]

  static array GetErrors( )

Returns the logged errors

This function returns the error messages currently in the queue and clears the queue.


API Tags:
Return:  The error messages
Access:  public


[ Top ]
static method GetNotices  [line 996]

  static array GetNotices( )

Returns the logged notices

This function returns the notice messages currently in the queue and clears the queue.


API Tags:
Return:  The notice messages
Access:  public


[ Top ]
static method IsErrors  [line 956]

  static boolean IsErrors( )

Determine whether there are errors or not

This function determines whether any error messages are in the queue


API Tags:
Return:  Whether or not there are errors
Access:  public


[ Top ]
static method IsNotices  [line 968]

  static boolean IsNotices( )

Determine whether there are notices or not

This function determines whether any notice messages are in the queue


API Tags:
Return:  Whether or not there are notices
Access:  public


[ Top ]
static method LoadActionFile  [line 876]

  static boolean LoadActionFile( string $_module, string $_action  )

Tries to load the file for an action

This function attempts to load the file containing a certain action.

Parameters:
string   $_module:  The name of the module of the action
string   $_action:  The name of the action

API Tags:
Return:  The success of the loading
Access:  private

Information Tags:
Throws:  Exception

[ Top ]
static method LoadModuleFile  [line 853]

  static boolean LoadModuleFile( string $_module  )

Tries to load the file for a module

This function attempts to load the file containing a certain module.

Parameters:
string   $_module:  The name of the module

API Tags:
Return:  The success of the loading
Access:  private

Information Tags:
Throws:  Krai_Router_Exception

[ Top ]
static method Notice  [line 944]

  static void Notice( string $message  )

Save a notice message

This function records a notice message to the message queue

Parameters:
string   $message:  Message to save

API Tags:
Access:  public


[ Top ]
static method ReloadMessages  [line 896]

  static void ReloadMessages( )

Reloads messages from session if available

This function reloads notice and error messages that may have been saved in the php session.


API Tags:
Access:  private


[ Top ]
static method Run  [line 459]

  static void Run( [string $_uri = null]  )

Makes everything start up and work

This function starts everything in motion. According to the configuration, it loads and initializes all necessary and sufficient framework components. It initializes database connections, and finally initializes scrubbed versions of input variables.

Parameters:
string   $_uri:  An override for the usually determined request to process

API Tags:
Access:  public

Information Tags:
Throws:  Exception

[ Top ]
static method SaveMessages  [line 920]

  static void SaveMessages( )

Saves messages to the session

This function saves notice and error messages to the session for retrieval at the next request execution.


API Tags:
Access:  private


[ Top ]
static method SetMime  [line 612]

  static void SetMime( string $type, [boolean $force = false]  )

Sets the mime-type header for the response

This function is used to set the Content-type header for a response. It is most often used when the script is outputting an image or JSON. If it is not called by the application on a given request, the Content-type defaults to "text/html" for compatibility. However, some users may want to use "application/xhtml+xml" for strict XHTML compliance.

Parameters:
string   $type:  The mime-type to set
boolean   $force:  Flag to force a reset if the type had previously been set

API Tags:
Access:  public


[ Top ]
static method Setup  [line 343]

  static void Setup( string $_conf_file  )

This is the configuration function for the framework.

This function sets up the framework in preparation of being run. It expects a parameter of a string of the location and name of the YAML configuration file. If the application skeleton is being used, this should be "../includes/configs/krai.yml" from the usual default.php location.

The function sets up the Krai::$APPDIR, Krai::$FRAMEWORK, Krai::$INCLUDES, Krai::$MODULES, and Krai::$LAYOUTS variables, as well as starts a PHP session (unless disabled) and an output buffer (unless disabled).

Parameters:
string   $_conf_file:  The path to the configuration file.

API Tags:
Access:  public

Information Tags:
Throws:  Exception

[ Top ]
static method Uses  [line 695]

  static boolean Uses( )

A wrapper for including files and logging such. Uses http://www.php.net/func_get_args() for variable argument number.

This function accepts an unlimited number of arguments, each of which should be a string of a file that needs to be included into the application execution. The function uses http://www.php.net/include_once, so it is not suitable for files that need to be included multiple times.

Additionally, the function provides logging for all the includes processed through it, at the Krai::LOG_DEBUG level.


API Tags:
Return:  Whether or not the file was included successfully
Access:  public

Information Tags:
Throws:  Exception

[ Top ]
static method WriteBackLogs  [line 792]

  static void WriteBackLogs( )

Writes the back logs to the logger

This function writes the messages stored up in Krai::$_BACKLOGS to the logger. If this is called and the logger is still not initialized, an Exception is thrown.


API Tags:
Access:  private

Information Tags:
Throws:  Exception

[ Top ]
static method WriteLog  [line 767]

  static void WriteLog( string $message, [integer $level = Krai::LOG_INFO], [ $logs = array()], [string $cat = null], [ $forces = array()]  )

Provides an interface to the loghandler, whatever that might be.

This function is a wrapper for the logger currently in use (namely, Krai_Log). If the logger has been started, it writes to the log right away. Otherwise, it writes to the Krai::$_BACKLOGS array, so the log entries can be written if/when the logger gets initialized.

Parameters:
string   $message:  The message to write
integer   $level:  The level of the message
array   $logs:  The identifiers of the logs to which to write (default is the default log)
string   $cat:  The category of the log message
array   $forces:  I forget... the logger is being rewritten anyhow, so this will probably change...

API Tags:
Access:  public


[ Top ]
Constants
LOG_ALERT = LOG_ALERT [line 33]

Logger level constant. These are used with Krai_Log.


[ Top ]
LOG_CRITICAL = LOG_CRIT [line 34]

Logger level constant. These are used with Krai_Log.


[ Top ]
LOG_DEBUG = LOG_DEBUG [line 39]

Logger level constant. These are used with Krai_Log.


[ Top ]
LOG_EMERG = LOG_EMERG [line 32]

Logger level constant. These are used with Krai_Log.


[ Top ]
LOG_ERROR = LOG_ERR [line 35]

Logger level constant. These are used with Krai_Log.


[ Top ]
LOG_INFO = LOG_INFO [line 38]

Logger level constant. These are used with Krai_Log.


[ Top ]
LOG_NOTICE = LOG_NOTICE [line 37]

Logger level constant. These are used with Krai_Log.


[ Top ]
LOG_WARNING = LOG_WARNING [line 36]

Logger level constant. These are used with Krai_Log.


[ Top ]

Documentation generated on Fri, 25 Jul 2008 15:19:25 -0400 by phpDocumentor 1.4.2
Krai Framework site admin credits sitemap valid xhtml?