Prelude.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * Hoa
  4. *
  5. *
  6. * @license
  7. *
  8. * New BSD License
  9. *
  10. * Copyright © 2007-2017, Hoa community. All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. * * Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * * Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * * Neither the name of the Hoa nor the names of its contributors may be
  20. * used to endorse or promote products derived from this software without
  21. * specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  24. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS AND CONTRIBUTORS BE
  27. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  28. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  29. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  30. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  31. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  32. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. */
  35. if (false === defined('HOA')) {
  36. define('HOA', true);
  37. }
  38. if (false === defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50400) {
  39. throw new Exception(
  40. 'Hoa needs at least PHP5.4 to work; you have ' . phpversion() . '.'
  41. );
  42. }
  43. require_once __DIR__ . DIRECTORY_SEPARATOR . 'Autoloader.php';
  44. require_once __DIR__ . DIRECTORY_SEPARATOR . 'Consistency.php';
  45. $define = function ($constantName, $constantValue, $case = false) {
  46. if (!defined($constantName)) {
  47. return define($constantName, $constantValue, $case);
  48. }
  49. return false;
  50. };
  51. $define('SUCCEED', true);
  52. $define('FAILED', false);
  53. $define('…', '__hoa_core_fill');
  54. $define('DS', DIRECTORY_SEPARATOR);
  55. $define('PS', PATH_SEPARATOR);
  56. $define('ROOT_SEPARATOR', ';');
  57. $define('RS', ROOT_SEPARATOR);
  58. $define('CRLF', "\r\n");
  59. $define('OS_WIN', defined('PHP_WINDOWS_VERSION_PLATFORM'));
  60. $define('S_64_BITS', PHP_INT_SIZE == 8);
  61. $define('S_32_BITS', !S_64_BITS);
  62. $define('PHP_INT_MIN', ~PHP_INT_MAX);
  63. $define('PHP_FLOAT_MIN', (float) PHP_INT_MIN);
  64. $define('PHP_FLOAT_MAX', (float) PHP_INT_MAX);
  65. $define('π', M_PI);
  66. $define('nil', null);
  67. $define('_public', 1);
  68. $define('_protected', 2);
  69. $define('_private', 4);
  70. $define('_static', 8);
  71. $define('_abstract', 16);
  72. $define('_pure', 32);
  73. $define('_final', 64);
  74. $define('_dynamic', ~_static);
  75. $define('_concrete', ~_abstract);
  76. $define('_overridable', ~_final);
  77. $define('WITH_COMPOSER', class_exists('Composer\Autoload\ClassLoader', false) ||
  78. ('cli' === PHP_SAPI &&
  79. file_exists(__DIR__ . DS . '..' . DS . '..' . DS . 'autoload.php')));
  80. /**
  81. * Alias of \Hoa\Consistency\Xcallable.
  82. *
  83. * @param mixed $call First callable part.
  84. * @param mixed $able Second callable part (if needed).
  85. * @return mixed
  86. */
  87. if (!function_exists('xcallable')) {
  88. function xcallable($call, $able = '')
  89. {
  90. if ($call instanceof Hoa\Consistency\Xcallable) {
  91. return $call;
  92. }
  93. return new Hoa\Consistency\Xcallable($call, $able);
  94. }
  95. }