* This class loads class include files with a specific prefix and suffix
*
* @author Roland Haeder <webmaster@shipsimu.org>
- * @version 0.0.0
+ * @version 1.5.0
* @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.shipsimu.org
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ----------------------------------
+ * 1.5
+ * - Namespace scheme Project\Package[\SubPackage...] is fully supported and
+ * throws an E_USER_WARNING if not present. The last part will be always the
+ * class' name.
* 1.4
* - Some comments improved, other minor improvements
* 1.3
*/
public static function autoLoad ($className) {
// Try to include this class
- //* NOISY-DEBUG: */ printf('[%s:%d] className=%s' . PHP_EOL, __METHOD__, __LINE__, $className);
self::getSelfInstance()->includeClass($className);
}
* @return void
*/
public function includeClass ($className) {
+ // The class name should contain at least 2 back-slashes, so split at them
+ $classNameParts = explode("\\", $className);
+
+ // At least 3 parts should be there
+ if (count($classNameParts) < 3) {
+ // Namespace scheme is: Project\Package[\SubPackage...]
+ trigger_error(sprintf('Class name "%s" is not after naming-convention: Project\Package[\SubPackage...]', $className), E_USER_WARNING);
+ } // END - if
+
+ // Get last element
+ $shortClassName = array_pop($classNameParts);
+
// Create a name with prefix and suffix
- $fileName = $this->prefix . $className . $this->suffix;
+ $fileName = $this->prefix . $shortClassName . $this->suffix;
// Now look it up in our index
//* NOISY-DEBUG: */ printf('[%s:%d] ISSET: %s' . PHP_EOL, __METHOD__, __LINE__, $fileName);