Last active
August 8, 2019 14:41
-
-
Save hcooper/a978a1328da787deb390 to your computer and use it in GitHub Desktop.
Koken depends on the positional output of get_declared_classes(), which can not be guaranteed. This extract the class name from the plugin instead.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/application/libraries/shutter.php b/app/application/libraries/shutter.php | |
index 6308d6c..58f7127 100755 | |
--- a/app/application/libraries/shutter.php | |
+++ b/app/application/libraries/shutter.php | |
@@ -68,6 +68,18 @@ class Shutter { | |
return $json; | |
} | |
+ // tokenize a given file, and extract the class name | |
+ public static function extract_classname($file) { | |
+ $contents = file_get_contents($file); | |
+ $tokens = token_get_all($contents); | |
+ | |
+ foreach($tokens as $i => $token) { | |
+ if ($token[0] === T_CLASS) { | |
+ return $tokens[$i+2][1]; | |
+ } | |
+ } | |
+ } | |
+ | |
public static function init() | |
{ | |
$root = dirname(dirname(dirname(dirname(__FILE__)))); | |
@@ -84,8 +96,7 @@ class Shutter { | |
if ($fileinfo->isDir() && !$fileinfo->isDot() && file_exists($plugin)) { | |
include($plugin); | |
$data = json_decode(file_get_contents($info), true); | |
- $klasses = get_declared_classes(); | |
- $last = array_pop( $klasses ); | |
+ $last = self::extract_classname($plugin); | |
$data['php_class'] = new $last; | |
$data['php_class_name'] = get_class($data['php_class']); | |
self::$active_plugins[] = $data['php_class_name']; | |
@@ -129,8 +140,7 @@ class Shutter { | |
if ($matches && !class_exists($matches[1])) | |
{ | |
include($plugin); | |
- $klasses = get_declared_classes(); | |
- $last = array_pop( $klasses ); | |
+ $last = self::extract_classname($plugin); | |
$data['php_class'] = new $last; | |
$data['php_class_name'] = get_class($data['php_class']); | |
self::$class_map[ $data['php_class_name'] ] = $data['php_class']; | |
@@ -578,4 +588,5 @@ class KokenPlugin { | |
} | |
} | |
-Shutter::init(); | |
\ No newline at end of file | |
+Shutter::init(); | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This problem arises if using HHVM instead of PHP5. Confirmed here: https://github.com/facebook/hhvm/blob/master/hphp/doc/inconsistencies#L122-L124