@@ -43,6 +43,8 @@ class MoufClassExplorer {
43
43
private $ useCache = true ;
44
44
45
45
private $ cacheService ;
46
+
47
+ private $ analysisOffset = 0 ;
46
48
47
49
public function __construct ($ selfEdit = false ) {
48
50
$ this ->selfEdit = $ selfEdit ;
@@ -77,18 +79,19 @@ private function analyze() {
77
79
$ notYetAnalysedClassMap = $ classMap ;
78
80
$ nbRun = 0 ;
79
81
while (!empty ($ notYetAnalysedClassMap )) {
82
+ $ this ->analysisOffset = 0 ;
80
83
$ this ->analysisResponse = MoufReflectionProxy::analyzeIncludes2 ($ this ->selfEdit , $ notYetAnalysedClassMap );
81
84
$ nbRun ++;
82
85
$ startupPos = strpos ($ this ->analysisResponse , "FDSFZEREZ_STARTUP \n" );
83
86
if ($ startupPos === false ) {
84
87
// It seems there is a problem running the script, let's throw an exception
85
88
throw new MoufException ("Error while running classes analysis: " .$ this ->analysisResponse );
86
89
}
87
-
88
- $ this ->analysisResponse = substr ( $ this -> analysisResponse , $ startupPos +18 ) ;
90
+
91
+ $ this ->analysisOffset = $ startupPos +18 ;
89
92
//echo($this->analysisResponse);exit;
90
93
while (true ) {
91
- $ beginMarker = $ this ->trimLine ();
94
+ $ beginMarker = $ this ->popLine ();
92
95
if ($ beginMarker == "SQDSG4FDSE3234JK_ENDFILE " ) {
93
96
// We are finished analysing the file! Yeah!
94
97
break ;
@@ -97,26 +100,26 @@ private function analyze() {
97
100
throw new \Exception ("Strange behaviour while importing classes. Begin marker: " .$ beginMarker );
98
101
}
99
102
100
- $ analyzedClassName = $ this ->trimLine ();
103
+ $ analyzedClassName = $ this ->popLine ();
101
104
102
105
// Now, let's see if the end marker is right after the begin marker...
103
- $ endMarkerPos = strpos ($ this ->analysisResponse , "DSQRZREZRZER__AFTERINCLUDE \n" );
104
- if ($ endMarkerPos !== 0 ) {
106
+ $ endMarkerPos = strpos ($ this ->analysisResponse , "DSQRZREZRZER__AFTERINCLUDE \n" , $ this -> analysisOffset );
107
+ if ($ endMarkerPos !== $ this -> analysisOffset ) {
105
108
// There is a problem...
106
109
if ($ endMarkerPos === false ) {
107
110
// An error occured:
108
111
$ this ->forbiddenClasses [$ analyzedClassName ] = $ this ->analysisResponse ;
109
112
unset($ notYetAnalysedClassMap [$ analyzedClassName ]);
110
113
break ;
111
114
} else {
112
- $ this ->forbiddenClasses [$ analyzedClassName ] = substr ($ this ->analysisResponse , 0 , $ endMarkerPos );
113
- $ this ->analysisResponse = substr ( $ this -> analysisResponse , $ endMarkerPos) ;
115
+ $ this ->forbiddenClasses [$ analyzedClassName ] = substr ($ this ->analysisResponse , $ this -> analysisOffset , $ endMarkerPos - $ this -> analysisOffset );
116
+ $ this ->analysisOffset = $ endMarkerPos ;
114
117
}
115
118
}
116
- $ this ->trimLine ();
119
+ $ this ->popLine ();
117
120
118
121
unset($ notYetAnalysedClassMap [$ analyzedClassName ]);
119
-
122
+
120
123
}
121
124
}
122
125
@@ -159,17 +162,18 @@ private function analyze() {
159
162
private $ analysisResponse ;
160
163
161
164
/**
162
- * Trim the first line from $analysisResponse and returns it.
165
+ * Get the current line from $analysisResponse and returns it.
166
+ * Moves the internal offset pointer.
163
167
*/
164
- private function trimLine () {
165
- $ newLinePos = strpos ($ this ->analysisResponse , "\n" );
168
+ private function popLine () {
169
+ $ newLinePos = strpos ($ this ->analysisResponse , "\n" , $ this -> analysisOffset );
166
170
167
171
if ($ newLinePos === false ) {
168
172
throw new \Exception ("End of file reached! " );
169
173
}
170
174
171
- $ line = substr ($ this ->analysisResponse , 0 , $ newLinePos );
172
- $ this ->analysisResponse = substr ( $ this -> analysisResponse , $ newLinePos + 1 ) ;
175
+ $ line = substr ($ this ->analysisResponse , $ this -> analysisOffset , ( $ newLinePos - $ this -> analysisOffset ) );
176
+ $ this ->analysisOffset = $ newLinePos + 1 ;
173
177
return $ line ;
174
178
}
175
179
@@ -217,4 +221,4 @@ public function getErrors() {
217
221
}
218
222
219
223
}
220
- ?>
224
+ ?>
0 commit comments