@@ -47,16 +47,35 @@ private function validateVersion($version)
4747 private function updateBuildScript ($ newVersion )
4848 {
4949 $ 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 ) {
5677 throw new Exception ("Could not find version in build script " );
5778 }
58-
59- file_put_contents ($ this ->buildScript , $ newContent );
6079 }
6180
6281 private function updateManifest ($ newVersion )
@@ -80,8 +99,9 @@ private function updateManifest($newVersion)
8099 public function getCurrentVersion ()
81100 {
82101 $ 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 ];
85105 }
86106 return null ;
87107 }
0 commit comments