Support Joomla!

Packages

Package: Joomla-Framework

License

Content on this site is copyright © 2005 - 2008 Open Source Matters Inc and can be used in accordance with the Joomla! Electronic Documentation License. Some parts of this website may be subject to other licenses.
Source code for file /loader.php

Documentation is available at loader.php

  1. <?php
  2. /**
  3. @version $Id: loader.php 10381 2008-06-01 03:35:53Z pasamio $
  4. @package        Joomla.Framework
  5. @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
  6. @license        GNU/GPL, see LICENSE.php
  7. *  Joomla! is free software. This version may have been modified pursuant
  8. *  to the GNU General Public License, and as distributed it includes or
  9. *  is derivative of works licensed under the GNU General Public License or
  10. *  other free or open source software licenses.
  11. *  See COPYRIGHT.php for copyright notices and details.
  12. */
  13.  
  14. if(!defined('DS')) {
  15.     define'DS'DIRECTORY_SEPARATOR );
  16. }
  17.  
  18. /**
  19.  * @package        Joomla.Framework
  20.  */
  21. class JLoader
  22. {
  23.      /**
  24.      * Loads a class from specified directories.
  25.      *
  26.      * @param string $name    The class name to look for ( dot notation ).
  27.      * @param string $base    Search this directory for the class.
  28.      * @param string $key    String used as a prefix to denote the full path of the file ( dot notation ).
  29.      * @return void 
  30.      * @since 1.5
  31.      */
  32.     function import$filePath$base null$key 'libraries.' )
  33.     {
  34.         static $paths;
  35.  
  36.         if (!isset($paths)) {
  37.             $paths array();
  38.         }
  39.  
  40.         $keyPath $key $key $filePath $filePath;
  41.  
  42.         if (!isset($paths[$keyPath]))
  43.         {
  44.             if $base {
  45.                 $base =  dirname__FILE__ );
  46.             }
  47.  
  48.             $parts explode'.'$filePath );
  49.  
  50.             $classname array_pop$parts );
  51.             switch($classname)
  52.             {
  53.                 case 'helper' :
  54.                     $classname ucfirst(array_pop$parts )).ucfirst($classname);
  55.                     break;
  56.  
  57.                 default :
  58.                     $classname ucfirst($classname);
  59.                     break;
  60.             }
  61.  
  62.             $path  str_replace'.'DS$filePath );
  63.  
  64.             if (strpos($filePath'joomla'=== 0)
  65.             {
  66.                 /*
  67.                  * If we are loading a joomla class prepend the classname with a
  68.                  * capital J.
  69.                  */
  70.                 $classname    'J'.$classname;
  71.                 $classes    JLoader::register($classname$base.DS.$path.'.php');
  72.                 $rs            = isset($classes[strtolower($classname)]);
  73.             }
  74.             else
  75.             {
  76.                 /*
  77.                  * If it is not in the joomla namespace then we have no idea if
  78.                  * it uses our pattern for class names/files so just include.
  79.                  */
  80.                 $rs   include($base.DS.$path.'.php');
  81.             }
  82.  
  83.             $paths[$keyPath$rs;
  84.         }
  85.  
  86.         return $paths[$keyPath];
  87.     }
  88.  
  89.     /**
  90.      * Add a class to autoload
  91.      *
  92.      * @param    string $classname    The class name
  93.      * @param    string $file        Full path to the file that holds the class
  94.      * @return    array|boolean         Array of classes
  95.      * @since     1.5
  96.      */
  97.     function register ($class null$file null)
  98.     {
  99.         static $classes;
  100.  
  101.         if(!isset($classes)) {
  102.             $classes    array();
  103.         }
  104.  
  105.         if($class && is_file($file))
  106.         {
  107.             // Force to lower case.
  108.             $class strtolower($class);
  109.             $classes[$class$file;
  110.  
  111.             // In php4 we load the class immediately.
  112.             if((version_comparephpversion()'5.0' 0)) {
  113.                 JLoader::load($class);
  114.             }
  115.  
  116.         }
  117.  
  118.         return $classes;
  119.     }
  120.  
  121.  
  122.     /**
  123.      * Load the file for a class
  124.      *
  125.      * @access  public
  126.      * @param   string  $class  The class that will be loaded
  127.      * @return  boolean True on success
  128.      * @since   1.5
  129.      */
  130.     function load$class )
  131.     {
  132.         $class strtolower($class)//force to lower case
  133.  
  134.         if (class_exists($class)) {
  135.               return;
  136.         }
  137.  
  138.         $classes JLoader::register();
  139.         if(array_key_existsstrtolower($class)$classes)) {
  140.             include($classes[$class]);
  141.             return true;
  142.         }
  143.         return false;
  144.     }
  145. }
  146.  
  147.  
  148. /**
  149.  * When calling a class that hasn't been defined, __autoload will attempt to
  150.  * include the correct file for that class.
  151.  *
  152.  * This function get's called by PHP. Never call this function yourself.
  153.  *
  154.  * @param     string     $class 
  155.  * @access     public
  156.  * @return  boolean 
  157.  * @since   1.5
  158.  */
  159. function __autoload($class)
  160. {
  161.     if(JLoader::load($class)) {
  162.         return true;
  163.     }
  164.     return false;
  165. }
  166.  
  167. /**
  168.  * Global application exit.
  169.  *
  170.  * This function provides a single exit point for the framework.
  171.  *
  172.  * @param mixed Exit code or string. Defaults to zero.
  173.  */
  174. function jexit($message 0{
  175.     exit($message);
  176. }
  177.  
  178. /**
  179.  * Intelligent file importer
  180.  *
  181.  * @access public
  182.  * @param string $path A dot syntax path
  183.  * @since 1.5
  184.  */
  185. function jimport$path {
  186.     return JLoader::import($path);
  187. }

Documentation generated on Sat, 14 Nov 2009 11:15:34 +0000 by phpDocumentor 1.3.1