Skip to content

Commit f89ecdd

Browse files
committed
Autoloader improved
1 parent e7f2001 commit f89ecdd

File tree

12 files changed

+189
-115
lines changed

12 files changed

+189
-115
lines changed

_tools/studio/application/Autoloaders/StudioClasses.php renamed to _tools/studio/application/Autoloaders/01_StudioClasses.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@
1414
/**
1515
*
1616
*/
17-
class Autoloader_StudioClasses extends Autoloader_Loader
17+
return new class extends Autoloader_Loader
1818
{
19-
19+
/**
20+
* @return string
21+
*/
22+
public function getAutoloaderCode() : string
23+
{
24+
return 'JetStudio/Classes';
25+
}
2026
/**
2127
*
2228
* @param string $root_namespace
@@ -34,9 +40,7 @@ public function getScriptPath( string $root_namespace, string $namespace, string
3440
return false;
3541
}
3642

37-
$class_name = str_replace( '_', DIRECTORY_SEPARATOR, $class_name );
38-
39-
return SysConf_Path::getApplication() . 'Classes/' . $class_name . '.php';
43+
return SysConf_Path::getApplication() . 'Classes/' . $this->classNameToPath($class_name);
4044

4145
}
42-
}
46+
};

_tools/studio/application/Autoloaders/ModuleWizards.php renamed to _tools/studio/application/Autoloaders/02_ModuleWizards.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@
1313
/**
1414
*
1515
*/
16-
class Autoloader_ModuleWizards extends Autoloader_Loader
16+
return new class extends Autoloader_Loader
1717
{
18+
/**
19+
* @return string
20+
*/
21+
public function getAutoloaderCode() : string
22+
{
23+
return 'JetStudio/ModuleWizards';
24+
}
1825

1926
/**
2027
*
@@ -37,5 +44,4 @@ public function getScriptPath( string $root_namespace, string $namespace, string
3744
return ModuleWizards::getBasePath() . $path . '.php';
3845

3946
}
40-
}
41-
47+
};

_tools/studio/application/Autoloaders/ProjectClasses.php renamed to _tools/studio/application/Autoloaders/10_ProjectClasses.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,15 @@
1313
/**
1414
*
1515
*/
16-
class Autoloader_ProjectClasses extends Autoloader_Loader
16+
return new class extends Autoloader_Loader
1717
{
18+
/**
19+
* @return string
20+
*/
21+
public function getAutoloaderCode() : string
22+
{
23+
return 'application/Classes';
24+
}
1825

1926
/**
2027
*
@@ -30,8 +37,6 @@ public function getScriptPath( string $root_namespace, string $namespace, string
3037
return false;
3138
}
3239

33-
$class_name = str_replace( '_', DIRECTORY_SEPARATOR, $class_name );
34-
35-
return ProjectConf_Path::getApplicationClasses() . $class_name . '.php';
40+
return ProjectConf_Path::getApplicationClasses() . $this->classNameToPath( $class_name );
3641
}
37-
}
42+
};

_tools/studio/application/Autoloaders/ProjectModules.php renamed to _tools/studio/application/Autoloaders/11_ProjectModules.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,15 @@
1414
/**
1515
*
1616
*/
17-
class Autoloader_ProjectModules extends Autoloader_Loader
17+
return new class extends Autoloader_Loader
1818
{
19-
19+
/**
20+
* @return string
21+
*/
22+
public function getAutoloaderCode() : string
23+
{
24+
return 'application/Modules';
25+
}
2026
/**
2127
*
2228
* @param string $root_namespace
@@ -40,4 +46,4 @@ public function getScriptPath( string $root_namespace, string $namespace, string
4046

4147
return $module_path . $class_name . '.php';
4248
}
43-
}
49+
};

_tools/studio/application/Init/Autoloader.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,9 @@
1919

2020

2121
Autoloader::initialize();
22-
23-
24-
require SysConf_Path::getApplication() . 'Autoloaders/Jet.php';
25-
Autoloader_Jet::register();
26-
27-
require SysConf_Path::getApplication() . 'Autoloaders/StudioClasses.php';
28-
Autoloader_StudioClasses::register();
29-
30-
require SysConf_Path::getApplication() . 'Autoloaders/ModuleWizards.php';
31-
Autoloader_ModuleWizards::register();
32-
33-
require SysConf_Path::getApplication() . 'Autoloaders/ProjectClasses.php';
34-
Autoloader_ProjectClasses::register();
35-
36-
require SysConf_Path::getApplication() . 'Autoloaders/ProjectModules.php';
37-
Autoloader_ProjectModules::register();
22+
Autoloader::registerLibraryAutoloaders();
23+
Autoloader::registerApplicationAutoloaders();
24+
Autoloader::initComposerAutoloader();
3825

3926

4027
//Debug_Profiler::blockEnd('INIT - Autoloader');

application/Autoloaders/ApplicationClasses.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@
66
* @author Miroslav Marek <mirek.marek@web-jet.cz>
77
*/
88

9-
namespace JetApplication;
10-
119
use Jet\Autoloader_Loader;
1210
use Jet\SysConf_Path;
1311

1412
/**
1513
*
1614
*/
17-
class Autoloader_ApplicationClasses extends Autoloader_Loader
15+
return new class extends Autoloader_Loader
1816
{
17+
/**
18+
* @return string
19+
*/
20+
public function getAutoloaderCode() : string
21+
{
22+
return 'application/Classes';
23+
}
1924

2025
/**
2126
*
@@ -32,9 +37,7 @@ public function getScriptPath( string $root_namespace, string $namespace, string
3237
return false;
3338
}
3439

35-
$class_name = str_replace( '_', DIRECTORY_SEPARATOR, $class_name );
36-
37-
return SysConf_Path::getApplication() . 'Classes/' . $class_name . '.php';
40+
return SysConf_Path::getApplication() . 'Classes/' . $this->classNameToPath( $class_name );
3841

3942
}
40-
}
43+
};

application/Autoloaders/ApplicationModules.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,22 @@
66
* @author Miroslav Marek <mirek.marek@web-jet.cz>
77
*/
88

9-
namespace JetApplication;
10-
119
use Jet\Autoloader_Loader;
1210
use Jet\Application_Modules;
1311
use Jet\SysConf_Jet_Modules;
1412

1513
/**
1614
*
1715
*/
18-
class Autoloader_ApplicationModules extends Autoloader_Loader
16+
return new class extends Autoloader_Loader
1917
{
18+
/**
19+
* @return string
20+
*/
21+
public function getAutoloaderCode() : string
22+
{
23+
return 'application/Modules';
24+
}
2025

2126
/**
2227
*
@@ -38,11 +43,7 @@ public function getScriptPath( string $root_namespace, string $namespace, string
3843
return false;
3944
}
4045

41-
42-
$module_path = Application_Modules::getModuleDir( $module_name );
43-
44-
$class_name = str_replace( '_', DIRECTORY_SEPARATOR, $class_name );
45-
return $module_path . $class_name . '.php';
46+
return Application_Modules::getModuleDir( $module_name ) . $this->classNameToPath( $class_name );
4647

4748
}
48-
}
49+
};

application/Autoloaders/Jet.php

Lines changed: 0 additions & 38 deletions
This file was deleted.

application/Init/Autoloader.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,9 @@
1717

1818
require_once SysConf_Path::getLibrary() . 'Jet/Autoloader.php';
1919

20-
2120
Autoloader::initialize();
22-
23-
24-
require SysConf_Path::getApplication() . 'Autoloaders/Jet.php';
25-
Autoloader_Jet::register();
26-
27-
require SysConf_Path::getApplication() . 'Autoloaders/ApplicationClasses.php';
28-
Autoloader_ApplicationClasses::register();
29-
30-
31-
require SysConf_Path::getApplication() . 'Autoloaders/ApplicationModules.php';
32-
Autoloader_ApplicationModules::register();
33-
34-
$composer_autoloader = SysConf_Path::getLibrary().'Composer/autoload.php';
35-
if( file_exists( $composer_autoloader) ) {
36-
include_once $composer_autoloader;
37-
}
21+
Autoloader::registerLibraryAutoloaders();
22+
Autoloader::registerApplicationAutoloaders();
23+
Autoloader::initComposerAutoloader();
3824

3925
//Debug_Profiler::blockEnd('INIT - Autoloader');

0 commit comments

Comments
 (0)