Skip to content

Commit

Permalink
Make it work
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry committed Aug 3, 2018
1 parent f36c50a commit f1dea1e
Show file tree
Hide file tree
Showing 22 changed files with 158 additions and 53 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ e2e_027: bin/php-scoper.phar fixtures/set027-laravel/vendor
--force \
--no-interaction \
--stop-on-failure
composer --working-dir=build/set027-laravel dump-autoload
composer --working-dir=build/set027-laravel dump-autoload --no-dev

php build/set027-laravel/artisan -V > build/set027-laravel/output
diff fixtures/set027-laravel/expected-output build/set027-laravel/output
Expand Down Expand Up @@ -369,7 +369,7 @@ fixtures/set026/vendor:
touch $@

fixtures/set027-laravel/vendor: fixtures/set027-laravel/composer.lock
composer --working-dir=fixtures/set027 install
composer --working-dir=fixtures/set027-laravel install --no-dev
touch $@

composer.lock: composer.json
Expand Down
6 changes: 5 additions & 1 deletion fixtures/set027-laravel/artisan
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ define('LARAVEL_START', microtime(true));
|
*/

require __DIR__.'/vendor/autoload.php';
if (file_exists(__DIR__.'/vendor/scoper-autoload.php')) {
require __DIR__.'/vendor/scoper-autoload.php';
} else {
require __DIR__.'/vendor/autoload.php';
}

$app = require_once __DIR__.'/bootstrap/app.php';

Expand Down
50 changes: 0 additions & 50 deletions fixtures/set027-laravel/config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,54 +161,4 @@
App\Providers\RouteServiceProvider::class,

],

/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
|
| This array of class aliases will be registered when this application
| is started. However, feel free to register as many as you wish as
| the aliases are "lazy" loaded so they don't hinder performance.
|
*/

'aliases' => [

'App' => Illuminate\Support\Facades\App::class,
'Artisan' => Illuminate\Support\Facades\Artisan::class,
'Auth' => Illuminate\Support\Facades\Auth::class,
'Blade' => Illuminate\Support\Facades\Blade::class,
'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
'Bus' => Illuminate\Support\Facades\Bus::class,
'Cache' => Illuminate\Support\Facades\Cache::class,
'Config' => Illuminate\Support\Facades\Config::class,
'Cookie' => Illuminate\Support\Facades\Cookie::class,
'Crypt' => Illuminate\Support\Facades\Crypt::class,
'DB' => Illuminate\Support\Facades\DB::class,
'Eloquent' => Illuminate\Database\Eloquent\Model::class,
'Event' => Illuminate\Support\Facades\Event::class,
'File' => Illuminate\Support\Facades\File::class,
'Gate' => Illuminate\Support\Facades\Gate::class,
'Hash' => Illuminate\Support\Facades\Hash::class,
'Lang' => Illuminate\Support\Facades\Lang::class,
'Log' => Illuminate\Support\Facades\Log::class,
'Mail' => Illuminate\Support\Facades\Mail::class,
'Notification' => Illuminate\Support\Facades\Notification::class,
'Password' => Illuminate\Support\Facades\Password::class,
'Queue' => Illuminate\Support\Facades\Queue::class,
'Redirect' => Illuminate\Support\Facades\Redirect::class,
'Redis' => Illuminate\Support\Facades\Redis::class,
'Request' => Illuminate\Support\Facades\Request::class,
'Response' => Illuminate\Support\Facades\Response::class,
'Route' => Illuminate\Support\Facades\Route::class,
'Schema' => Illuminate\Support\Facades\Schema::class,
'Session' => Illuminate\Support\Facades\Session::class,
'Storage' => Illuminate\Support\Facades\Storage::class,
'URL' => Illuminate\Support\Facades\URL::class,
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,

],

];
1 change: 1 addition & 0 deletions fixtures/set027-laravel/expected-output
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Laravel Framework 5.6.26
1 change: 1 addition & 0 deletions fixtures/set027-laravel/routes/api.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions fixtures/set027-laravel/routes/channels.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
|
*/

use Illuminate\Support\Facades\Broadcast;

Broadcast::channel('App.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
1 change: 1 addition & 0 deletions fixtures/set027-laravel/routes/console.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan;

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions fixtures/set027-laravel/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
|
*/

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
return view('welcome');
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
19 changes: 19 additions & 0 deletions src/Scoper/Composer/AutoloadPrefixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

namespace Humbug\PhpScoper\Scoper\Composer;

use function array_map;
use Humbug\PhpScoper\Whitelist;
use stdClass;

Expand All @@ -38,6 +39,10 @@ public static function prefixPackageAutoloads(stdClass $contents, string $prefix
$contents->{'autoload-dev'} = self::prefixAutoloads($contents->{'autoload-dev'}, $prefix, $whitelist);
}

if (isset($contents->extra, $contents->extra->laravel, $contents->extra->laravel->providers)) {
$contents->extra->laravel->providers = self::prefixLaravelProviders($contents->extra->laravel->providers, $prefix, $whitelist);
}

return $contents;
}

Expand All @@ -62,6 +67,7 @@ private static function prefixAutoloads(stdClass $autoload, string $prefix, Whit
return $autoload;
}


private static function prefixAutoload(array $autoload, string $prefix, Whitelist $whitelist): array
{
$loader = [];
Expand Down Expand Up @@ -163,4 +169,17 @@ private static function mergeNamespaces(string $psr0Namespace, $psr0Path, $psr4)

return $psr0Path;
}

private static function prefixLaravelProviders(array $providers, string $prefix, Whitelist $whitelist): array
{
return array_map(
function (string $provider) use ($prefix, $whitelist): string {
return $whitelist->belongsToWhitelistedNamespace($provider)
? $provider
: sprintf('%s\\%s', $prefix, $provider)
;
},
$providers
);
}
}
125 changes: 125 additions & 0 deletions tests/Scoper/Composer/InstalledPackagesScoperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,131 @@ public function provideInstalledPackagesFiles()
"platform": {}
}
]
JSON
];

yield [
<<<'JSON'
[
{
"name": "fideloper\/proxy",
"version": "4.0.0",
"version_normalized": "4.0.0.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/fideloper\/TrustedProxy.git",
"reference": "cf8a0ca4b85659b9557e206c90110a6a4dba980a"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/fideloper\/TrustedProxy\/zipball\/cf8a0ca4b85659b9557e206c90110a6a4dba980a",
"reference": "cf8a0ca4b85659b9557e206c90110a6a4dba980a",
"shasum": ""
},
"require": {
"illuminate\/contracts": "~5.0",
"php": ">=5.4.0"
},
"require-dev": {
"illuminate\/http": "~5.6",
"mockery\/mockery": "~1.0",
"phpunit\/phpunit": "^6.0"
},
"time": "2018-02-07T20:20:57+00:00",
"type": "library",
"extra": {
"laravel": {
"providers": [
"Fideloper\\Proxy\\TrustedProxyServiceProvider"
]
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Fideloper\\Proxy\\": "src\/"
}
},
"notification-url": "https:\/\/packagist.org\/downloads\/",
"license": [
"MIT"
],
"authors": [
{
"name": "Chris Fidao",
"email": "[email protected]"
}
],
"description": "Set trusted proxies for Laravel",
"keywords": [
"load balancing",
"proxy",
"trusted proxy"
]
}
]

JSON
,
<<<'JSON'
[
{
"name": "fideloper\/proxy",
"version": "4.0.0",
"version_normalized": "4.0.0.0",
"source": {
"type": "git",
"url": "https:\/\/github.com\/fideloper\/TrustedProxy.git",
"reference": "cf8a0ca4b85659b9557e206c90110a6a4dba980a"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/fideloper\/TrustedProxy\/zipball\/cf8a0ca4b85659b9557e206c90110a6a4dba980a",
"reference": "cf8a0ca4b85659b9557e206c90110a6a4dba980a",
"shasum": ""
},
"require": {
"illuminate\/contracts": "~5.0",
"php": ">=5.4.0"
},
"require-dev": {
"illuminate\/http": "~5.6",
"mockery\/mockery": "~1.0",
"phpunit\/phpunit": "^6.0"
},
"time": "2018-02-07T20:20:57+00:00",
"type": "library",
"extra": {
"laravel": {
"providers": [
"Foo\\Fideloper\\Proxy\\TrustedProxyServiceProvider"
]
}
},
"installation-source": "dist",
"autoload": {
"psr-4": {
"Foo\\Fideloper\\Proxy\\": "src\/"
}
},
"notification-url": "https:\/\/packagist.org\/downloads\/",
"license": [
"MIT"
],
"authors": [
{
"name": "Chris Fidao",
"email": "[email protected]"
}
],
"description": "Set trusted proxies for Laravel",
"keywords": [
"load balancing",
"proxy",
"trusted proxy"
]
}
]
JSON
];
}
Expand Down

0 comments on commit f1dea1e

Please sign in to comment.