4
4
5
5
namespace PhpSchool \PhpWorkshop \Solution ;
6
6
7
+ use PhpSchool \PhpWorkshop \Utils \System ;
7
8
use Symfony \Component \Filesystem \Filesystem ;
8
9
9
- class InMemorySolution implements SolutionInterface
10
+ class InTempSolution implements SolutionInterface
10
11
{
11
12
/**
12
13
* @var string
13
14
*/
14
15
private string $ baseDirectory ;
15
16
17
+ /**
18
+ * @var string
19
+ */
20
+ private string $ entryPoint ;
21
+
16
22
/**
17
23
* @var SolutionFile[]
18
24
*/
@@ -22,21 +28,22 @@ private function __construct(SolutionInterface $solution)
22
28
{
23
29
$ fileSystem = new Filesystem ();
24
30
25
- $ currentPath = explode ('/ ' , realpath (__DIR__ ));
26
- $ solutionPath = explode ('/ ' , realpath ($ solution ->getBaseDirectory ()));
27
- $ entryPointPath = explode ('/ ' , realpath ($ solution ->getEntryPoint ()));
31
+ $ tempDir = System::tempDir ();
32
+ $ currentPath = explode ('/ ' , System::realpath (__DIR__ ));
33
+ $ solutionPath = explode ('/ ' , System::realpath ($ solution ->getBaseDirectory ()));
34
+ $ entryPointPath = explode ('/ ' , System::realpath ($ solution ->getEntryPoint ()));
28
35
29
36
$ intersection = array_intersect ($ currentPath , $ solutionPath );
30
37
31
38
if (count ($ intersection ) <= 1 ) {
32
- $ intersection = explode ('/ ' , realpath ( sys_get_temp_dir ()) );
39
+ $ intersection = explode ('/ ' , $ tempDir );
33
40
}
34
41
35
42
$ basename = implode ('/ ' , array_diff ($ solutionPath , $ intersection ));
36
43
$ entrypoint = implode ('/ ' , array_diff ($ entryPointPath , $ intersection ));
37
44
38
- $ this ->baseDirectory = sprintf ('%s/php-school/%s ' , realpath ( sys_get_temp_dir ()) , $ basename );
39
- $ this ->entryPoint = sprintf ('%s/php-school/%s ' , realpath ( sys_get_temp_dir ()) , $ entrypoint );
45
+ $ this ->baseDirectory = sprintf ('%s/php-school/%s ' , $ tempDir , $ basename );
46
+ $ this ->entryPoint = sprintf ('%s/php-school/%s ' , $ tempDir , $ entrypoint );
40
47
41
48
if ($ fileSystem ->exists ($ this ->baseDirectory )) {
42
49
$ fileSystem ->remove ($ this ->baseDirectory );
@@ -57,14 +64,14 @@ private function __construct(SolutionInterface $solution)
57
64
: $ fileSystem ->copy ($ file ->getPathname (), $ target );
58
65
}
59
66
60
- $ this ->files = array_map (function (SolutionFile $ solutionFile ) use ($ intersection ) {
61
- $ filePath = explode ('/ ' , realpath ($ solutionFile ->__toString ()));
67
+ $ this ->files = array_map (function (SolutionFile $ solutionFile ) use ($ intersection, $ tempDir ) {
68
+ $ filePath = explode ('/ ' , System:: realpath ($ solutionFile ->__toString ()));
62
69
$ file = implode ('/ ' , array_diff ($ filePath , $ intersection ));
63
- return SolutionFile::fromFile (sprintf ('%s/php-school/%s ' , realpath ( sys_get_temp_dir ()) , $ file ));
70
+ return SolutionFile::fromFile (sprintf ('%s/php-school/%s ' , $ tempDir , $ file ));
64
71
}, $ solution ->getFiles ());
65
72
}
66
73
67
- public static function fromSolution (SolutionInterface $ solution )
74
+ public static function fromSolution (SolutionInterface $ solution ): SolutionInterface
68
75
{
69
76
return new self ($ solution );
70
77
}
0 commit comments