autoload.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * iCalcreator, the PHP class package managing iCal (rfc2445/rfc5445) calendar information.
  4. *
  5. * copyright (c) 2007-2021 Kjell-Inge Gustafsson, kigkonsult, All rights reserved
  6. * Link https://kigkonsult.se
  7. * Package iCalcreator
  8. * Version 2.29.30
  9. * License Subject matter of licence is the software iCalcreator.
  10. * The above copyright, link, package and version notices,
  11. * this licence notice and the invariant [rfc5545] PRODID result use
  12. * as implemented and invoked in iCalcreator shall be included in
  13. * all copies or substantial portions of the iCalcreator.
  14. *
  15. * iCalcreator is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Lesser General Public License as published
  17. * by the Free Software Foundation, either version 3 of the License,
  18. * or (at your option) any later version.
  19. *
  20. * iCalcreator is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Lesser General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Lesser General Public License
  26. * along with iCalcreator. If not, see <https://www.gnu.org/licenses/>.
  27. *
  28. * This file is a part of iCalcreator.
  29. */
  30. /**
  31. * autoload.php
  32. *
  33. * iCalcreator package autoloader
  34. *
  35. * @author Kjell-Inge Gustafsson, kigkonsult <ical@kigkonsult.se>
  36. * @since 2.29.30 - 2020-12-09
  37. */
  38. /**
  39. * Do NOT alter or remove the constant!!
  40. */
  41. define( 'ICALCREATOR_VERSION', 'iCalcreator 2.30' );
  42. /**
  43. * load iCalcreator src and support classes and Traits
  44. */
  45. spl_autoload_register(
  46. function( $class ) {
  47. static $BS = '\\';
  48. static $PHP = '.php';
  49. static $PREFIX = 'Kigkonsult\\Icalcreator\\';
  50. static $SRC = 'src';
  51. static $SRCDIR = null;
  52. static $TEST = 'test';
  53. static $TESTDIR = null;
  54. if( is_null( $SRCDIR )) {
  55. $SRCDIR = __DIR__ . DIRECTORY_SEPARATOR . $SRC . DIRECTORY_SEPARATOR;
  56. $TESTDIR = __DIR__ . DIRECTORY_SEPARATOR . $TEST . DIRECTORY_SEPARATOR;
  57. }
  58. if( 0 != strncmp( $PREFIX, $class, 23 ))
  59. return false;
  60. $class = substr( $class, 23 );
  61. if( false !== strpos( $class, $BS ))
  62. $class = str_replace( $BS, DIRECTORY_SEPARATOR, $class );
  63. $file = $SRCDIR . $class . $PHP;
  64. if( file_exists( $file )) {
  65. include $file;
  66. }
  67. else {
  68. $file = $TESTDIR . $class . $PHP;
  69. if( file_exists( $file )) {
  70. include $file;
  71. }
  72. }
  73. }
  74. );