File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace Kiboko \Component \Satellite \ExpressionLanguage ;
6
+
7
+ use PhpSpec \Locator \Resource ;
8
+ use Symfony \Component \ExpressionLanguage \ExpressionFunction ;
9
+
10
+ final class Download extends ExpressionFunction
11
+ {
12
+ public function __construct (string $ name )
13
+ {
14
+ parent ::__construct (
15
+ $ name ,
16
+ function (string $ value , string $ context = '' ): string {
17
+ $ pattern = <<<'PHP'
18
+ (function () use($input) {
19
+ $resource = \fopen(%s %s, 'r');
20
+ if ($resource === false) {
21
+ throw new \RuntimeException('Could not open file.');
22
+ }
23
+ return $resource;
24
+ })()
25
+ PHP;
26
+
27
+ return sprintf ($ pattern , $ value , $ context );
28
+ },
29
+ function (string $ value , string $ context = '' ) {
30
+ $ resource = fopen ($ context . $ value , 'r ' );
31
+ if ($ resource === false ) {
32
+ throw new \RuntimeException ('Could not open file. ' );
33
+ }
34
+ return $ resource ;
35
+ },
36
+ );
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments