Completed
Push — master ( 36a006...f90c70 )
by CodexShaper
04:12
created

InstallComposer::__construct()   A

Complexity

Conditions 3
Paths 6

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 12
nc 6
nop 0
dl 0
loc 18
rs 9.8666
c 1
b 0
f 0
1
<?php
2
/**
3
 * Install composer.
4
 *
5
 * @link       https://github.com/maab16
6
 * @since      1.0.0
7
 *
8
 * @package    WPB
9
 * @subpackage WPB/app/Commands
10
 */
11
12
 /**
13
  * Register all actions and filters for the plugin.
14
  *
15
  * Maintain a list of all hooks that are registered throughout
16
  * the plugin, and register them with the WordPress API. Call the
17
  * run function to execute the list of actions and filters.
18
  *
19
  * @package    WPB
20
  * @subpackage WPB/app/Commands
21
  * @author     Md Abu Ahsan basir <[email protected]>
22
  */
23
class InstallComposer {
24
25
	/**
26
	 * Install composer factory.
27
	 *
28
	 * @since    1.0.0
29
	 */
30
	public function __construct() {
31
		if ( ! file_exists( __DIR__ . '/../vendor/autoload.php' ) ) {
32
33
			require_once __DIR__ . '/../vendor/autoload.php';
34
35
			$composer = 'composer';
36
37
			try {
38
				$process = \Symfony\Component\Process\Process::fromShellCommandline( $composer . ' install' );
39
				$process->setEnv(
40
					array(
41
						'COMPOSER_HOME' => __DIR__ . '/../vendor/bin/composer',
42
					)
43
				);
44
				$process->setTimeout( null ); // Setting timeout to null to prevent installation from stopping at a certain point in time.
45
				$process->setWorkingDirectory( __DIR__ )->mustRun();
46
			} catch ( \Exception $ex ) {
47
				echo $ex->getMessage();
48
			}
49
		}
50
	}
51
}
52