| 1 | 2 | simandl | <?php |
| 2 | | | |
| 3 | | | namespace Phem\ClassLoading; |
| 4 | | | |
| 5 | | | /** |
| 6 | | | * |
| 7 | | | * Loads 3rdParty Libraries outside framework namespaces. |
| 8 | | | * Each of them should be located in separate subdirectory of 3rdParty directory |
| 9 | | | * The subdirectory should contain bootstraper file ([SubdirectoryName]Boot.php) |
| 10 | | | * |
| 11 | | | * @author Jakub PetrĹžĂlka <petrzilka@czweb.net> |
| 12 | | | */ |
| 13 | | | class ThirdPartyLoader extends Loader |
| 14 | | | { |
| 15 | | | public function commit() |
| 16 | | | { |
| 17 | | | $dirContent = scandir(THIRD_PARTY_DIR); |
| 18 | | | |
| 19 | | | foreach ($dirContent as $dirEntry) |
| 20 | | | { |
| 21 | | | |
| 22 | | | if (($dirEntry == ".") || ($dirEntry == "..")) continue; |
| 23 | | | |
| 24 | | | if (is_dir(THIRD_PARTY_DIR . DS . $dirEntry)) |
| 25 | | | { |
| 26 | | | $bootFileName = THIRD_PARTY_DIR . DS . $dirEntry . DS . $dirEntry . BOOTSTRAPER_SUFFIX . '.php'; |
| 27 | | | if (file_exists($bootFileName)) |
| 28 | | | { |
| 29 | | | require_once $bootFileName; |
| 30 | | | |
| 31 | | | //the boot file must contain class named [SubdirectoryName]Boot |
| 32 | | | $bootstraperClass = $dirEntry . BOOTSTRAPER_SUFFIX; |
| 33 | | | if (!class_exists($bootstraperClass)) |
| 34 | | | die("Invalid boot file in dependecy " . $dirEntry); |
| 35 | | | |
| 36 | | | //the class must be descendant of BootStrapper |
| 37 | | | $bootstrapper = new $bootstraperClass(); |
| 38 | | | if (!is_a($bootstrapper, "Phem\ClassLoading\Bootstrapping\Bootstrapper")) |
| 39 | | | die("Bootstraper of component " . $dirEntry . " must be inherited from Bootstraper"); |
| 40 | | | |
| 41 | | | $bootstrapper->init(); |
| 42 | | | } |
| 43 | | | else |
| 44 | | | { |
| 45 | | | die("Bootstraper file for component " . $dirEntry. " not found"); |
| 46 | | | } |
| 47 | | | } |
| 48 | | | } |
| 49 | | | } |
| 50 | | | } |