.

Load Class Reference
[Core]

Wrappers around include functions. More...

List of all members.

Static Public Member Functions

static  add_module_base_dir ($dir)
  Add a new module directory.
static  autoload ($class_name)
static  classes_in_directory ($directory, $classes, $extension= 'cls', $required=true)
  Load a class from given directory respecting overloading.
static  commands ($commands)
  Includes the specified command.
static  components ($classes)
  Includes the specified component.
static  directories ($directories)
  Load all files from directory.
static  enable_module ($modules)
  Adds module path to internal path repository.
static  filename_to_classname ($filename, $appendix=array(), $extension_to_strip= '')
  Turns a file name into a class name by following this rules.
static  files ($files, $order=self::ORDER_OVERLOAD)
  Include files on all directories.
static  first_file ($files)
  Include file, search all directories, but stop if file was found.
static  get_base_directories ($order=self::ORDER_OVERLOAD)
  Returns array of all directories that can contain coponents.
static  get_files_from_directory ($directory, $pattern= '*.php')
  Returns array of files from app, core and modules.
static  get_loaded_modules ()
  An array of all modules loaded.
static  get_module_dir ($module)
  Returns absolute path to given module base dir.
static  helpers ($classes)
  Includes the specified gyro component.
static  interfaces ($classes)
  Includes the specified gyro interface.
static  is_module_loaded ($modname)
  Returns true, if given module was loaded.
static  models ($models)
  Includes the specified model.
static  tools ($tools)
  Includes the specified tool.

Public Attributes

const  ORDER_DECORATORS = 'decorators'
const  ORDER_OVERLOAD = 'overload'

Detailed Description

Wrappers around include functions.

Author:
Gerd Riesselmann

Definition at line 10 of file load.cls.php.


Member Function Documentation

static Load::add_module_base_dir ( dir  )  [static]

Add a new module directory.

Parameters:
$dir  Absolute path to directory

Definition at line 201 of file load.cls.php.

00201                                                          {
00202 //              if (substr($dir, -1, 1) != '/') {
00203 //                      $dir .= '/'; 
00204 //              }
00205                 self::$module_base_dirs[] = rtrim(realpath($dir), '/') . '/';           
00206         }       
static Load::autoload ( class_name  )  [static]

Definition at line 474 of file load.cls.php.

00474                                                      {
00475                 $class_name = strtolower($class_name);
00476                 if (substr($class_name, 0, 3) == 'dao') {
00477                         self::models(substr($class_name, 3));
00478                 }
00479         }
static Load::classes_in_directory ( directory,
classes,
extension = 'cls',
required = true  
) [static]

Load a class from given directory respecting overloading.

Parameters:
string  $directory Subdirectory of component
mixed  $classes Either name of class to load or array of names
string  $extension File extension of class files, e.g. 'cls' will include files of name *.cls.php
Returns:
void
Exceptions:
Exception  if class is not found

Definition at line 344 of file load.cls.php.

00344                                                                                                                 {
00345                 return self::do_load($directory, $classes, $extension, $required);
00346         }
static Load::commands ( commands  )  [static]

Includes the specified command.

Parameters:
mixed  $commands Either name of command to load or array of commads
Returns:
void
Exceptions:
Exception  if command could not be loaded

Definition at line 191 of file load.cls.php.

00191                                                    {
00192                 $args = func_get_args();
00193                 self::do_load('behaviour/commands', $args, 'cmd');
00194         }
static Load::components ( classes  )  [static]

Includes the specified component.

Parameters:
mixed  $classes Either name of class to load or array of names
Returns:
void
Exceptions:
Exception  if item could not be loaded

Definition at line 91 of file load.cls.php.

00091                                                     {
00092                 $args = func_get_args();
00093                 self::do_load('lib/components', $args);
00094         }
static Load::directories ( directories  )  [static]

Load all files from directory.

Parameters:
mixed  $directories Either name of directory to load or array of directories
Returns:
void
Exceptions:
Exception  if directory does not exist

Definition at line 140 of file load.cls.php.

00140                                                          {
00141                 $basedirs = self::get_base_directories(self::ORDER_DECORATORS);
00142                 $arr_directories = self::to_array(func_get_args());
00143                 foreach($arr_directories as $directory) {
00144                         $found = false;
00145                         foreach($basedirs as $basedir) {
00146                                 $path = $basedir . $directory;
00147                                         if (is_dir($path)) {
00148                                                 $found = true;
00149                                                 foreach (gyro_glob($path . '/*.php') as $inc) {
00150                                                         include_once($inc);
00151                                                 }
00152                                         }
00153                         }
00154                         if (!$found) {
00155                                 throw new Exception("Directory $directory not found");
00156                         }
00157                 }
00158         }
static Load::enable_module ( modules  )  [static]

Adds module path to internal path repository.

You may either pass a name or an absoulte path. If given a name, Gyro expects the module to be located beneath the Gyro modules directory

If a file enabled.inc.php exists beneath the module's root directory, it is included here. Use this to enable other modules, this modules depends on

Parameters:
mixed  $modules Either name or directory of module to load or array of names and directories
Returns:
void
Exceptions:
Exception  if directory does not exist

Definition at line 221 of file load.cls.php.

00221                                                        {
00222                 $modules = self::to_array($modules);
00223                 foreach($modules as $module) {
00224                         $mod_name = $module;
00225                         if (substr($module, 0, 1) != '/') {
00226                                 foreach(self::$module_base_dirs as $module_base_dir) {
00227                                         $module = $module_base_dir . $mod_name;
00228                                         if (file_exists($module)) {
00229                                                 break;
00230                                         }
00231                                 }
00232                         }
00233                         if (substr($module, -1, 1) != '/') {
00234                                 $module .= '/'; 
00235                         }
00236                         // Path is resolved.
00237                         if (!in_array($module, self::$module_dirs)) {
00238                                 // Don't load twice if it's alright
00239                                 if (!is_dir($module)) {
00240                                         throw new Exception("Module $module not found");
00241                                 }
00242                                 if (file_exists($module . 'enabled.inc.php')) {
00243                                         include_once($module . 'enabled.inc.php');
00244                                 }
00245                                 self::$module_dirs[$mod_name] = $module;
00246                         }
00247                 }
00248                 self::$base_dir_cache = array();
00249         }
static Load::filename_to_classname ( filename,
appendix = array(),
extension_to_strip = ''  
) [static]

Turns a file name into a class name by following this rules.

  • All parts are converted to Camel Casing
  • Parts are created by exploding filename at '.','_' or any other whitespace character
  • $appendix are added to Parts
Attention:
Existence of class is not checked! Just a string is returned

For example

 filename_to_classname('validate.content.cmd.php', array('some_model', 'Command'), $extension_to_strip = 'cmd')

will return "ValidateContentSomeModelCommand"

Parameters:
string  $filename
array|string  $appendix
string  $extension_to_strip File extension that gets stripped of filename (.php will be stripped always)
Returns:
string

Definition at line 52 of file load.cls.php.

00052                                                                                                                {
00053                 $filename = basename($filename, '.php');
00054                 $filename = basename($filename, '.' . $extension_to_strip);
00055                 
00056                 $appendix = Arr::force($appendix, false); 
00057                 foreach($appendix as $t) {
00058                         $filename .= '.' . $t;
00059                 }
00060 
00061                 $filename = str_replace('_', '.', $filename);
00062                 $filename = String::plain_ascii($filename, '.', true);
00063                 $cls = '';
00064                 $fragments = explode('.', $filename);
00065                 foreach($fragments as $f) {
00066                         $cls .= ucfirst($f); // $f is ASCII!
00067                 }
00068 
00069                 return $cls;
00070         }
static Load::files ( files,
order = self::ORDER_OVERLOAD  
) [static]

Include files on all directories.

Parameters:
mixed  $fiels Either filename array of filenames
$order  Either ORDER_OVERLOAD or ORDER_DECORATORS
Returns:
bool True on success

Definition at line 286 of file load.cls.php.

00286                                                                           {
00287                 $files = self::to_array($files);
00288                 $ret = true;
00289                 foreach($files as $file) {
00290                         $ret = $ret && self::do_include_file($file, false, $order);     
00291                 }
00292                 return $ret;
00293         }
static Load::first_file ( files  )  [static]

Include file, search all directories, but stop if file was found.

Parameters:
mixed  $files Either filename array of filenames
Returns:
bool True, if all files where found, false otherwise

Definition at line 301 of file load.cls.php.

00301                                                   {
00302                 $files = self::to_array(func_get_args());
00303                 $ret = true;
00304                 foreach($files as $file) {
00305                         $ret = $ret && self::do_include_file($file, true);      
00306                 }
00307                 return $ret;
00308         }
static Load::get_base_directories ( order = self::ORDER_OVERLOAD  )  [static]

Returns array of all directories that can contain coponents.

Dependend on $order the order of directories is:

ORDER_OVERLOAD: application directory, module directories in descending order of initialization, and the gyro core dir. ORDER_DECORATOR: core directory, module directories in order of initialization, application directoy

Parameters:
$order  Either ORDER_OVERLOAD or ORDER_DECORATORS
Returns:
array

Definition at line 425 of file load.cls.php.

00425                                                                                  {
00426                 $ret = Arr::get_item(self::$base_dir_cache, $order, false);
00427                 if ($ret !== false) {
00428                         return $ret;
00429                 }
00430                 
00431                 $ret = self::$module_dirs;
00432                 switch($order) {
00433                         case self::ORDER_OVERLOAD:
00434                                 $ret = array_reverse($ret);
00435                                 array_unshift($ret, APP_INCLUDE_ABSPATH);
00436                                 $ret[] = GYRO_CORE_DIR;
00437                                 break;
00438                         case self::ORDER_DECORATORS:
00439                                 array_unshift($ret, GYRO_CORE_DIR);
00440                                 $ret[] = APP_INCLUDE_ABSPATH;                           
00441                                 break;
00442                         default:
00443                                 throw new Exception('Invalid sort order in Load::get_base_directories');
00444                                 break;
00445                 }
00446 
00447                 self::$base_dir_cache[$order] = $ret;
00448                 return $ret;
00449         }
static Load::get_files_from_directory ( directory,
pattern = '*.php'  
) [static]

Returns array of files from app, core and modules.

Parameters:
string  $directory
string  $pattern

Definition at line 166 of file load.cls.php.

00166                                                                                         {
00167                 $basedirs = self::get_base_directories_subdirs($directory, self::ORDER_DECORATORS);
00168                 $found = false;
00169                 $ret = array();
00170                 foreach($basedirs as $path) {
00171                         $found = true;
00172                         foreach (gyro_glob($path . $pattern) as $inc) {
00173                                 $ret[basename($inc)] = $inc;
00174                         }
00175                 }
00176                 
00177                 if (!$found) {
00178                         throw new Exception("Directory $directory not found");
00179                 }
00180                 
00181                 return $ret;
00182         }
static Load::get_loaded_modules (  )  [static]

An array of all modules loaded.

Returns:
array

Definition at line 266 of file load.cls.php.

00266                                                     {
00267                 return array_keys(self::$module_dirs);
00268         }
static Load::get_module_dir ( module  )  [static]

Returns absolute path to given module base dir.

Parameters:
string  $module
Returns:
string

Definition at line 257 of file load.cls.php.

00257                                                        {
00258                 return Arr::get_item(self::$module_dirs, $module, false);
00259         }
static Load::helpers ( classes  )  [static]

Includes the specified gyro component.

Parameters:
mixed  $classes Either name of class to load or array of names
Returns:
void
Exceptions:
Exception  if item could not be loaded

Definition at line 79 of file load.cls.php.

00079                                                  {
00080                 $args = func_get_args();
00081                 self::do_load('lib/helpers', $args);
00082         }
static Load::interfaces ( classes  )  [static]

Includes the specified gyro interface.

Parameters:
mixed  $classes Either name of class to load or array of names
Returns:
void
Exceptions:
Exception  if item could not be loaded

Definition at line 103 of file load.cls.php.

00103                                                     {
00104                 $args = func_get_args();
00105                 self::do_load('lib/interfaces', $args);
00106         }
static Load::is_module_loaded ( modname  )  [static]

Returns true, if given module was loaded.

Parameters:
string  $modname

Definition at line 275 of file load.cls.php.

00275                                                           {
00276                 return in_array($modname, self::get_loaded_modules());
00277         }
static Load::models ( models  )  [static]

Includes the specified model.

Parameters:
mixed  $models Either name of model to load or array of names
Returns:
void
Exceptions:
Exception  if item could not be loaded

Definition at line 115 of file load.cls.php.

00115                                                {
00116                 $args = func_get_args(); 
00117                 self::do_load('model/classes', $args, 'model', false);
00118                 self::do_load('model/classes', $args, 'facade', false);
00119         }       
static Load::tools ( tools  )  [static]

Includes the specified tool.

Parameters:
mixed  $tools Either name of tool to load or array of names
Returns:
void
Exceptions:
Exception  if item could not be loaded

Definition at line 128 of file load.cls.php.

00128                                              {
00129                 $args = func_get_args();
00130                 self::do_load('controller/tools', $args);
00131         }       

Member Data Documentation

const Load::ORDER_DECORATORS = 'decorators'

Definition at line 12 of file load.cls.php.

const Load::ORDER_OVERLOAD = 'overload'

Definition at line 11 of file load.cls.php.


The documentation for this class was generated from the following file: