Skip to content

Commit 3dad7c3

Browse files
authored
Merge pull request #149 from Zheness/patch-1
Use of offset during analyse
2 parents a2d19c0 + 6c89b75 commit 3dad7c3

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

src/Mouf/MoufClassExplorer.php

+20-16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class MoufClassExplorer {
4343
private $useCache = true;
4444

4545
private $cacheService;
46+
47+
private $analysisOffset = 0;
4648

4749
public function __construct($selfEdit = false) {
4850
$this->selfEdit = $selfEdit;
@@ -77,18 +79,19 @@ private function analyze() {
7779
$notYetAnalysedClassMap = $classMap;
7880
$nbRun = 0;
7981
while (!empty($notYetAnalysedClassMap)) {
82+
$this->analysisOffset = 0;
8083
$this->analysisResponse = MoufReflectionProxy::analyzeIncludes2($this->selfEdit, $notYetAnalysedClassMap);
8184
$nbRun++;
8285
$startupPos = strpos($this->analysisResponse, "FDSFZEREZ_STARTUP\n");
8386
if ($startupPos === false) {
8487
// It seems there is a problem running the script, let's throw an exception
8588
throw new MoufException("Error while running classes analysis: ".$this->analysisResponse);
8689
}
87-
88-
$this->analysisResponse = substr($this->analysisResponse, $startupPos+18);
90+
91+
$this->analysisOffset = $startupPos+18;
8992
//echo($this->analysisResponse);exit;
9093
while (true) {
91-
$beginMarker = $this->trimLine();
94+
$beginMarker = $this->popLine();
9295
if ($beginMarker == "SQDSG4FDSE3234JK_ENDFILE") {
9396
// We are finished analysing the file! Yeah!
9497
break;
@@ -97,26 +100,26 @@ private function analyze() {
97100
throw new \Exception("Strange behaviour while importing classes. Begin marker: ".$beginMarker);
98101
}
99102

100-
$analyzedClassName = $this->trimLine();
103+
$analyzedClassName = $this->popLine();
101104

102105
// 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) {
105108
// There is a problem...
106109
if ($endMarkerPos === false) {
107110
// An error occured:
108111
$this->forbiddenClasses[$analyzedClassName] = $this->analysisResponse;
109112
unset($notYetAnalysedClassMap[$analyzedClassName]);
110113
break;
111114
} 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;
114117
}
115118
}
116-
$this->trimLine();
119+
$this->popLine();
117120

118121
unset($notYetAnalysedClassMap[$analyzedClassName]);
119-
122+
120123
}
121124
}
122125

@@ -159,17 +162,18 @@ private function analyze() {
159162
private $analysisResponse;
160163

161164
/**
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.
163167
*/
164-
private function trimLine() {
165-
$newLinePos = strpos($this->analysisResponse, "\n");
168+
private function popLine() {
169+
$newLinePos = strpos($this->analysisResponse, "\n", $this->analysisOffset);
166170

167171
if ($newLinePos === false) {
168172
throw new \Exception("End of file reached!");
169173
}
170174

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;
173177
return $line;
174178
}
175179

@@ -217,4 +221,4 @@ public function getErrors() {
217221
}
218222

219223
}
220-
?>
224+
?>

0 commit comments

Comments
 (0)