Sha256: cb9ecb0f4b557c86769eb93a379774fb2cdd717165a09c1ede534a2845527b2a

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

#!/usr/bin/env php
<?php

$projectDirHost = dirname(dirname(dirname($_SERVER['PHP_SELF'])));
$projectDirGuest = '/vagrant';
$homeDirHost = $projectDirHost . '/.idea/vagrant';
$homeDirGuest = $projectDirGuest . '/.idea/vagrant';
$pipe = 'vagrant ssh -c ';

chdir($projectDirHost);

// Detect Host IP
$hostIpFile = $homeDirHost . '/host_ip';
if (!file_exists($hostIpFile)) {
	$ip = shell_exec('vagrant ssh -c "sudo ip route | awk \'/default/ { print \$3 }\'"');
	file_put_contents($hostIpFile, $ip);
}
$hostIp = trim(file_get_contents($hostIpFile));
if (!filter_var($hostIp, FILTER_VALIDATE_IP)) {
	throw new Exception('Cannot detect host IP, got value `' . $hostIp . '`.');
}


$arguments = $argv;
array_shift($arguments);
foreach ($arguments as $index => &$argument) {
	// IP mapping
	$argument = str_replace(array('127.0.0.1', 'localhost'), $hostIp, $argument);

	// Paths mapping
	$filePath = $argument;
	if (file_exists($filePath)) {
		if (strpos($filePath, $projectDirHost) !== false) {
			// Mapping project paths to remote paths
			$arguments[$index] = str_replace($projectDirHost, $projectDirGuest, $filePath);
		} else {
			// Mapping any other local system paths to remote paths, upload files
			if(!is_dir($homeDirHost . '/scripts/')) {
				mkdir($homeDirHost . '/scripts/', 0777, true);
			}
			copy($filePath, $homeDirHost . '/scripts/' . basename($filePath));
			$arguments[$index] = $homeDirGuest . '/scripts/' . basename($filePath);
		}
	}

	$argument = escapeshellarg($argument);
}


// Get XDEBUG environment variable
$env = '';
if (isset($_SERVER['XDEBUG_CONFIG'])) {
	$env = "XDEBUG_CONFIG='" . $_SERVER['XDEBUG_CONFIG'] . "'";
}

$includePaths = array('.', $projectDirGuest . '/vendor/phpunit/phpunit');
$arguments = array_merge(array('-d', 'include_path=' . implode(':', $includePaths)), $arguments);

passthru($pipe . '"' . $env . ' php ' . implode(' ', $arguments) . '"');

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vagrant-phpstorm-tunnel-0.1.1 data/php