Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP] classloader
julek12
post
Post #1





Grupa: Zarejestrowani
Postów: 97
Pomógł: 5
Dołączył: 6.02.2009
Skąd: Gorzów Wlkp.

Ostrzeżenie: (0%)
-----


Witam,
mam kod classloadera:
  1. <?php
  2. function classLoader($class_name)
  3. {
  4. $class_file = $_SERVER['DOCUMENT_ROOT'] . '/test/inc/classes/' . $class_name . '.php';
  5.  
  6. if (file_exists($class_file) && is_readable($class_file) && !class_exists($class_name, false))
  7. {
  8. require_once($class_file);
  9. }
  10. else
  11. {
  12. throw new Exception('Class "' . $class_name . '" cannot be found.');
  13. }
  14. }
  15. spl_autoload_extensions('.php');
  16. spl_autoload_register('classLoader');
  17.  
  18. function functionLoader($function_name)
  19. {
  20. $function_file = $_SERVER['DOCUMENT_ROOT'] . '/test/inc/functions/' . $function_name . '.php';
  21.  
  22. if (file_exists($function_file) && is_readable($function_file) && !function_exists($function_name))
  23. {
  24. require_once($function_file);
  25. }
  26. else
  27. {
  28. throw new Exception('Function " ' . $function_name . ' "cannot be found.');
  29. }
  30. }
  31. spl_autoload_extensions('.php');
  32. spl_autoload_register('functionLoader');
  33. ?>


I teraz dołączam go tak:
  1. include($_SERVER['DOCUMENT_ROOT'] . '/test/inc/functions/functions_loader.php');
  2. functionLoader('functions');


Dobrze robię, jeśli mam nazwe klasy np:
  1. $db = new Db_Pdo()
to nie muszę robić
  1. classLoader('db_pdo');
, i zastanawiam, się czy to:
  1. spl_autoload_extensions('.php');
  2. spl_autoload_register('functionLoader');

jest potrzebne

Ten post edytował julek12 22.11.2009, 07:44:26
Go to the top of the page
+Quote Post

Posty w temacie
- julek12   [PHP] classloader   22.11.2009, 07:44:17
- - Zyx   Nie jest potrzebne, tym bardziej, że PHP nie obsłu...   22.11.2009, 10:57:47


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 25.08.2025 - 04:07