From 817d964b8e7db705338198d363573bb975a7f993 Mon Sep 17 00:00:00 2001
From: fh <fh-github@fholzhauer.de>
Date: Mon, 21 Oct 2013 11:17:59 +0200
Subject: [PATCH 1/4] Adding support for composer cache -
 http://getcomposer.org/

---
 lib/vagrant-cachier/bucket.rb                 |  1 +
 lib/vagrant-cachier/bucket/composer.rb        | 36 +++++++++++++++++++
 .../cap/linux/composer_path.rb                | 14 ++++++++
 lib/vagrant-cachier/plugin.rb                 |  5 +++
 4 files changed, 56 insertions(+)
 create mode 100644 lib/vagrant-cachier/bucket/composer.rb
 create mode 100644 lib/vagrant-cachier/cap/linux/composer_path.rb

diff --git a/lib/vagrant-cachier/bucket.rb b/lib/vagrant-cachier/bucket.rb
index 0e425a8..8b3e04f 100644
--- a/lib/vagrant-cachier/bucket.rb
+++ b/lib/vagrant-cachier/bucket.rb
@@ -40,3 +40,4 @@ require_relative "bucket/pacman"
 require_relative "bucket/yum"
 require_relative "bucket/rvm"
 require_relative "bucket/apt_cacher"
+require_relative "bucket/composer"
diff --git a/lib/vagrant-cachier/bucket/composer.rb b/lib/vagrant-cachier/bucket/composer.rb
new file mode 100644
index 0000000..dff71b5
--- /dev/null
+++ b/lib/vagrant-cachier/bucket/composer.rb
@@ -0,0 +1,36 @@
+module VagrantPlugins
+  module Cachier
+    class Bucket
+      class Composer < Bucket
+        def self.capability
+          :composer_path
+        end
+
+        def install
+          machine = @env[:machine]
+          guest   = machine.guest
+
+          if guest.capability?(:composer_path)
+            if composer_path = guest.capability(:composer_path)
+              bucket_path = "/tmp/vagrant-cache/#{@name}/"
+              #remove trailing slash, or symlink will fail
+              composer_path = composer_path.chomp('/')               
+              @env[:cache_dirs] << composer_path
+
+              machine.communicate.tap do |comm|
+                comm.execute("mkdir -p #{bucket_path}")
+
+                unless comm.test("test -L #{composer_path}")
+                  comm.sudo("rm -rf #{composer_path}")
+                  comm.sudo("ln -s #{bucket_path} #{composer_path}")
+               end
+              end
+            end
+          else
+            @env[:ui].info I18n.t('vagrant_cachier.skipping_bucket', bucket: 'Composer')
+          end
+        end
+      end
+    end
+  end
+end
diff --git a/lib/vagrant-cachier/cap/linux/composer_path.rb b/lib/vagrant-cachier/cap/linux/composer_path.rb
new file mode 100644
index 0000000..3e9116c
--- /dev/null
+++ b/lib/vagrant-cachier/cap/linux/composer_path.rb
@@ -0,0 +1,14 @@
+module VagrantPlugins
+  module Cachier
+    module Cap
+      module Linux
+        module ComposerPath 
+          def self.composer_path(machine)
+            composer_path = '/home/vagrant/.composer/'
+            return composer_path 
+          end
+        end
+      end
+    end
+  end
+end
diff --git a/lib/vagrant-cachier/plugin.rb b/lib/vagrant-cachier/plugin.rb
index 29dc502..929e0f3 100644
--- a/lib/vagrant-cachier/plugin.rb
+++ b/lib/vagrant-cachier/plugin.rb
@@ -26,6 +26,11 @@ module VagrantPlugins
         Cap::Linux::RvmPath
       end
 
+      guest_capability 'linux', 'composer_path' do
+        require_relative 'cap/linux/composer_path'
+        Cap::Linux::ComposerPath
+      end
+
       guest_capability 'linux', 'chef_file_cache_path' do
         require_relative 'cap/linux/chef_file_cache_path'
         Cap::Linux::ChefFileCachePath

From 828793afdeb97d705aa2c7214902b0c6f23a1121 Mon Sep 17 00:00:00 2001
From: fh <fh-github@fholzhauer.de>
Date: Tue, 22 Oct 2013 16:42:29 +0200
Subject: [PATCH 2/4] removing trailing slashes and chomp()

---
 lib/vagrant-cachier/bucket/composer.rb         | 4 +---
 lib/vagrant-cachier/cap/linux/composer_path.rb | 2 +-
 2 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/lib/vagrant-cachier/bucket/composer.rb b/lib/vagrant-cachier/bucket/composer.rb
index dff71b5..cb939ad 100644
--- a/lib/vagrant-cachier/bucket/composer.rb
+++ b/lib/vagrant-cachier/bucket/composer.rb
@@ -12,9 +12,7 @@ module VagrantPlugins
 
           if guest.capability?(:composer_path)
             if composer_path = guest.capability(:composer_path)
-              bucket_path = "/tmp/vagrant-cache/#{@name}/"
-              #remove trailing slash, or symlink will fail
-              composer_path = composer_path.chomp('/')               
+              bucket_path = "/tmp/vagrant-cache/#{@name}"
               @env[:cache_dirs] << composer_path
 
               machine.communicate.tap do |comm|
diff --git a/lib/vagrant-cachier/cap/linux/composer_path.rb b/lib/vagrant-cachier/cap/linux/composer_path.rb
index 3e9116c..605fde7 100644
--- a/lib/vagrant-cachier/cap/linux/composer_path.rb
+++ b/lib/vagrant-cachier/cap/linux/composer_path.rb
@@ -4,7 +4,7 @@ module VagrantPlugins
       module Linux
         module ComposerPath 
           def self.composer_path(machine)
-            composer_path = '/home/vagrant/.composer/'
+            composer_path = '/home/vagrant/.composer'
             return composer_path 
           end
         end

From a0a164cf2b6b58202920de62d20db5540746170f Mon Sep 17 00:00:00 2001
From: Fabio Rehm <fgrehm@gmail.com>
Date: Tue, 22 Oct 2013 13:51:02 -0200
Subject: [PATCH 3/4] Install php-cli on dev box

---
 development/Vagrantfile | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/development/Vagrantfile b/development/Vagrantfile
index 5fcb1c1..b4d44b5 100644
--- a/development/Vagrantfile
+++ b/development/Vagrantfile
@@ -48,7 +48,7 @@ Vagrant.configure("2") do |config|
     # Here we have the RubyGems cache bucket configured to the right path, so we
     # bundle the project
     debian.vm.provision :shell, inline: '
-      sudo apt-get install git -y
+      sudo apt-get install -y git php5-cli
       HOME=/home/vagrant su -p vagrant -l -c "cd /vagrant && bundle"
     '
   end
@@ -86,5 +86,4 @@ Vagrant.configure("2") do |config|
         pacman -Syu --noconfirm libffi git
         HOME=/home/vagrant su -p vagrant -l -c "cd /vagrant && bundle"'
   end
-
 end

From f8e419b8b606265ae90eb8d64170af18d8d32ea4 Mon Sep 17 00:00:00 2001
From: Fabio Rehm <fgrehm@gmail.com>
Date: Tue, 22 Oct 2013 13:51:45 -0200
Subject: [PATCH 4/4] "Disable" composer bucket if php is not installed

---
 lib/vagrant-cachier/cap/linux/composer_path.rb | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/vagrant-cachier/cap/linux/composer_path.rb b/lib/vagrant-cachier/cap/linux/composer_path.rb
index 605fde7..db89b7a 100644
--- a/lib/vagrant-cachier/cap/linux/composer_path.rb
+++ b/lib/vagrant-cachier/cap/linux/composer_path.rb
@@ -2,10 +2,16 @@ module VagrantPlugins
   module Cachier
     module Cap
       module Linux
-        module ComposerPath 
+        module ComposerPath
           def self.composer_path(machine)
-            composer_path = '/home/vagrant/.composer'
-            return composer_path 
+            composer_path = nil
+            machine.communicate.tap do |comm|
+              return unless comm.test('which php')
+              comm.execute 'echo $HOME' do |buffer, output|
+                composer_path = output.chomp if buffer == :stdout
+              end
+            end
+            return "#{composer_path}/.composer"
           end
         end
       end