ruckusing.inc.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. declare( strict_types=1 );
  3. use Isolated\Symfony\Component\Finder\Finder;
  4. return array(
  5. /*
  6. * By default when running php-scoper add-prefix, it will prefix all relevant code found in the current working
  7. * directory. You can however define which files should be scoped by defining a collection of Finders in the
  8. * following configuration key.
  9. *
  10. * For more see: https://github.com/humbug/php-scoper#finders-and-paths
  11. */
  12. 'finders' => array(
  13. Finder::create()->files()->in( 'vendor/ruckusing/ruckusing-migrations' )
  14. ->exclude( [ 'config', 'tests', 'lib/Task/Hello' ] )
  15. ->name( [ '*.php', 'LICENSE', 'composer.json' ] ),
  16. ),
  17. /*
  18. * When scoping PHP files, there will be scenarios where some of the code being scoped indirectly references the
  19. * original namespace. These will include, for example, strings or string manipulations. PHP-Scoper has limited
  20. * support for prefixing such strings. To circumvent that, you can define patchers to manipulate the file to your
  21. * heart contents.
  22. *
  23. * For more see: https://github.com/humbug/php-scoper#patchers
  24. */
  25. 'patchers' => array(
  26. /**
  27. * Replaces the Adapter string references with the prefixed versions.
  28. *
  29. * @param string $filePath The path of the current file.
  30. * @param string $prefix The prefix to be used.
  31. * @param string $content The content of the specific file.
  32. *
  33. * @return string The modified content.
  34. */
  35. function( $file_path, $prefix, $content ) {
  36. if ( substr( $file_path, -33 ) !== 'lib/Ruckusing/FrameworkRunner.php' ) {
  37. return $content;
  38. }
  39. $replaced = preg_replace(
  40. '/\$adapter_class = "Ruckusing_Adapter_(MySQL|PgSQL|Sqlite3)_Base"/',
  41. sprintf( '$adapter_class = "\%s\Ruckusing_Adapter_\\1_Base"', $prefix ),
  42. $content
  43. );
  44. $replaced = str_replace(
  45. "\set_error_handler(array('Ruckusing_Exception', 'errorHandler'), \E_ALL);",
  46. sprintf( '\set_error_handler(array(\'\%s\Ruckusing_Exception\', \'errorHandler\'), \E_ALL);', $prefix ),
  47. $replaced
  48. );
  49. $replaced = str_replace(
  50. "\set_exception_handler(array('Ruckusing_Exception', 'exceptionHandler'));",
  51. sprintf( '\set_exception_handler(array(\'\%s\Ruckusing_Exception\', \'exceptionHandler\'));', $prefix ),
  52. $replaced
  53. );
  54. return $replaced;
  55. },
  56. /**
  57. * Replaces a string reference to a class with the prefixed version.
  58. *
  59. * @param string $file_path The path of the current file.
  60. * @param string $prefix The prefix to be used.
  61. * @param string $content The content of the specific file.
  62. *
  63. * @return string The modified content.
  64. */
  65. function( $file_path, $prefix, $content ) {
  66. if ( substr( $file_path, -27 ) !== 'Ruckusing/Util/Migrator.php' ) {
  67. return $content;
  68. }
  69. $replaced = str_replace(
  70. '"Ruckusing_Util_Migrator"',
  71. sprintf( '"\%s\Ruckusing_Util_Migrator"', $prefix ),
  72. $content
  73. );
  74. return $replaced;
  75. },
  76. /**
  77. * Prefixes the Namespace prefix define.
  78. *
  79. * @param string $file_path The path of the current file.
  80. * @param string $prefix The prefix to be used.
  81. * @param string $content The content of the specific file.
  82. *
  83. * @return string The modified content.
  84. */
  85. function( $file_path, $prefix, $content ) {
  86. if ( substr( $file_path, -25 ) !== 'Ruckusing/Util/Naming.php' ) {
  87. return $content;
  88. }
  89. $replaced = str_replace(
  90. 'const CLASS_NS_PREFIX = \'Task_\'',
  91. sprintf( 'const CLASS_NS_PREFIX = \'\%s\Task_\'', $prefix ),
  92. $content
  93. );
  94. return $replaced;
  95. },
  96. /**
  97. * Escapes the namespace for use in a regex match.
  98. *
  99. * @param string $file_path The path of the current file.
  100. * @param string $prefix The prefix to be used.
  101. * @param string $content The content of the specific file.
  102. *
  103. * @return string The modified content.
  104. */
  105. function( $file_path, $prefix, $content ) {
  106. if ( substr( $file_path, -25 ) !== 'Ruckusing/Util/Naming.php' ) {
  107. return $content;
  108. }
  109. $replaced = str_replace(
  110. 'preg_match(\'/\' . self::CLASS_NS_PREFIX . \'/\'',
  111. 'preg_match(\'/\' . preg_quote(self::CLASS_NS_PREFIX) . \'/\'',
  112. $content
  113. );
  114. return $replaced;
  115. },
  116. ),
  117. /*
  118. * By default, PHP-Scoper will not prefix the user defined constants, classes and functions belonging to the global
  119. * namespace. You can however change that setting for them to be prefixed as usual unless explicitly whitelisted.
  120. *
  121. * https://github.com/humbug/php-scoper#whitelist
  122. */
  123. 'whitelist-global-constants' => false,
  124. 'whitelist-global-classes' => false,
  125. 'whitelist' => [ 'FALSE', 'NULL' ],
  126. );