-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComposer.php
108 lines (91 loc) · 2.62 KB
/
Composer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace abhishek6262\Composer;
require_once __DIR__ . "/functions.php";
require_once __DIR__ . "/System/Environment.php";
require_once __DIR__ . "/System/Response.php";
use abhishek6262\Composer\System\Environment;
use abhishek6262\Composer\System\Response;
/**
* Class Composer
* @package abhishek6262\Composer
*/
class Composer
{
/**
* @var Environment
*/
protected $environment;
/**
* Composer constructor.
*
* @param string $rootPath (Absolute Path [__DIR__]) The root directory of the project where composer.json file is stored.
* @param string $binPath (Absolute Path [__DIR__]) The directory where the composer should be installed.
*/
public function __construct(string $rootPath, string $binPath = '')
{
$this->environment = new Environment($rootPath, $binPath);
}
/**
* Executes the raw composer command.
*
* @param string $command
*
* @return Response
*/
public function rawCommand(string $command): Response
{
$CURRENT_WORKING_DIRECTORY = getcwd();
chdir($this->environment->rootPath);
$MAX_EXECUTION_TIME = 1800; // "30 Mins" for slow internet connections.
set_time_limit($MAX_EXECUTION_TIME);
exec( escapeshellcmd($this->environment->getPHPPath() . " " . $this->environment->binPath . "/composer " . $command) . " 2>&1", $message, $code );
chdir($CURRENT_WORKING_DIRECTORY);
return new Response($message, $code);
}
/**
* Determines whether composer is installed in the project.
*
* @return bool
*/
public function exists(): bool
{
return file_exists($this->environment->binPath . "/composer") ? true : false;
}
/**
* Installs composer in the project.
*
* @return void
*/
public function install()
{
$this->environment->install();
}
/**
* Installs the packages present in the composer.json file.
*
* @return Response
*/
public function installPackages(): Response
{
return $this->rawCommand("install");
}
/**
* Determines whether the project has packages to be installed.
*
* @return bool
*/
public function packagesExists(): bool
{
return file_exists($this->environment->rootPath . "/composer.json") ? true : false;
}
/**
* Determines whether the packages are already installed in the
* project.
*
* @return bool
*/
public function packagesInstalled(): bool
{
return file_exists($this->environment->rootPath . "/vendor/") ? true : false;
}
}