]> git.mxchange.org Git - core.git/commitdiff
Rewrites:
authorRoland Haeder <roland@mxchange.org>
Sun, 26 Feb 2017 13:00:29 +0000 (14:00 +0100)
committerRoland Haeder <roland@mxchange.org>
Tue, 28 Feb 2017 21:10:04 +0000 (22:10 +0100)
- rewrote detectCorePath() so it can handle more than one (.) path
- all my applications have this framework cloned to "./core/" and currently
  uses a symbolic link inc/ -> core/inc/. This is then no longer needed and
  should be removed from all projects. This surely implies that index.php has
  been distributed on all projects.
- later on this will be changed, then there is no class in index.php, but only
  one include file and one call to main() method.

Signed-off-by: Roland Häder <roland@mxchange.org>
index.php

index 308cda9277dd63f3fef63dc86cdfbb6cf657b753..8a0bec3be1dd52b9dad0a75d128df578d7a336de 100644 (file)
--- a/index.php
+++ b/index.php
@@ -177,15 +177,50 @@ final class ApplicationEntryPoint {
 
        /**
         * Determines the correct absolute path for all includes only once per run.
-        * Other calls of this method are being "cached".
+        * Other calls of this method are being "cached". This is done by checking
+        * a small list of common paths where the framework can reside and check if
+        * inc/config.php can be found.
         *
         * @return      $corePath       Base path (core) for all includes
         */
        protected static final function detectCorePath () {
                // Is it not set?
                if (empty(self::$corePath)) {
-                       // Auto-detect our core path
-                       self::$corePath = str_replace("\\", '/', dirname(__FILE__));
+                       // Auto-detect core path (first application-common)
+                       foreach (array('core', '.') as $possiblePath) {
+                               // Create full path for testing
+                               $realPath = realpath($possiblePath);
+
+                               // Debug message
+                               //* NOISY-DEBUG: */ printf('[%s:%d]: realPath[%s]=%s' . PHP_EOL, __METHOD__, __LINE__, gettype($realPath), $realPath);
+
+                               // Is it FALSE?
+                               if ($realPath === FALSE) {
+                                       // Then, not found.
+                                       continue;
+                               } // END - if
+
+                               // First create full-qualified file name (FQFN) to inc/config.php
+                               $fqfn = sprintf(
+                                       '%s%sinc%sconfig.php',
+                                       $realPath,
+                                       DIRECTORY_SEPARATOR,
+                                       DIRECTORY_SEPARATOR,
+                                       $possiblePath
+                               );
+
+                               // Debug message
+                               //* NOISY-DEBUG: */ printf('[%s:%d]: fqfn=%s' . PHP_EOL, __METHOD__, __LINE__, $fqfn);
+
+                               // Is it readable?
+                               if (is_readable($fqfn)) {
+                                       // Found one
+                                       self::$corePath = $realPath;
+
+                                       // Abort here
+                                       break;
+                               } // END - if
+                       } // END - foreach
                } // END - if
 
                // Return it