Skip to content
This repository was archived by the owner on Dec 27, 2023. It is now read-only.

Commit 712db67

Browse files
committed
More boring work
1 parent d99e0fc commit 712db67

File tree

4 files changed

+48
-8
lines changed

4 files changed

+48
-8
lines changed

src/Command/InstallCommand.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ final class InstallCommand extends Command
1515
{
1616
const RETURN_CODE_OK = 0;
1717
const RETURN_CODE_INSTALLER_INSTANTIATION_ERROR = 1;
18+
const RETURN_CODE_INSTALLER_INSTALL_ERROR = 2;
1819

1920
protected function configure()
2021
{
@@ -50,14 +51,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
5051
$io = $this->getIO();
5152

5253
try {
53-
$installer = Installer::getInstaller($composerCmd, $installPath);
54+
$installer = Installer::getInstaller($composerCmd);
5455
} catch (\RuntimeException $e) {
5556
$io->writeError('ERROR: '.$e->getMessage());
5657
// TODO : Use verbosity levels to enable showing the stacktrace
5758
return self::RETURN_CODE_INSTALLER_INSTANTIATION_ERROR;
5859
}
5960

60-
61+
try {
62+
$installer->install($installPath);
63+
} catch (\RuntimeException $e) {
64+
$io->writeError('ERROR: '.$e->getMessage());
65+
// TODO : Use verbosity levels to enable showing the stacktrace
66+
return self::RETURN_CODE_INSTALLER_INSTALL_ERROR;
67+
}
6168

6269
return self::RETURN_CODE_OK;
6370
}

src/Installer/Installer.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ abstract class Installer
1919

2020
/**
2121
* @param null|string $composerCmd
22-
* @param null|string $installPath
2322
* @return Installer
2423
*/
25-
public static function getInstaller($composerCmd = null, $installPath = null)
24+
public static function getInstaller($composerCmd = null)
2625
{
2726
$system = System::getSystem();
2827
$composerCmd = (null !== $composerCmd) ? $composerCmd : $system->getComposerCommand();
@@ -31,10 +30,6 @@ public static function getInstaller($composerCmd = null, $installPath = null)
3130
throw new \RuntimeException('Unable to find the composer executable.');
3231
}
3332

34-
if (null !== $installPath && !$system->validatePath($installPath)) {
35-
throw new \RuntimeException('Invalid install path.');
36-
}
37-
3833
if ($system instanceof UnixSystem) {
3934
return new LinuxInstaller($system, $composerCmd);
4035
} elseif ($system instanceof MacSystem) {
@@ -46,6 +41,24 @@ public static function getInstaller($composerCmd = null, $installPath = null)
4641
}
4742
}
4843

44+
/**
45+
* @param null|string $installPath
46+
*/
47+
public function install($installPath = null)
48+
{
49+
$installPath = (null !== $installPath) ? $installPath : $this->getInstallPath();
50+
if (null !== $installPath && !$this->system->validatePath($installPath)) {
51+
throw new \RuntimeException('Invalid install path.');
52+
}
53+
54+
$this->system->ensurePath($installPath);
55+
}
56+
57+
/**
58+
* @return string
59+
*/
60+
public abstract function getInstallPath();
61+
4962
/**
5063
* Installer constructor.
5164
* @param System $system

src/Installer/LinuxInstaller.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,18 @@ public function __construct(UnixSystem $system, $composerCmd)
1818
{
1919
parent::__construct($system, $composerCmd);
2020
}
21+
22+
/**
23+
* @return string
24+
*/
25+
public function getInstallPath()
26+
{
27+
$currentUser = $this->system->getCurrentUser();
28+
29+
if ('root' === $currentUser) {
30+
return '/opt/jupyter-php';
31+
} else {
32+
return $this->system->getCurrentUserHome().'/.jupyter-php';
33+
}
34+
}
2135
}

src/System/UnixSystem.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,13 @@ public function validatePath($path)
114114
*/
115115
public function ensurePath($path)
116116
{
117+
$absPath = $this->getAbsolutePath($path);
118+
119+
if (false === mkdir($this->getAbsolutePath($path), 0744, true)) {
120+
throw new \RuntimeException('Unable to create the specified directory ('.$absPath.').');
121+
}
117122

123+
return $absPath;
118124
}
119125

120126
/**

0 commit comments

Comments
 (0)