Source Code Documentation


s2member\includes\functions\class-autoloader.inc.php


  1. <?php
  2. /**
  3. * s2Member class autoloader.
  4. *
  5. * Defines the __autoload function for s2Member classes.
  6. * This highly optimizes s2Member. Giving it a much smaller footprint.
  7. * See: {@link http://www.php.net/manual/en/function.spl-autoload-register.php}
  8. *
  9. * Copyright: © 2009-2011
  10. * {@link http://www.websharks-inc.com/ WebSharks, Inc.}
  11. * (coded in the USA)
  12. *
  13. * Released under the terms of the GNU General Public License.
  14. * You should have received a copy of the GNU General Public License,
  15. * along with this software. In the main directory, see: /licensing/
  16. * If not, see: {@link http://www.gnu.org/licenses/}.
  17. *
  18. * @package s2Member
  19. * @since 3.5
  20. */
  21. if (realpath (__FILE__) === realpath ($_SERVER["SCRIPT_FILENAME"]))
  22. exit ("Do not access this file directly.");
  23.  
  24. if (!function_exists ("ws_plugin__s2member_classes"))
  25. {
  26. /**
  27. * s2Member class autoloader.
  28. *
  29. * The __autoload function for s2Member classes.
  30. * This highly optimizes s2Member. Giving it a much smaller footprint.
  31. * See: {@link http://www.php.net/manual/en/function.spl-autoload-register.php}
  32. *
  33. * @package s2Member
  34. * @since 3.5
  35. *
  36. * @param str $class The class that needs to be loaded. Passed in by PHP itself.
  37. * @return null
  38. */
  39. function ws_plugin__s2member_classes ($class = FALSE)
  40. {
  41. static /* Holds the classes directory location (location is optimized with a static var). */ $c;
  42. static /* All possible dir & sub-directory locations (with a static var). */ $c_class_dirs;
  43.  
  44. if (strpos ($class, "c_ws_plugin__s2member_") === 0 && strpos ($class, "c_ws_plugin__s2member_pro_") === false)
  45. {
  46. $c = /* Configures location of classes. */ (!isset ($c)) ? dirname (dirname (__FILE__)) . "/classes" : $c;
  47. $c_class_dirs = (!isset ($c_class_dirs)) ? array_merge (array ($c), _ws_plugin__s2member_classes_scan_dirs_r ($c)) : $c_class_dirs;
  48.  
  49. $class = str_replace ("_", "-", str_replace ("c_ws_plugin__s2member_", "", $class));
  50.  
  51. foreach /* Start looking for the class. */ ($c_class_dirs as $class_dir)
  52. if ($class_dir === $c || strpos ($class, basename ($class_dir)) === 0)
  53. if (file_exists ($class_dir . "/" . $class . ".inc.php"))
  54. {
  55. include_once $class_dir . "/" . $class . ".inc.php";
  56.  
  57. break /* Now stop looking. */;
  58. }
  59. }
  60. return /* Return for uniformity. */;
  61. }
  62. /**
  63. * Scans recursively for class sub-directories.
  64. *
  65. * Used by the s2Member autoloader.
  66. *
  67. * @package s2Member
  68. * @since 3.5
  69. *
  70. * @param str $starting_dir The directory to start scanning from.
  71. * @return str[] An array of class directories.
  72. */
  73. function _ws_plugin__s2member_classes_scan_dirs_r ($starting_dir = FALSE)
  74. {
  75. $dirs = /* Initialize dirs array. */ array ();
  76.  
  77. foreach (func_get_args () as $starting_dir)
  78. if /* Does this directory exist? */ (is_dir ($starting_dir))
  79. foreach /* Scan this directory. */ (scandir ($starting_dir) as $dir)
  80. if ($dir !== "." && $dir !== ".." && is_dir ($dir = $starting_dir . "/" . $dir))
  81. $dirs = array_merge ($dirs, array ($dir), _ws_plugin__s2member_classes_scan_dirs_r ($dir));
  82.  
  83. return /* Return array of all directories. */ $dirs;
  84. }
  85. spl_autoload_register /* Register __autoload. */ ("ws_plugin__s2member_classes");
  86. }
  87. ?>

s2member\includes\functions\class-autoloader.inc.php

Source Code Documentation