biow0lf / evedev-kb

Automatically exported from code.google.com/p/evedev-kb
1 stars 0 forks source link

Autoloading of classes #115

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
http://code.google.com/p/evedev-
kb/source/browse/trunk/common/includes/class.edkloader.php

EDK now has an autoloader that tries to load the correct file based on 
class name. 
cache::check() automatically calls 
require_once('common/includes/class.cache.php); before calling the method. 
Mods can replace classes by adding them to a registry with 
edkloader::register().

I underestimated just how many class/files in EDK don't fit that scheme so 
this work is not complete yet. Any broken links will be fixed for 3.1 but 
the whole design may be finished later.

I intend to rename non-conforming class/files where only one or two classes 
are involved and leave a stub in the original file that loads the correct 
one. This will support any older mods that load class files directly.
e.g. http://code.google.com/p/evedev-
kb/source/browse/trunk/common/includes/class.corp.php

Longer term every class will be in its own file that is named to match the 
class. ClassName_Naming => class.classnamenaming.php If a class is only 
used as a helper to another that is loaded first then it is safe to leave 
it one file. The stubs will also be removed.

Original issue reported on code.google.com by kovellia on 29 May 2010 at 9:29

GoogleCodeExporter commented 9 years ago

Original comment by kovellia on 29 May 2010 at 2:44

GoogleCodeExporter commented 9 years ago
Two possible extensions to this. If a class is named Foo_Bar then the file 
class.foo.php is checked. This way a collection of related classes can be in 
the one 
file. Another possibility is Foo_Bar looks in foo/class.bar.php.

I only see the first as a plus if the classes are related so that if one is 
loaded 
then the rest are also needed. Currently this is only true of the contract 
classes. 
Both toplist and eveapi files load a lot of unused classes.

The second approach could make the classes more manageable yet individually 
small.

I may add this as a check for both possibilities for short term simplicity. A 
call to 
load Class http_request would first look in 
common/includes/http/class.request.php 
then if not found common/includes/class.http_request.php 

Original comment by kovellia on 30 May 2010 at 7:32

GoogleCodeExporter commented 9 years ago
Continuing to discuss this with myself, I implemented the second option and 
have 
modified class.eveapi.php to match. A bit more testing is needed before I 
submit it.

API_Killlog is mapped to api/class.killlog.php

Original comment by kovellia on 30 May 2010 at 11:36

GoogleCodeExporter commented 9 years ago
Changes all made and the ensuing dramas from changing filenames have been 
quelled

Original comment by kovellia on 3 Jun 2010 at 6:37