Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the link for the aliases #714

Merged
merged 1 commit into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ potentially very difficult to debug due to dissimilar or unsupported package ver
- [Further Reading](docs/further-reading.md#further-reading)
- [Polyfills](docs/further-reading.md#polyfills)
- [How to deal with unknown third-party symbols](docs/further-reading.md#how-to-deal-with-unknown-third-party-symbols)
- [Autoload aliases](docs/further-reading.md#autoload-aliases)
- [Class aliases](docs/further-reading.md#class-aliases)
- [Function aliases](docs/further-reading.md#function-aliases)
- [Limitations](docs/limitations.md#limitations)
- [Dynamic symbols](docs/limitations.md#dynamic-symbols)
- [Date symbols](docs/limitations.md#date-symbols)
Expand Down
19 changes: 19 additions & 0 deletions docs/further-reading.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

- [Polyfills](#polyfills)
- [How to deal with unknown third-party symbols](#how-to-deal-with-unknown-third-party-symbols)
- [Autoload aliases](#autoload-aliases)
- [Class aliases](#class-aliases)
- [Function aliases](#function-aliases)


### Polyfills
Expand Down Expand Up @@ -106,10 +109,26 @@ symbol will result in an alias being registered (see [exposed-symbols]), which
means you _need_ to have the function declared within your codebase at some point.


### Autoload aliases

#### Class aliases

When [exposing a class], an alias will be registered.

#### Function aliases

When [exposing a function] or when a globally declared [excluded function]
declaration is found (see [#706]), an alias will be registered.


<br />
<hr />

« [Configuration](configuration.md#configuration) • [Limitations](limitations.md#limitations) »

[excluded-symbols]: configuration.md#excluded-symbols
[excluding a function]: configuration.md#excluded-symbols
[exposed-symbols]: configuration.md#exposed-symbols
[exposing a class]: configuration.md#exposing-classes
[exposing a function]: configuration.md#exposing-functions
[#706]: https://github.com/humbug/php-scoper/pull/706
16 changes: 8 additions & 8 deletions src/Autoload/ScoperAutoloadGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ final class ScoperAutoloadGenerator
{
// TODO: aliasing functions could be done via a single function to reduce boiler-template.

private const EXPOSED_FUNCTIONS_DOC = <<<'EOF'
// Exposed functions. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposing-functions
private const FUNCTION_ALIASES_DOC = <<<'EOF'
// Function aliases. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#function-aliases
EOF;

private const EXPOSED_CLASSES_DOC = <<<'EOF'
// Exposed classes. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposing-classes
private const CLASS_ALIASES_DOC = <<<'EOF'
// Class aliases. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#class-aliases
EOF;

/** @var non-empty-string */
Expand Down Expand Up @@ -127,7 +127,7 @@ private static function createClassAliasStatementsSection(
$statements = self::wrapStatementsInNamespaceBlock($statements);
}

array_unshift($statements, self::EXPOSED_CLASSES_DOC);
array_unshift($statements, self::CLASS_ALIASES_DOC);

return $statements;
}
Expand Down Expand Up @@ -209,7 +209,7 @@ private static function createFunctionAliasStatements(
return $statements;
}

array_unshift($statements, self::EXPOSED_FUNCTIONS_DOC);
array_unshift($statements, self::FUNCTION_ALIASES_DOC);

return $statements;
}
Expand Down
32 changes: 16 additions & 16 deletions tests/Autoload/ScoperAutoloadGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public static function provideRegistry(): iterable
$loader = require_once __DIR__.'/autoload.php';
require_once __DIR__.'/composer/InstalledVersions.php';

// Exposed functions. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposing-functions
// Function aliases. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#function-aliases
if (!function_exists('foo')) {
function foo() {
return \Humbug\foo(...func_get_args());
Expand Down Expand Up @@ -105,8 +105,8 @@ function bar() {
require_once __DIR__.'/composer/InstalledVersions.php';
}

// Exposed functions. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposing-functions
// Function aliases. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#function-aliases
namespace Acme {
if (!function_exists('Acme\foo')) {
function foo() {
Expand Down Expand Up @@ -151,8 +151,8 @@ function baz() {
$loader = require_once __DIR__.'/autoload.php';
require_once __DIR__.'/composer/InstalledVersions.php';

// Exposed classes. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposing-classes
// Class aliases. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#class-aliases
if (!class_exists('A\Foo', false) && !interface_exists('A\Foo', false) && !trait_exists('A\Foo', false)) {
spl_autoload_call('Humbug\A\Foo');
}
Expand All @@ -178,8 +178,8 @@ function baz() {
$loader = require_once __DIR__.'/autoload.php';
require_once __DIR__.'/composer/InstalledVersions.php';

// Exposed classes. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposing-classes
// Class aliases. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#class-aliases
if (!class_exists('Foo', false) && !interface_exists('Foo', false) && !trait_exists('Foo', false)) {
spl_autoload_call('Humbug\Foo');
}
Expand Down Expand Up @@ -215,16 +215,16 @@ function baz() {
require_once __DIR__.'/composer/InstalledVersions.php';
}

// Exposed classes. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposing-classes
// Class aliases. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#class-aliases
namespace {
if (!class_exists('A\Foo', false) && !interface_exists('A\Foo', false) && !trait_exists('A\Foo', false)) {
spl_autoload_call('Humbug\A\Foo');
}
}

// Exposed functions. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposing-functions
// Function aliases. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#function-aliases
namespace {
if (!function_exists('foo')) {
function foo() {
Expand Down Expand Up @@ -284,8 +284,8 @@ function baz() {
$loader = require_once __DIR__.'/autoload.php';
require_once __DIR__.'/composer/InstalledVersions.php';

// Exposed functions. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposing-functions
// Function aliases. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#function-aliases
if (!function_exists('__autoload')) {
function __autoload($className) {
return \Humbug\__autoload(...func_get_args());
Expand Down Expand Up @@ -316,8 +316,8 @@ function __autoload($className) {
require_once __DIR__.'/composer/InstalledVersions.php';
}

// Exposed functions. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/configuration.md#exposing-functions
// Function aliases. For more information see:
// https://github.com/humbug/php-scoper/blob/master/docs/further-reading.md#function-aliases
namespace {
if (!function_exists('__autoload')) {
function __autoload($className) {
Expand Down