Skip to content
This repository was archived by the owner on Feb 10, 2023. It is now read-only.

Commit acad0bd

Browse files
Expose ConcreteImplementation as non-internal
1 parent cebd9eb commit acad0bd

23 files changed

+52
-34
lines changed

src/Internal/ConcreteImplementation.php renamed to src/ConcreteImplementation.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,32 @@
77
* file that was distributed with this source code.
88
*/
99

10-
namespace FriendsOfPHP\WellKnownImplementations\Internal;
10+
namespace FriendsOfPHP\WellKnownImplementations;
1111

1212
use Composer\InstalledVersions;
1313

1414
/**
15-
* @internal
15+
* @author Nicolas Grekas <[email protected]>
1616
*/
1717
class ConcreteImplementation
1818
{
1919
public const PSR7_VENDOR = PSR7_VENDOR;
2020
public const PSR18_VENDOR = PSR18_VENDOR;
2121
public const HTTPLUG_VENDOR = HTTPLUG_VENDOR;
22+
23+
public const VENDOR_GUZZLE = 'Guzzle';
24+
public const VENDOR_HTTPLUG_CURL = 'HttplugCurl';
25+
public const VENDOR_HTTPLUG_GUZZLE6 = 'HttplugGuzzle6';
26+
public const VENDOR_HTTPLUG_GUZZLE7 = 'HttplugGuzzle7';
27+
public const VENDOR_HTTPLUG_REACT = 'HttplugReact';
28+
public const VENDOR_LAMINAS = 'Laminas';
29+
public const VENDOR_NYHOLM = 'Nyholm';
30+
public const VENDOR_PHP_SLIM = 'Slim';
31+
public const VENDOR_PHP_Symfony = 'Symfony';
32+
33+
/**
34+
* @internal
35+
*/
2236
public const IMPLEMENTATIONS = [
2337
'PSR7' => [
2438
'Nyholm' => 'nyholm/psr7',
@@ -32,13 +46,16 @@ class ConcreteImplementation
3246
],
3347
'HTTPLUG' => [
3448
'Symfony' => ['symfony/http-client' => '4.4'],
35-
'PhpHttpGuzzle7' => 'php-http/guzzle7-adapter',
36-
'PhpHttpGuzzle6' => 'php-http/guzzle6-adapter',
37-
'PhpHttpCurl' => 'php-http/curl-client',
38-
'PhpHttpReact' => 'php-http/react-adapter',
49+
'HttplugGuzzle7' => 'php-http/guzzle7-adapter',
50+
'HttplugGuzzle6' => 'php-http/guzzle6-adapter',
51+
'HttplugCurl' => 'php-http/curl-client',
52+
'HttplugReact' => 'php-http/react-adapter',
3953
],
4054
];
4155

56+
/**
57+
* @internal
58+
*/
4259
public static function initialize(): void
4360
{
4461
foreach (self::IMPLEMENTATIONS as $const => $packages) {

src/Internal/ComposerPlugin.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@
2626
use Composer\Script\Event;
2727
use Composer\Script\ScriptEvents;
2828
use Composer\Util\Filesystem;
29+
use FriendsOfPHP\WellKnownImplementations\ConcreteImplementation;
2930

3031
/**
32+
* @author Nicolas Grekas <[email protected]>
33+
*
3134
* @internal
3235
*/
3336
class ComposerPlugin implements PluginInterface, EventSubscriberInterface
@@ -88,35 +91,41 @@ public function uninstall(Composer $composer, IOInterface $io)
8891
public function preAutoloadDump(Event $event)
8992
{
9093
$filesystem = new Filesystem();
91-
$vendor = $filesystem->normalizePath(realpath(realpath($event->getComposer()->getConfig()->get('vendor-dir'))));
92-
$filesystem->ensureDirectoryExists($vendor.'/composer');
94+
$vendorDir = $filesystem->normalizePath(realpath(realpath($event->getComposer()->getConfig()->get('vendor-dir'))));
95+
$filesystem->ensureDirectoryExists($vendorDir.'/composer');
9396

9497
$repo = $event->getComposer()->getRepositoryManager()->getLocalRepository();
9598
$vendors = self::initializeConcreteImplementation($repo);
9699

97-
$namespace = __NAMESPACE__;
98100
$psr7Vendor = str_replace(['NULL', '\\\\'], ['null', '\\'], var_export(PSR7_VENDOR, true));
99101
$psr18Vendor = str_replace(['NULL', '\\\\'], ['null', '\\'], var_export(PSR18_VENDOR, true));
100102
$httplugVendor = str_replace(['NULL', '\\\\'], ['null', '\\'], var_export(HTTPLUG_VENDOR, true));
101103

102-
$filesystem->filePutContentsIfModified($vendor.'/composer/WellKnownConcreteImplementation.php', <<<EOPHP
104+
natcasesort($vendors);
105+
$vendorConsts = '';
106+
foreach ($vendors as $vendor) {
107+
$vendorConsts .= "\n public const VENDOR".strtoupper(preg_replace('/[A-Z]++/', '_$0', $vendor)).' = '.var_export($vendor, true).';';
108+
}
109+
110+
$filesystem->filePutContentsIfModified($vendorDir.'/composer/WellKnownConcreteImplementation.php', <<<EOPHP
103111
<?php
104112
105-
namespace $namespace;
113+
namespace FriendsOfPHP\WellKnownImplementations;
106114
107115
class ConcreteImplementation
108116
{
109117
public const PSR7_VENDOR = $psr7Vendor;
110118
public const PSR18_VENDOR = $psr18Vendor;
111119
public const HTTPLUG_VENDOR = $httplugVendor;
120+
$vendorConsts
112121
}
113122
114123
EOPHP
115124
);
116125

117126
$rootPackage = $event->getComposer()->getPackage();
118127
$autoload = $rootPackage->getAutoload();
119-
$autoload['classmap'][] = $vendor.'/composer/WellKnownConcreteImplementation.php';
128+
$autoload['classmap'][] = $vendorDir.'/composer/WellKnownConcreteImplementation.php';
120129
$rootPackage->setAutoload($autoload);
121130

122131
unset($vendors[PSR7_VENDOR], $vendors[PSR18_VENDOR], $vendors[HTTPLUG_VENDOR]);
@@ -126,8 +135,8 @@ class ConcreteImplementation
126135
continue;
127136
}
128137
$autoload = $package->getAutoload();
138+
$autoload['exclude-from-classmap'][] = 'src/ConcreteImplementation.php';
129139
$autoload['exclude-from-classmap'][] = 'src/Internal/ComposerPlugin.php';
130-
$autoload['exclude-from-classmap'][] = 'src/Internal/ConcreteImplementation.php';
131140
foreach ($vendors as $vendor) {
132141
$autoload['exclude-from-classmap'][] = 'src/Internal/'.$vendor.'/';
133142
}

src/Internal/PhpHttpCurl/PhpHttpCurlHttplugClient.php renamed to src/Internal/HttplugCurl/HttplugCurlHttplugClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
* file that was distributed with this source code.
88
*/
99

10-
namespace FriendsOfPHP\WellKnownImplementations\Internal\PhpHttpCurl;
10+
namespace FriendsOfPHP\WellKnownImplementations\Internal\HttplugCurl;
1111

1212
use FriendsOfPHP\WellKnownImplementations\WellKnownPsr17Factory;
1313
use Http\Client\Curl\Client;
1414

1515
/**
1616
* @internal
1717
*/
18-
class PhpHttpCurlHttplugClient extends Client
18+
class HttplugCurlHttplugClient extends Client
1919
{
2020
public function __construct()
2121
{

src/Internal/PhpHttpGuzzle6/PhpHttpGuzzle6HttplugClient.php renamed to src/Internal/HttplugGuzzle6/HttplugGuzzle6HttplugClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
* file that was distributed with this source code.
88
*/
99

10-
namespace FriendsOfPHP\WellKnownImplementations\Internal\PhpHttpGuzzle6;
10+
namespace FriendsOfPHP\WellKnownImplementations\Internal\HttplugGuzzle6;
1111

1212
use Http\Adapter\Guzzle6\Client;
1313

14-
class_alias(Client::class, PhpHttpGuzzle6HttplugClient::class);
14+
class_alias(Client::class, HttplugGuzzle6HttplugClient::class);
1515

1616
if (false) {
1717
/**
1818
* @internal
1919
*/
20-
class PhpHttpGuzzle6HttplugClient extends Client
20+
class HttplugGuzzle6HttplugClient extends Client
2121
{
2222
public function __construct()
2323
{

src/Internal/PhpHttpGuzzle7/PhpHttpGuzzle7HttplugClient.php renamed to src/Internal/HttplugGuzzle7/HttplugGuzzle7HttplugClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
* file that was distributed with this source code.
88
*/
99

10-
namespace FriendsOfPHP\WellKnownImplementations\Internal\PhpHttpGuzzle7;
10+
namespace FriendsOfPHP\WellKnownImplementations\Internal\HttplugGuzzle7;
1111

1212
use Http\Adapter\Guzzle7\Client;
1313

14-
class_alias(Client::class, PhpHttpGuzzle7HttplugClient::class);
14+
class_alias(Client::class, HttplugGuzzle7HttplugClient::class);
1515

1616
if (false) {
1717
/**
1818
* @internal
1919
*/
20-
class PhpHttpGuzzle7HttplugClient extends Client
20+
class HttplugGuzzle7HttplugClient extends Client
2121
{
2222
public function __construct()
2323
{

src/Internal/PhpHttpReact/PhpHttpReactHttplugClient.php renamed to src/Internal/HttplugReact/HttplugReactHttplugClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
* file that was distributed with this source code.
88
*/
99

10-
namespace FriendsOfPHP\WellKnownImplementations\Internal\PhpHttpReact;
10+
namespace FriendsOfPHP\WellKnownImplementations\Internal\HttplugReact;
1111

1212
use Http\Adapter\React\Client;
1313

14-
class_alias(Client::class, PhpHttpReactHttplugClient::class);
14+
class_alias(Client::class, HttplugReactHttplugClient::class);
1515

1616
if (false) {
1717
/**
1818
* @internal
1919
*/
20-
class PhpHttpReactHttplugClient extends Client
20+
class HttplugReactHttplugClient extends Client
2121
{
2222
public function __construct()
2323
{

src/WellKnownHttplugClient.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace FriendsOfPHP\WellKnownImplementations;
1111

12-
use FriendsOfPHP\WellKnownImplementations\Internal\ConcreteImplementation;
1312
use Http\Client\HttpAsyncClient;
1413
use Http\Client\HttpClient;
1514

src/WellKnownPsr18Client.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace FriendsOfPHP\WellKnownImplementations;
1111

12-
use FriendsOfPHP\WellKnownImplementations\Internal\ConcreteImplementation;
1312
use Psr\Http\Client\ClientInterface;
1413

1514
if (null !== $vendor = ConcreteImplementation::PSR18_VENDOR) {

src/WellKnownPsr7Request.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace FriendsOfPHP\WellKnownImplementations;
1111

12-
use FriendsOfPHP\WellKnownImplementations\Internal\ConcreteImplementation;
1312
use Psr\Http\Message\RequestInterface;
1413
use Psr\Http\Message\UriInterface;
1514

src/WellKnownPsr7Response.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
namespace FriendsOfPHP\WellKnownImplementations;
1111

12-
use FriendsOfPHP\WellKnownImplementations\Internal\ConcreteImplementation;
1312
use Psr\Http\Message\ResponseInterface;
1413

1514
if (null !== $vendor = ConcreteImplementation::PSR7_VENDOR) {

0 commit comments

Comments
 (0)