Skip to content

Commit 74293c6

Browse files
authored
Isolate the PHAR with PHP-Scoper (#105)
1 parent 4e3fe53 commit 74293c6

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ before_install:
1818
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
1919
- export PATH="$PATH:$HOME/.composer/vendor/bin"
2020
- wget https://phar.phpunit.de/phpunit-6.3.phar
21+
- composer global require humbug/php-scoper:^1.0@dev
2122
- if [[ $coverage = 1 ]]; then mkdir -p build/logs; fi
2223
- if [[ $coverage = 1 ]]; then wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar; fi
2324
- if [[ $lint = 1 ]]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.4.0/php-cs-fixer.phar; fi
@@ -36,6 +37,8 @@ script:
3637
- |
3738
if [[ ! $deps && $TRAVIS_PHP_VERSION = "7.1" ]]; then
3839
composer install --no-dev --prefer-dist --classmap-authoritative --no-progress --no-suggest --ansi;
40+
~/.composer/vendor/bin/php-scoper add-prefix --output-dir=build/schema-generator;
41+
composer -d=build/schema-generator dump-autoload --classmap-authoritative --no-dev;
3942
php -d phar.readonly=0 box.phar build;
4043
php schema.phar generate-types tmp/ tests/e2e/schema.yml;
4144
diff tests/e2e/src/AppBundle/Entity/Person.php tmp/AppBundle/Entity/Person.php;

box.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"base-path": "build/schema-generator",
23
"directories": [
34
"data/",
45
"src/",

scoper.inc.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
use Isolated\Symfony\Component\Finder\Finder;
15+
16+
return [
17+
'finders' => [
18+
Finder::create()->files()
19+
->in('src')
20+
->in('data')
21+
->in('templates'),
22+
Finder::create()
23+
->files()
24+
->ignoreVCS(true)
25+
->notName('/LICENSE|.*\\.md|.*\\.dist|Makefile|composer\\.json|composer\\.lock/')
26+
->exclude([
27+
'doc',
28+
'test',
29+
'test_old',
30+
'tests',
31+
'Test',
32+
'Tests',
33+
])
34+
->in('vendor'),
35+
Finder::create()->append([
36+
'bin/schema',
37+
'composer.json',
38+
]),
39+
Finder::create()->append([
40+
'vendor/friendsofphp/php-cs-fixer/tests/Test',
41+
]),
42+
],
43+
'whitelist' => [
44+
'ApiPlatform\Core\Annotation\ApiProperty',
45+
'ApiPlatform\Core\Annotation\ApiResource',
46+
],
47+
'patchers' => [
48+
function (string $filePath, string $prefix, string $content): string {
49+
//
50+
// PHP-CS-Fixer patch
51+
//
52+
53+
if ($filePath === __DIR__.'/vendor/friendsofphp/php-cs-fixer/src/FixerFactory.php') {
54+
return preg_replace(
55+
'/\$fixerClass = \'PhpCsFixer(.*?\;)/',
56+
sprintf('$fixerClass = \'%s\\PhpCsFixer$1', $prefix),
57+
$content
58+
);
59+
}
60+
61+
return $content;
62+
},
63+
],
64+
];

0 commit comments

Comments
 (0)