@@ -15,12 +15,35 @@ use Symfony\Component\Console\Input\InputArgument;
1515use Symfony \Component \Console \Input \InputOption ;
1616use Symfony \Component \Console \Input \ArgvInput ;
1717
18- $ cwd = getcwd ();
19- $ vendorAutoLoadFile = realpath (__DIR__ . "/../vendor/autoload.php " );
18+ // PHP.Gt should always be loaded as a Composer dependency. The vendor directory
19+ // will be in the project's root directory — not PHP.Gt's root directory.
20+ // We first need to find the root directory by working up the directory tree
21+ // until the vendor directory is found.
22+ $ vendorDirectory = null ;
23+ while (true ) {
24+ $ cwd = getcwd ();
25+ if (is_dir ("$ cwd/vendor " )) {
26+ $ vendorDirectory = "$ cwd/vendor " ;
27+ break ;
28+ }
29+ chdir (".. " );
30+
31+ if (getcwd () === $ cwd ) {
32+ // We have reached the root directory of the filesystem without finding
33+ // the vendor directory.
34+ echo "No vendor directory found. \n"
35+ . "Have you performed a composer install? \n\n"
36+ . "See http://www.php.gt/docs/installation for more information. \n" ;
37+ exit (1 );
38+ }
39+ }
40+
41+ $ vendorAutoLoadFile = realpath ("$ vendorDirectory/autoload.php " );
2042if (!file_exists ($ vendorAutoLoadFile )) {
21- // If this script exists within the vendor/brightflair/php.gt directory:
22- $ vendorAutoLoadFile = realpath (__DIR__ . "/../../../autoload.php " );
23- $ cwd = realpath (__DIR__ . "/../../../.. " );
43+ echo "No Composer autoloader script found. \n"
44+ . "Have you performed a composer install? \n\n"
45+ . "See http://www.php.gt/docs/installation for more information. \n" ;
46+ exit (1 );
2447}
2548require ($ vendorAutoLoadFile );
2649
@@ -47,25 +70,10 @@ try {
4770 if (!is_null ($ overrideApproot )) {
4871 $ approot = "$ approot/ $ overrideApproot " ;
4972 }
50- // Change autoloaders so we are definitely using the current project's
51- // dependencies (rather than the global PHP.Gt dependencies).
52- $ projectAutoloader = "$ approot/vendor/autoload.php " ;
53- if (!file_exists ($ projectAutoloader )) {
54- // We must be running the bin/serve script manually...
55- $ projectAutoloader = $ vendorAutoLoadFile ;
56- }
57-
58- if (!file_exists ($ projectAutoloader )) {
59- echo "\nYour project must require PHP.Gt "
60- . "as a dependency using composer. \n\n"
61- . "See http://www.php.gt/docs/installation for more information. " ;
62- exit (1 );
63- }
64-
73+
6574 $ xdebug = $ input ->getOption ("xdebug " );
6675 ini_set ("xdebug.idekey " , $ xdebug );
67-
68- require ($ projectAutoloader );
76+
6977 new Server ($ input );
7078 exit (0 );
7179}
@@ -76,4 +84,4 @@ catch(Exception $e) {
7684 echo strip_tags ($ definition ->asText ());
7785 echo "\n" ;
7886 exit (1 );
79- }
87+ }
0 commit comments