Page MenuHomeCode

No OneTemporary

diff --git a/dev/scripts/autoload.tcl b/dev/scripts/autoload.tcl
index 326b195..b94f5e4 100755
--- a/dev/scripts/autoload.tcl
+++ b/dev/scripts/autoload.tcl
@@ -1,133 +1,129 @@
#!/usr/local/bin/tclsh8.5
#
# php-autoload-generator
-# (c) Sébastien Santoro aka Dereckson, 2010-2013, some rights reserved.
+# (c) Sébastien Santoro aka Dereckson, 2010-2018, some rights reserved.
# Released under BSD license
#
# Last version of the code can be fetch at:
# http://bitbucket.org/dereckson/php-autoload-generator
#
-# This code generator write a __autoload() PHP method, when you don't have a
-# consistent pattern for classes naming and don't want to register several
-# autoloader with spl_autoload_register().
+# This code generator writes a spl_autoload_register PHP method,
+# when you don't have a consistent pattern for classes naming.
#
# Parses your classes folder & reads each file to check if it contains classes.
#
#
# Configuration
#
#A list of regexp, one per directory to ignore
set config(directoriesToIgnore) {Smarty SmartLine}
#The output to produce before the lines
set config(templateBefore) "<?php
-/**
- * This magic method is called when a class can't be loaded
- */
-function __autoload (\$className) {
+spl_autoload_register(function (string \$className) {
//Classes"
#The output to produce after the
set config(templateAfter) "
//Loader
if (array_key_exists(\$className, \$classes)) {
require_once(\$classes\[\$className]);
}
-}"
+});"
#The line format, for %%lines%%
set config(templateClassLine) { $classes['%%class%%'] = '%%file%%';}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Helpers methods
#
#Find .php script
proc find_scripts {directory} {
set dirs {}
foreach i [lsort [glob -nocomplain -dir $directory *]] {
if {[file type $i] == "directory" && ![is_ignored_directory $i]} {
lappend dirs $i
} elseif {[file extension $i] == ".php"} {
find_objects $i
}
}
foreach subdir $dirs {
#Adds a white line as a separator, then the classes in this dir
puts ""
find_scripts $subdir
}
}
#Called when we've got a winner
proc add_class {script class} {
global config
set line $config(templateClassLine)
regsub -all -- "%%class%%" $line $class line
regsub -all -- "%%file%%" $line $script line
puts $line
}
#Find objects like classes or interfaces in the file
#Thanks to Richard Suchenwirth for its glob-r code snippet this proc is forked
proc find_objects {file} {
set fp [open $file]
while {[gets $fp line] >= 0} {
set pos1 [string first "class " $line]
if {$pos1 == -1} {
set pos1 [string first "interface " $line]
set len 10
} {
set len 6
}
set pos2 [string first " \{" $line $pos1]
set pos3 [string first " implements" $line $pos1]
set pos4 [string first " extends" $line $pos1]
if {$pos1 > -1 && $pos2 > -1} {
if {$pos4 > -1} {
#We test implements first, as if a class implements and extends
#the syntax is class Plane extends Vehicle implements FlyingItem
set pos $pos4
} elseif {$pos3 > -1} {
set pos $pos3
} else {
set pos $pos2
}
set class [string range $line [expr $pos1 + $len] [expr $pos - 1]]
add_class $file $class
}
}
close $fp
}
#Check if the directory is ignored
proc is_ignored_directory {directory} {
global config
foreach re $config(directoriesToIgnore) {
if [regexp $re $directory] {return 1}
}
return 0
}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Procedural code
#
if {$argc > 0} {
set directory [lindex $argv 0]
} {
set directory .
}
puts $config(templateBefore)
find_scripts $directory/includes
puts $config(templateAfter)
diff --git a/includes/autoload.php b/includes/autoload.php
index d00f0e6..bbb4a16 100755
--- a/includes/autoload.php
+++ b/includes/autoload.php
@@ -1,63 +1,60 @@
<?php
-/**
- * This magic method is called when a class can't be loaded
- */
-function __autoload ($className) {
+spl_autoload_register(function (string $className) {
//Classes
$classes['IAuthentication'] = './includes/auth/IAuthentication.php';
$classes['UserPasswordAuthentication'] = './includes/auth/UserPasswordAuthentication.php';
$classes['YubiCloudAuthentication'] = './includes/auth/YubiCloudAuthentication.php';
$classes['Cache'] = './includes/cache/cache.php';
$classes['CacheMemcached'] = './includes/cache/memcached.php';
$classes['CacheVoid'] = './includes/cache/void.php';
$classes['ContentFile'] = './includes/content/file.php';
$classes['ContentLocation'] = './includes/content/location.php';
$classes['ContentZone'] = './includes/content/zone.php';
$classes['GeoBody'] = './includes/geo/body.php';
$classes['GeoGalaxy'] = './includes/geo/galaxy.php';
$classes['GeoLocation'] = './includes/geo/location.php';
$classes['GeoOctocube'] = './includes/geo/octocube.php';
$classes['GeoPlace'] = './includes/geo/place.php';
$classes['GeoPoint3D'] = './includes/geo/point3D.php';
$classes['GeoPointPolarZ'] = './includes/geo/pointPolarZ.php';
$classes['GeoScene'] = './includes/geo/scene.php';
$classes['GeoSceneIndex'] = './includes/geo/sceneindex.php';
$classes['Application'] = './includes/objects/application.php';
$classes['Content'] = './includes/objects/content.php';
$classes['Invite'] = './includes/objects/invite.php';
$classes['Message'] = './includes/objects/message.php';
$classes['MOTD'] = './includes/objects/motd.php';
$classes['Perso'] = './includes/objects/perso.php';
$classes['Port'] = './includes/objects/port.php';
$classes['Profile'] = './includes/objects/profile.php';
$classes['ProfileComment'] = './includes/objects/profilecomment.php';
$classes['ProfilePhoto'] = './includes/objects/profilephoto.php';
$classes['Request'] = './includes/objects/request.php';
$classes['RequestReply'] = './includes/objects/requestreply.php';
$classes['Ship'] = './includes/objects/ship.php';
$classes['User'] = './includes/objects/user.php';
$classes['SettingsPage'] = './includes/settings/page.php';
$classes['Setting'] = './includes/settings/setting.php';
$classes['Settings'] = './includes/settings/settings.php';
$classes['StoryChoice'] = './includes/story/choice.php';
$classes['StoryHook'] = './includes/story/hook.php';
$classes['DemoStoryHook'] = './includes/story/hook_demo.php';
$classes['SpatioportStoryHook'] = './includes/story/hook_spatioport.php';
$classes['StorySection'] = './includes/story/section.php';
$classes['Story'] = './includes/story/story.php';
$classes['TravelPlace'] = './includes/travel/place.php';
$classes['Travel'] = './includes/travel/travel.php';
//Loader
if (array_key_exists($className, $classes)) {
require_once($classes[$className]);
}
-}
+});

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 23, 15:16 (1 d, 11 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
20924
Default Alt Text
(7 KB)

Event Timeline