/framework/ZoopLibrary.php

http://zoop.googlecode.com/ · PHP · 50 lines · 38 code · 6 blank · 6 comment · 5 complexity · e810684a8c592daa01b002aaff5d1e59 MD5 · raw file

  1. <?php
  2. abstract class ZoopLibrary
  3. {
  4. private $mods, $path;
  5. /**
  6. * Stuff about the constructor
  7. *
  8. * @return ZoopLibrary
  9. */
  10. final function __construct($path)
  11. {
  12. $this->path = $path;
  13. $this->mods = array();
  14. $this->init();
  15. }
  16. protected function registerMod($name)
  17. {
  18. if(!isset($this->mods[$name]))
  19. $this->mods[$name] = false;
  20. }
  21. public function hasMod($name)
  22. {
  23. return isset($this->mods[$name]);
  24. }
  25. public function loadMod($name)
  26. {
  27. // if this library doesn't have this module then Zoop will have to figure out which one does
  28. if(!$this->hasMod($name))
  29. return Zoop::loadMod($name);
  30. if(isset($this->mods[$name]) && $this->mods[$name])
  31. return;
  32. $modName = ucfirst($name) . 'Module';
  33. include("$this->path/$name/$modName.php");
  34. $this->mods[$name] = new $modName("$this->path/$name", $this);
  35. }
  36. public function loadMods()
  37. {
  38. foreach($this->mods as $name => $mod)
  39. {
  40. if(!$mod)
  41. $this->loadMod($name);
  42. }
  43. }
  44. }