1+ #!/usr/bin/env php
2+ <?php
3+ /**
4+ * Go! AOP Framework PHP 8 Compatibility Checker
5+ *
6+ * This script helps verify that your environment is properly configured
7+ * for PHP 8 compatibility with the Go! AOP Framework.
8+ */
9+
10+ if (PHP_VERSION_ID < 80200 ) {
11+ echo "❌ PHP 8.2+ is required. Current version: " . PHP_VERSION . "\n" ;
12+ echo "Please upgrade to PHP 8.2 or higher. \n" ;
13+ exit (1 );
14+ }
15+
16+ echo "✅ PHP Version: " . PHP_VERSION . " (compatible) \n" ;
17+
18+ // Check if composer is available
19+ $ autoloadPath = __DIR__ . '/../vendor/autoload.php ' ;
20+ if (!file_exists ($ autoloadPath )) {
21+ echo "❌ Composer dependencies not installed \n" ;
22+ echo "Run: composer install \n" ;
23+ exit (1 );
24+ }
25+
26+ require_once $ autoloadPath ;
27+
28+ echo "✅ Composer autoloader available \n" ;
29+
30+ // Check parser-reflection version
31+ try {
32+ if (!class_exists ('\Go\ParserReflection\ReflectionFile ' )) {
33+ echo "❌ Parser-reflection library not available \n" ;
34+ echo "Run: composer install \n" ;
35+ exit (1 );
36+ }
37+ $ reflection = new \Go \ParserReflection \ReflectionFile (__FILE__ );
38+ echo "✅ Parser-reflection library loaded \n" ;
39+ } catch (Exception $ e ) {
40+ echo "❌ Parser-reflection error: " . $ e ->getMessage () . "\n" ;
41+ exit (1 );
42+ }
43+
44+ // Test getConstants compatibility
45+ echo "\n--- Testing getConstants() PHP 8 compatibility --- \n" ;
46+
47+ $ testCode = '<?php
48+ namespace CompatTest;
49+ class TestClass {
50+ const PUBLIC_CONST = "public";
51+ protected const PROTECTED_CONST = "protected";
52+ private const PRIVATE_CONST = "private";
53+ } ' ;
54+
55+ $ testFile = sys_get_temp_dir () . '/compat_test.php ' ;
56+ file_put_contents ($ testFile , $ testCode );
57+
58+ try {
59+ $ reflectionFile = new \Go \ParserReflection \ReflectionFile ($ testFile );
60+ include_once $ testFile ;
61+
62+ $ namespace = $ reflectionFile ->getFileNamespace ('CompatTest ' );
63+ $ class = $ namespace ->getClass ('CompatTest\TestClass ' );
64+
65+ $ allConstants = $ class ->getConstants ();
66+ $ publicConstants = $ class ->getConstants (\ReflectionClassConstant::IS_PUBLIC );
67+
68+ echo " All constants: " . count ($ allConstants ) . "\n" ;
69+ echo " Public constants (with filter): " . count ($ publicConstants ) . "\n" ;
70+
71+ if (count ($ publicConstants ) === count ($ allConstants )) {
72+ echo " ⚠️ Filter parameter accepted but not properly implemented \n" ;
73+ echo " This is a known issue. See UPGRADE-PHP8.md for details. \n" ;
74+ } else {
75+ echo " ✅ Filter parameter working correctly \n" ;
76+ }
77+
78+ } catch (Exception $ e ) {
79+ echo "❌ Error testing getConstants(): " . $ e ->getMessage () . "\n" ;
80+ } finally {
81+ unlink ($ testFile );
82+ }
83+
84+ // Test PHP 8 syntax parsing
85+ echo "\n--- Testing PHP 8 syntax parsing --- \n" ;
86+
87+ $ syntaxTests = [
88+ 'Union Types ' => '<?php class Test { public string|int $prop; } ' ,
89+ 'Attributes ' => '<?php #[\Attribute] class A {} #[A] class B {} ' ,
90+ 'Named Parameters ' => '<?php class Test { function f($a = "", $b = "") {} function g() { $this->f(b: "x", a: "y"); } } ' ,
91+ ];
92+
93+ foreach ($ syntaxTests as $ name => $ code ) {
94+ $ testFile = sys_get_temp_dir () . '/syntax_test_ ' . md5 ($ name ) . '.php ' ;
95+ file_put_contents ($ testFile , $ code );
96+
97+ try {
98+ new \Go \ParserReflection \ReflectionFile ($ testFile );
99+ echo " ✅ $ name \n" ;
100+ } catch (Exception $ e ) {
101+ echo " ❌ $ name: " . $ e ->getMessage () . "\n" ;
102+ } finally {
103+ unlink ($ testFile );
104+ }
105+ }
106+
107+ echo "\n--- Framework Core Classes --- \n" ;
108+
109+ // Test core framework classes
110+ $ coreClasses = [
111+ 'Go\Core\AdviceMatcher ' ,
112+ 'Go\Instrument\Transformer\MagicConstantTransformer ' ,
113+ 'Go\Aop\Pointcut\TruePointcut ' ,
114+ ];
115+
116+ foreach ($ coreClasses as $ className ) {
117+ try {
118+ $ reflection = new ReflectionClass ($ className );
119+ echo " ✅ $ className \n" ;
120+ } catch (Exception $ e ) {
121+ echo " ❌ $ className: " . $ e ->getMessage () . "\n" ;
122+ }
123+ }
124+
125+ echo "\n🎉 PHP 8 compatibility check complete! \n" ;
126+ echo "\nFor detailed information about PHP 8 compatibility, see: \n" ;
127+ echo " - UPGRADE-PHP8.md \n" ;
128+ echo " - CHANGELOG.md \n" ;
129+ echo "\nIf you encounter issues, please report them at: \n" ;
130+ echo " https://github.com/goaop/framework/issues \n" ;
0 commit comments