api.autolader.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. //Register and load file classes
  3. spl_autoload_register(function ($className) {
  4. $api_directory = 'api' . DIRECTORY_SEPARATOR;
  5. $libs_directory = 'libs' . DIRECTORY_SEPARATOR;
  6. $venor_directory = 'vendor' . DIRECTORY_SEPARATOR;
  7. // Defined path
  8. $classFileName = strtolower($className);
  9. $apiClassFileName = $api_directory . $libs_directory . 'api.' . $classFileName . '.php';
  10. $vendorClassFileName = $api_directory . $venor_directory . strtolower($className) . DIRECTORY_SEPARATOR . $classFileName . '.php';
  11. if (strpos($className, 'nya_') !== false) {
  12. $notOrmTable = str_replace("nya_", '', $className);
  13. $exec = '
  14. class ' . $className . ' extends NyanORM {
  15. public function __construct() {
  16. parent::__construct();
  17. $this->tableName = "' . $notOrmTable . '";
  18. }
  19. }';
  20. eval($exec); //automatic models generation
  21. } else {
  22. if (file_exists($apiClassFileName)) {
  23. include $apiClassFileName;
  24. } elseif (file_exists($vendorClassFileName)) {
  25. include $vendorClassFileName;
  26. }
  27. }
  28. });