File tree 1 file changed +41
-0
lines changed
1 file changed +41
-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 {
17
+ $ pattern = <<<'PHP'
18
+ (function () use ($input) {
19
+ $resource = fopen($value, 'r');
20
+ if ($resource === false) {
21
+ throw new \RuntimeException('Could not open file.');
22
+ }
23
+ if(!is_readable($resource)) {
24
+ throw new \RuntimeException('Could not read the file.');
25
+ }
26
+ return $ressource;
27
+ })()
28
+ PHP;
29
+
30
+ return sprintf ($ pattern , $ value );
31
+ },
32
+ function (string $ value ) {
33
+ $ resource = fopen ($ value , 'r ' );
34
+ if ($ resource === false ) {
35
+ throw new \RuntimeException ('Could not open file. ' );
36
+ }
37
+ return $ resource ;
38
+ },
39
+ );
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments