vagrant-phpstorm-tunnel 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99902a60cfbac6ae8a05ed6403be0cd9f425b43c
4
- data.tar.gz: 807967bcf01eae61de44c79a97fe8cb3bb586ec8
3
+ metadata.gz: 1d9482a0100d5aa82f72d85ec121f834ed681449
4
+ data.tar.gz: 7c8e625a46c9cb041b948534125b82be649331be
5
5
  SHA512:
6
- metadata.gz: e7604c8431c15ab95bd8cbc469d4430d8735c2f07c957da78d293f4c63c9a9684420165616a144edff4760197320b6dd6d3fb2b47b5057282a26e0555e4f410f
7
- data.tar.gz: ebd7f35aed9918615647ca846563a9b9fff69d8ea6cd3830bbeb9c14309e32363389cc3cc54d84459f8b0b0c2204b081e8d5d9c6511708b8f2808fbcfb1ff719
6
+ metadata.gz: c188fb3c973efa43ee60f97d275f47383709333524e375b7b85fc7fd16b766bc6f54c04894b0ecac468207925ef46c13d9fdb37dcacd3575356ddff3d1289ecf
7
+ data.tar.gz: 46fb36af966247aad6d27a54696a8bf9804d2817dadabac9786ec3a98e6aa6e3b8b425c47efcc1a61f6c768f65ff1d44d31ad50fc2730fb9c53d9b8fa8d6530c
data/README.md CHANGED
@@ -1,23 +1,23 @@
1
1
  vagrant-phpstorm-tunnel
2
- ==============================
2
+ =======================
3
+ `vagrant-phpstorm-tunnel` installs a proxy php binary which can be configured as a php-interpreter in [PhpStorm](http://www.jetbrains.com/phpstorm/).
4
+ It will forward all php calls to `php` in the [Vagrant](http://www.vagrantup.com/) VM.
3
5
 
4
- `vagrant-phpstorm-tunnel` creates tunnel between [PHPStorm](http://www.jetbrains.com/phpstorm/) and [Vagrant](http://www.vagrantup.com/) machine to allow executing [PHP](http://php.net/) via [SSH](http://en.wikipedia.org/wiki/Secure_Shell)
6
+ This is a workaround for a missing feature in PhpStorm (see http://youtrack.jetbrains.com/issue/WI-19485).
5
7
 
6
- ## Installation
7
-
8
- $ vagrant plugin install vagrant-phpstorm-tunnel
9
-
10
- ## Vagrantfile
11
-
12
- ```ruby
13
- Vagrant.require_plugin "vagrant-phpstorm-tunnel"
14
-
15
- Vagrant.configure("2") do |config|
16
- #...
17
- end
8
+ Installation
9
+ ------------
10
+ ```sh
11
+ vagrant plugin install vagrant-phpstorm-tunnel
18
12
  ```
19
13
 
20
- ## PhpStorm
21
-
22
- `vagrant-phpstorm-tunnel` will create file `php` in location `./scripts/vagrant/php` relative to `Vagrantfile`. You should configure you `PHP` interpreter by navigate to folder `<path-to-project>/scripts/vagrant`.
14
+ PhpStorm
15
+ --------
16
+ `vagrant-phpstorm-tunnel` will create a file `.idea/vagrant/php` in your vagrant-project.
17
+ Select this file as a PHP interpreter in PhpStorm:
18
+ ![PhpStorm screenshot](docu/phpstorm-interpreter.png)
23
19
 
20
+ Limitations
21
+ -----------
22
+ The plugin assumes your project is shared as `/vagrant` in the VM.
23
+ It will copy PhpStorm's helper-scripts into `.idea/vagrant/tmp/` to make them accessible from within the VM.
data/data/php CHANGED
@@ -1,54 +1,49 @@
1
- #!/usr/bin/env php
1
+ #!/usr/bin/env php
2
2
  <?php
3
3
 
4
- $scriptDir = __DIR__;
5
-
6
- $projectDir = '';
7
- $projectTmpDir = '/tmp';
8
-
4
+ $projectDir = dirname(dirname(dirname($_SERVER['PHP_SELF'])));
5
+ $homeDir = $projectDir . '/.idea/vagrant';
6
+ $tmpDir = $homeDir . '/tmp';
9
7
  $vagrantDir = '/vagrant';
10
- $vagrantIp = '10.10.10.1';
8
+ $pipe = 'vagrant ssh -c ';
11
9
 
12
- $pathCrumbs = explode('/', $scriptDir);
13
- while(count($pathCrumbs)) {
14
- $_path = implode('/', $pathCrumbs);
15
- if(is_dir($_path . '/.idea')) {
16
- $projectDir = $_path;
17
- break;
18
- }
19
- array_pop($pathCrumbs);
20
- }
10
+ chdir($projectDir);
21
11
 
22
- if (empty($projectDir)) {
23
- echo "Cannot detect project dir!";
24
- exit;
12
+ // Detect Host IP
13
+ $hostIpFile = $homeDir . '/host_ip';
14
+ if (!file_exists($hostIpFile)) {
15
+ $ip = shell_exec('vagrant ssh -c "sudo ip route | awk \'/default/ { print \$3 }\'"');
16
+ file_put_contents($hostIpFile, $ip);
17
+ }
18
+ $hostIp = trim(file_get_contents($hostIpFile));
19
+ if (!filter_var($hostIp, FILTER_VALIDATE_IP)) {
20
+ throw new Exception('Cannot detect host IP, got value `' . $hostIp . '`.');
25
21
  }
26
22
 
27
- $args = $_SERVER['argv'];
28
- foreach ($args as $index => &$arg) {
29
23
 
24
+ $arguments = $argv;
25
+ array_shift($arguments);
26
+ foreach ($arguments as $index => &$argument) {
30
27
  // IP mapping
31
- $arg = str_replace(array('127.0.0.1', 'localhost'), $vagrantIp, $arg);
28
+ $argument = str_replace(array('127.0.0.1', 'localhost'), $hostIp, $argument);
32
29
 
33
30
  // Paths mapping
34
- $filePath = $arg;
31
+ $filePath = $argument;
35
32
  if (file_exists($filePath)) {
36
33
  if (strpos($filePath, $projectDir) !== false) {
37
34
  // Mapping project paths to remote paths
38
- $args[$index] = str_replace($projectDir, $vagrantDir, $filePath);
35
+ $arguments[$index] = str_replace($projectDir, $vagrantDir, $filePath);
39
36
  } else {
40
- if (strpos($filePath, $projectDir) === false) {
41
- // Mapping any other local system paths to remote paths, upload files
42
- $basename = basename($filePath);
43
- copy($filePath, $projectDir . $projectTmpDir . '/tunnel.' . $basename);
44
- $args[$index] = $vagrantDir . $projectTmpDir . '/tunnel.' . $basename;
45
- }
37
+ // Mapping any other local system paths to remote paths, upload files
38
+ $basename = basename($filePath);
39
+ copy($filePath, $projectDir . '/' . $tmpDir . '/tunnel.' . $basename);
40
+ $arguments[$index] = $vagrantDir . '/' . $tmpDir . '/tunnel.' . $basename;
46
41
  }
47
42
  }
48
43
 
49
- $arg = escapeshellarg($arg);
44
+ $argument = escapeshellarg($argument);
50
45
  }
51
- array_shift($args);
46
+
52
47
 
53
48
  // Get XDEBUG environment variable
54
49
  $env = '';
@@ -56,15 +51,5 @@ if (isset($_SERVER['XDEBUG_CONFIG'])) {
56
51
  $env = "XDEBUG_CONFIG='" . $_SERVER['XDEBUG_CONFIG'] . "'";
57
52
  }
58
53
 
59
- // Tunnel
60
- $pipe = 'vagrant ssh -c ';
61
-
62
- // Remote command
63
- $commandRemote = $env . ' php ' . implode(' ', $args);
64
-
65
- // Local command
66
- $commandLocal = 'cd ' . $projectDir . ' && ' . $pipe . '"' . $commandRemote . '"';
67
- passthru($commandLocal);
68
54
 
69
- exit;
70
- ?>
55
+ passthru($pipe . '"' . $env . ' php ' . implode(' ', $arguments) . '"');
@@ -1,13 +1,13 @@
1
1
  require 'vagrant-phpstorm-tunnel/configurator'
2
2
 
3
- module VagrantPhpStormTunnel
4
- class Plugin < Vagrant.plugin("2")
3
+ module VagrantPhpstormTunnel
4
+ class Plugin < Vagrant.plugin('2')
5
5
 
6
- name "vagrant-phpstorm-tunnel"
6
+ name 'vagrant-phpstorm-tunnel'
7
7
 
8
8
  %w{up provision}.each do |action|
9
- action_hook(:restart_host_tunnel, "machine_action_#{action}".to_sym) do |hook|
10
- hook.append VagrantPhpStormTunnel::Configurator
9
+ action_hook(:install_tunnel, "machine_action_#{action}".to_sym) do |hook|
10
+ hook.append VagrantPhpstormTunnel::Configurator
11
11
  end
12
12
  end
13
13
 
@@ -1,12 +1,13 @@
1
1
  require 'fileutils'
2
2
 
3
- module VagrantPhpStormTunnel
3
+ module VagrantPhpstormTunnel
4
4
  class Configurator
5
5
  def initialize(app, env)
6
6
  @app = app
7
7
  @env = env
8
8
 
9
9
  @root_path = @env[:root_path].to_s
10
+ @home_path = '.idea/vagrant'
10
11
  end
11
12
 
12
13
  def is_intellij
@@ -14,25 +15,22 @@ module VagrantPhpStormTunnel
14
15
  end
15
16
 
16
17
  def link_php_to_intellij
17
- destination_path = @root_path + '/.idea/vagrant/php'
18
+ destination_path = File.join(@root_path, @home_path, 'php')
18
19
  source_path = File.expand_path('../../../data/php', __FILE__)
19
20
 
20
- if !File.exist? destination_path
21
- FileUtils.mkdir_p(File.dirname(destination_path))
22
- File.link(source_path, destination_path)
23
- File.chmod(0755, destination_path)
24
- end
21
+ FileUtils.rm_rf(@home_path)
22
+ FileUtils.mkdir_p(@home_path)
23
+ File.link(source_path, destination_path)
24
+ File.chmod(0755, destination_path)
25
25
  end
26
26
 
27
27
  def call(env)
28
28
  @env = env
29
29
  @app.call(env)
30
30
 
31
- if !is_intellij
32
- raise "Cannot detect intellij environment at #{@root_path}"
31
+ if is_intellij
32
+ link_php_to_intellij
33
33
  end
34
-
35
- link_php_to_intellij
36
34
  end
37
35
  end
38
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-phpstorm-tunnel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cargo Media
@@ -16,18 +16,18 @@ dependencies:
16
16
  name: rake
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
- - - '>='
19
+ - - ">="
20
20
  - !ruby/object:Gem::Version
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
- - - '>='
26
+ - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: '0'
29
- description: Creates tunnel between PhpStorm and Vagrant machine to allow execute
30
- PHP via SSH
29
+ description: Installs a proxy php binary which can be configured as a php-interpreter
30
+ in PhpStorm
31
31
  email: hello@cargomedia.ch
32
32
  executables: []
33
33
  extensions: []
@@ -35,9 +35,9 @@ extra_rdoc_files: []
35
35
  files:
36
36
  - LICENSE
37
37
  - README.md
38
- - lib/vagrant-phpstorm-tunnel/configurator.rb
39
- - lib/vagrant-phpstorm-tunnel.rb
40
38
  - data/php
39
+ - lib/vagrant-phpstorm-tunnel.rb
40
+ - lib/vagrant-phpstorm-tunnel/configurator.rb
41
41
  homepage: https://github.com/cargomedia/vagrant-phpstorm-tunnel
42
42
  licenses:
43
43
  - MIT
@@ -48,18 +48,18 @@ require_paths:
48
48
  - lib
49
49
  required_ruby_version: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - '>='
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  required_rubygems_version: !ruby/object:Gem::Requirement
55
55
  requirements:
56
- - - '>='
56
+ - - ">="
57
57
  - !ruby/object:Gem::Version
58
58
  version: '0'
59
59
  requirements: []
60
60
  rubyforge_project:
61
- rubygems_version: 2.0.3
61
+ rubygems_version: 2.2.2
62
62
  signing_key:
63
63
  specification_version: 4
64
- summary: PhpStorm-Vagrant tunnel
64
+ summary: Proxy php-calls from PhpStorm to Vagrant
65
65
  test_files: []