oauth2-client.inc.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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' => [
  13. Finder::create()->files()->in( 'vendor/league/oauth2-client' )->name( [ '*.php', 'LICENSE', 'composer.json' ] ),
  14. ],
  15. /*
  16. * When scoping PHP files, there will be scenarios where some of the code being scoped indirectly references the
  17. * original namespace. These will include, for example, strings or string manipulations. PHP-Scoper has limited
  18. * support for prefixing such strings. To circumvent that, you can define patchers to manipulate the file to your
  19. * heart contents.
  20. *
  21. * For more see: https://github.com/humbug/php-scoper#patchers
  22. */
  23. 'patchers' => [
  24. /**
  25. * Replaces the Adapter string references with the prefixed versions.
  26. *
  27. * @param string $filePath The path of the current file.
  28. * @param string $prefix The prefix to be used.
  29. * @param string $content The content of the specific file.
  30. *
  31. * @return string The modified content.
  32. */
  33. function( $file_path, $prefix, $content ) {
  34. // 26 is the length of the GrantFactory.php file path.
  35. if ( substr( $file_path, -26 ) !== 'src/Grant/GrantFactory.php' ) {
  36. return $content;
  37. }
  38. $replaced = str_replace(
  39. '$class = \'League\\\\OAuth2\\\\Client\\\\Grant\\\\\' . $class;',
  40. sprintf( '$class = \'%s\\\\League\\\\OAuth2\\\\Client\\\\Grant\\\\\' . $class;', $prefix ),
  41. $content
  42. );
  43. return $replaced;
  44. },
  45. ],
  46. );