@@ -47,16 +47,35 @@ private function validateVersion($version)
47
47
private function updateBuildScript ($ newVersion )
48
48
{
49
49
$ content = file_get_contents ($ this ->buildScript );
50
- $ pattern = "/private \$version = '[^']+';/ " ;
51
- $ replacement = "private \$version = ' $ newVersion'; " ;
52
-
53
- $ newContent = preg_replace ($ pattern , $ replacement , $ content );
54
-
55
- if ($ newContent === $ content ) {
50
+ $ patterns = [
51
+ // Class property
52
+ "/(private\s+ \\\$version\s*=\s*')[^']+(');/ " ,
53
+ // Global variable
54
+ "/( \\\$version\s*=\s*')[^']+(');/ "
55
+ ];
56
+ $ replacement = "\$version = ' $ newVersion'; " ;
57
+
58
+ $ newContent = preg_replace ($ patterns , $ replacement , $ content );
59
+
60
+ $ updated = false ;
61
+ foreach ($ patterns as $ pattern ) {
62
+ $ newContent = preg_replace (
63
+ $ pattern ,
64
+ "\$1 {$ newVersion }\$2; " ,
65
+ $ content ,
66
+ -1 ,
67
+ $ count
68
+ );
69
+ if ($ count ) {
70
+ file_put_contents ($ this ->buildScript , $ newContent );
71
+ $ updated = true ;
72
+ break ;
73
+ }
74
+ }
75
+
76
+ if (! $ updated ) {
56
77
throw new Exception ("Could not find version in build script " );
57
78
}
58
-
59
- file_put_contents ($ this ->buildScript , $ newContent );
60
79
}
61
80
62
81
private function updateManifest ($ newVersion )
@@ -80,8 +99,9 @@ private function updateManifest($newVersion)
80
99
public function getCurrentVersion ()
81
100
{
82
101
$ content = file_get_contents ($ this ->buildScript );
83
- if (preg_match ("/private \\\$version = '([^']+)';/ " , $ content , $ matches )) {
84
- return $ matches [1 ];
102
+ if (preg_match ("/private\s+ \\\$version\s*=\s*'([^']+)';/ " , $ content , $ m )
103
+ || preg_match ("/ \\\$version\s*=\s*'([^']+)';/ " , $ content , $ m )) {
104
+ return $ m [1 ];
85
105
}
86
106
return null ;
87
107
}
0 commit comments