Project

General

Profile

« Previous | Next » 

Revision 23

Added by Manuela over 6 years ago

CoreAutoloader::addNamespace() + ::doRegister() modified.
initialize:: register Autoloader fitted to modified methods

View differences:

branches/main/admin/interface/version.php
48 48
if (!defined('VERSION_LOADED')) {
49 49
    $sInfo = '
50 50
        VERSION  = "2.10.1-dev"
51
        REVISION = "22"
51
        REVISION = "23"
52 52
        SP       = ""
53 53
    ';
54 54
    foreach (parse_ini_string($sInfo) as $item=>$value) {
branches/main/framework/CoreAutoloader.php
17 17
 * You should have received a copy of the GNU General Public License 2
18 18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 19
 */
20
/**
20
/*
21 21
 * Description of Autoloader
22 22
 *
23 23
 * @package      Core
24 24
 * @copyright    Manuela v.d.Decken <manuela@isteam.de>
25 25
 * @author       Manuela v.d.Decken <manuela@isteam.de>
26
 * @license      GNU General Public License 3.0
26
 * @license      GNU General Public License 2.0
27 27
 * @version      0.0.1
28 28
 * @revision     $Id$
29 29
 * @since        File available since 05.07.2017
......
43 43
class CoreAutoloader
44 44
{
45 45

  
46
    private static $sInstallPath = '';
46
    private static $sInstallPath = null;
47 47
    private static $aPatterns = [];
48 48
    private static $aReplacements = [];
49 49

  
50
    private static $aTransNs = [
51
        'vendor/jscalendar' => 'include/jscalendar',
52
        'vendor'            => 'include',
53
        'bin/interfaces'    => 'framework',
54
        'bin/db'            => 'framework/db',
55
        'bin'               => 'framework',
56
        'addon'             => 'modules',
57
        'acp'               => 'admin',
58
    ];
50
    private static $aTransNs = [];
59 51
/**
60 52
 * add new Namespace->Directory relation or overwrite existing
61
 * @param string $sNamespace
62
 * @param string $sDirectory
53
 * @param mixed $sNamespace
54
 * @param string $sDirectory (default: '')
63 55
 */
64
    public static function addNamespace($sNamespace, $sDirectory)
56
    public static function addNamespace($mNamespace, $sDirectory = '')
65 57
    {
66
        $sNamespace = \trim(\str_replace('\\', '/', $sNamespace), '/');
67
        $sDirectory = \trim(\str_replace('\\', '/', $sDirectory), '/');
68
        self::$aTransNs[$sNamespace] = $sDirectory;
69
        \krsort(self::$aTransNs);
70
        self::$aPatterns = self::$aReplacements = [];
71
        foreach (self::$aTransNs as $sPattern => $sReplacement) {
72
            self::$aPatterns[]     = '@^('.$sPattern.'/)@su';
73
            self::$aReplacements[] = $sReplacement.'/';
58
        if (\is_null(self::$sInstallPath)) {
59
            throw new \RuntimeException('can not add namespaces before autoloader is registered!!');
74 60
        }
61
        if (\is_string($mNamespace)) {
62
            $mNamespace = [$mNamespace, $sDirectory];
63
        }
64
        if (\is_array($mNamespace)) {
65
            foreach ($mNamespace as $sNamespace => $sDirectory) {
66
                $sNamespace = \trim(\str_replace('\\', '/', $sNamespace), '/');
67
                $sDirectory = \trim(\str_replace('\\', '/', $sDirectory), '/');
68
                self::$aTransNs[$sNamespace] = $sDirectory;
69
            }
70
            \krsort(self::$aTransNs);
71
            self::$aPatterns = self::$aReplacements = [];
72
            foreach (self::$aTransNs as $sPattern => $sReplacement) {
73
                self::$aPatterns[]     = '@^('.$sPattern.'/)@su';
74
                self::$aReplacements[] = $sReplacement.'/';
75
            }
76
        }
75 77
    }
76 78

  
77 79
    public static function autoLoad($sClassName)
......
107 109
/**
108 110
 * register this autoloader
109 111
 */
110
    public static function doRegister(array $aAdditionalTranslations = null)
112
    public static function doRegister($sPathPrefix)
111 113
    {
112
        if (!is_null($aAdditionalTranslations)) {
113
            foreach ($aAdditionalTranslations as $sKey=>$sValue) {
114
                self::$aTransNs[$sKey] = $sValue;
114
        self::$sInstallPath = \rtrim(\str_replace('\\', '/', $sPathPrefix), '/').'/';
115
        if (\is_dir(self::$sInstallPath) && \is_readable(self::$sInstallPath)) {
116
            \krsort(self::$aTransNs);
117
            foreach (self::$aTransNs as $sPattern => $sReplacement) {
118
                self::$aPatterns[]     = '@^('.$sPattern.'/)@su';
119
                self::$aReplacements[] = $sReplacement.'/';
115 120
            }
121
            \spl_autoload_register([__CLASS__, 'autoLoad']);
122
        } else {
123
            throw new \RuntimeException('invalid PathPrefix given!!');
116 124
        }
117
        \krsort(self::$aTransNs);
118
        self::$sInstallPath = \rtrim(\str_replace('\\', '/', \dirname(__DIR__)), '/').'/';
119
        foreach (self::$aTransNs as $sPattern => $sReplacement) {
120
            self::$aPatterns[]     = '@^('.$sPattern.'/)@su';
121
            self::$aReplacements[] = $sReplacement.'/';
122
        }
123
        \spl_autoload_register([__CLASS__, 'autoLoad']);
124 125
    }
125 126

  
126 127
/**
branches/main/framework/initialize.php
1 1
<?php
2
/**
2

  
3
/*
4
 * Copyright (C) 2017 Manuela v.d.Decken <manuela@isteam.de>
3 5
 *
4
 * @category        framework
5
 * @package         initialize
6
 * @author          WebsiteBaker Project
7
 * @copyright       Ryan Djurovich
8
 * @copyright       WebsiteBaker Org. e.V.
9
 * @link            http://websitebaker.org/
10
 * @license         http://www.gnu.org/licenses/gpl.html
11
 * @platform        WebsiteBaker 2.8.3
12
 * @requirements    PHP 5.3.6 and higher
13
 * @version         $Id$
14
 * @filesource      $HeadURL$
15
 * @lastmodified    $Date$
6
 * DO NOT ALTER OR REMOVE COPYRIGHT OR THIS HEADER
16 7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU General Public License as published by
10
 * the Free Software Foundation, version 2 of the License.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License 2 for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License 2
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 19
 */
20
/**
21
 * @package      Core
22
 * @copyright    Ryan Djurovich
23
 * @author       Ryan Djurovich
24
 * @author       Manuela v.d.Decken <manuela@isteam.de>
25
 * @license      GNU General Public License 2.0
26
 * @version      1.0.1
27
 * @revision     $Id$
28
 * @deprecated   no / since 0000/00/00
29
 * @description  xxx
30
 */
18 31
// $aPhpFunctions = get_defined_functions();
19 32
/**
20 33
 * sanitize $_SERVER['HTTP_REFERER']
......
274 287
    if (!class_exists('\bin\CoreAutoloader')) {
275 288
        include __DIR__.'/CoreAutoloader.php';
276 289
    }
277
    \bin\CoreAutoloader::doRegister();
290
    \bin\CoreAutoloader::doRegister(dirname(__DIR__));
291
    \bin\CoreAutoloader::addNamespace([ // add several needed namespaces
292
        'bin'                => 'framework',
293
        'addon'              => 'modules',
294
        'vendor'             => 'include',
295
        'vendor\\jscalendar' => 'include/jscalendar',
296
        'bin\\db'            => 'framework/db',
297
        'bin\\security'      => 'framework',
298
        'bin\\interfaces'    => 'framework',
299
    ]);
300

  
278 301
    // *** initialize Exception handling
279 302
    if(!function_exists('globalExceptionHandler')) {
280 303
        include(__DIR__.'/globalExceptionHandler.php');
......
305 328
// ---------------------------
306 329
// get Database connection data from configuration
307 330
    defined('ADMIN_DIRECTORY') ? '' : define('ADMIN_DIRECTORY', 'admin');
308
    if (!preg_match('/xx[a-z0-9_][a-z0-9_\-\.]+/i', 'xx'.ADMIN_DIRECTORY)) {
309
        throw new RuntimeException('Invalid admin-directory: ' . ADMIN_DIRECTORY);
331
    if (
332
        !(preg_match('/xx[a-z0-9_][a-z0-9_\-\.]+/i', 'xx'.ADMIN_DIRECTORY) &&
333
         is_dir(dirname(__DIR__).'/'.ADMIN_DIRECTORY))
334
    ) {
335
        throw new RuntimeException('Invalid admin-directory set: ' . ADMIN_DIRECTORY);
310 336
    }
337
// add Namespace 'acp' to Autoloader
338
    \bin\CoreAutoloader::addNamespace('acp', ADMIN_DIRECTORY);
311 339
    defined('ADMIN_URL') ? '' : define('ADMIN_URL', WB_URL.'/'.ADMIN_DIRECTORY);
312 340
    defined('ADMIN_PATH') ? '' : define('ADMIN_PATH', WB_PATH.'/'.ADMIN_DIRECTORY);
313 341
    if ( !defined('WB_REL')){
......
318 346
        define('DOCUMENT_ROOT', preg_replace('/'.preg_quote(str_replace('\\', '/', WB_REL), '/').'$/', '', str_replace('\\', '/', WB_PATH)));
319 347
        $_SERVER['DOCUMENT_ROOT'] = DOCUMENT_ROOT;
320 348
    }
321
// add Namespace 'acp' to Autoloader
322
    \bin\CoreAutoloader::addNamespace('acp', ADMIN_DIRECTORY);
323 349

  
324 350
    if (class_exists('database')) {
325 351
        // sanitize $_SERVER['HTTP_REFERER']

Also available in: Unified diff