Support Joomla!

Joomla! 1.5 Documentation

Packages

Package: Joomla-Framework

Developer Network License

The Joomla! Developer Network content is © copyright 2006 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution- NonCommercial- ShareAlike 2.5
Source code for file /loader.php

Documentation is available at loader.php

  1. <?php
  2. /**
  3. @version $Id: loader.php 6685 2007-02-19 20:04:00Z chrisdavenport $
  4. @package        Joomla.Framework
  5. @copyright    Copyright (C) 2005 - 2007 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.
  27.      * @param string|array$dirs Search these directories for the class.
  28.      * @return void 
  29.      * @since 1.5
  30.      */
  31.     function import$filePath )
  32.     {
  33.         static $paths;
  34.  
  35.         if (!isset($paths))
  36.         {
  37.             $paths array();
  38.         }
  39.  
  40.         if (!isset($paths[$filePath]))
  41.         {
  42.             $paths[$filePathtrue;
  43.  
  44.             $parts explode'.'$filePath );
  45.  
  46.             $base =  dirname__FILE__ );
  47.  
  48.             if(array_pop$parts == '*')
  49.             {
  50.                 $path $base DS implodeDS$parts );
  51.  
  52.                 if (!is_dir$path )) {
  53.                     return false;
  54.                 }
  55.  
  56.                 $dir dir$path );
  57.                 while ($file $dir->read()) {
  58.                     if (preg_match'#(.*?)\.php$#'$file$m )) {
  59.                         $nPath str_replace'*'$m[1]$filePath );
  60.                         // we need to check each file again incase one has a jimport
  61.                         if (!isset($paths[$nPath]))
  62.                         {
  63.                             require_once $path DS $file;
  64.                             $paths[$nPathtrue;
  65.                         }
  66.                     }
  67.                 }
  68.                 $dir->close();
  69.             else {
  70.                 $path str_replace'.'DS$filePath );
  71.                 require_once $base DS $path '.php';
  72.             }
  73.         }
  74.         return true;
  75.     }
  76.  
  77.     /**
  78.      * A common object factory.
  79.      *
  80.      * Assumes that the class constructor takes only one parameter, an associative array of
  81.      * construction options. Attempts to load the class automatically.
  82.      *
  83.      * @access public
  84.      * @param string $class The class name to instantiate.
  85.      * @param array $options An associative array of options (default null).
  86.      * @return object An object instance.
  87.      */
  88.     function &factory($class$options null)
  89.     {
  90.         JLoader::import($class);
  91.         $obj new $class($options);
  92.         return $obj;
  93.     }
  94.  
  95.     /**
  96.      * Custom require_once function to improve preformance
  97.      *
  98.      * @access private
  99.      * @param string $file The path to the file to include
  100.      * @since 1.5
  101.      * @see require_once
  102.      *
  103.      */
  104.     function _requireOnce$file )
  105.     {
  106.         static $paths;
  107.  
  108.         if (!isset($paths)) {
  109.             $paths array();
  110.         }
  111.  
  112.         if(!isset($paths[$file])) {
  113.                 require($file);
  114.             $paths[$filetrue;
  115.         }
  116.     }
  117. }
  118.  
  119. /**
  120.  * Intelligent file importer
  121.  *
  122.  * @access public
  123.  * @param string $path A dot syntax path
  124.  * @since 1.5
  125.  */
  126. function jimport$path {
  127.     return JLoader::import($path);
  128. }
  129. ?>

Documentation generated on Mon, 05 Mar 2007 21:09:53 +0000 by phpDocumentor 1.3.1