-
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simplify PhpScoper integration & Make the scoping prefix unique (#121)
Add an adapter for PHP-Scoper which: - Removes the dependency on the configuration API - Simplify the scoping signature - Avoid to pass around the whole PHP-Scoper config The new integration also ensure the scoping is done with a random prefix.
- Loading branch information
Showing
13 changed files
with
358 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the box project. | ||
* | ||
* (c) Kevin Herrera <kevin@herrera.io> | ||
* Théo Fidry <theo.fidry@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace KevinGH\Box\PhpScoper; | ||
|
||
use Humbug\PhpScoper\Scoper; | ||
use KevinGH\Box\NotCallable; | ||
|
||
final class FakePhpScoper implements Scoper | ||
{ | ||
use NotCallable; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function scope(string $filePath, string $contents, string $prefix, array $patchers, array $whitelist): string | ||
{ | ||
$this->__call(__METHOD__, func_get_args()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the box project. | ||
* | ||
* (c) Kevin Herrera <kevin@herrera.io> | ||
* Théo Fidry <theo.fidry@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace KevinGH\Box\PhpScoper; | ||
|
||
final class NullScoper implements Scoper | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function scope(string $filePath, string $contents): string | ||
{ | ||
return $contents; | ||
} | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getWhitelist(): array | ||
{ | ||
return []; | ||
} | ||
|
||
public function getPrefix(): string | ||
{ | ||
return ''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the box project. | ||
* | ||
* (c) Kevin Herrera <kevin@herrera.io> | ||
* Théo Fidry <theo.fidry@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace KevinGH\Box\PhpScoper; | ||
|
||
interface Scoper | ||
{ | ||
/** | ||
* Scope AKA. apply the given prefix to the file in the appropriate way. | ||
* | ||
* @param string $filePath File to scope | ||
* @param string $contents File contents | ||
* | ||
* @return string Contents of the file with the prefix applied | ||
*/ | ||
public function scope(string $filePath, string $contents): string; | ||
|
||
/** | ||
* @return string[] | ||
*/ | ||
public function getWhitelist(): array; | ||
|
||
public function getPrefix(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the box project. | ||
* | ||
* (c) Kevin Herrera <kevin@herrera.io> | ||
* Théo Fidry <theo.fidry@gmail.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace KevinGH\Box\PhpScoper; | ||
|
||
use Humbug\PhpScoper\Scoper as PhpScoper; | ||
|
||
final class SimpleScoper implements Scoper | ||
{ | ||
private $scoper; | ||
private $prefix; | ||
private $whitelist; | ||
private $patchers; | ||
|
||
public function __construct(PhpScoper $scoper, string $prefix, array $whitelist, array $patchers) | ||
{ | ||
$this->scoper = $scoper; | ||
$this->prefix = $prefix; | ||
$this->whitelist = $whitelist; | ||
$this->patchers = $patchers; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function scope(string $filePath, string $contents): string | ||
{ | ||
return $this->scoper->scope( | ||
$filePath, | ||
$contents, | ||
$this->prefix, | ||
$this->patchers, | ||
$this->whitelist | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getWhitelist(): array | ||
{ | ||
return $this->whitelist; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getPrefix(): string | ||
{ | ||
return $this->prefix; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.