phpow 0.0.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d2eed5b96c884f3eff408f84ec68a64fd21b5747
4
+ data.tar.gz: d94a5d3d20c08815add5fe9f04ece86a67b0ef0e
5
+ SHA512:
6
+ metadata.gz: 3e8661ea2fc257257e34bfbafaf99e8f15f7fe4181993bdc95ce071aa80c57222ed4ecf8d0f42edcbe5cd300afc4b1a328951404a98dcefb08cd3633658381a0
7
+ data.tar.gz: 51af992bc6ca45bf964a3b909b8a27d837a802b577b9eafb2ded27f552408a93500e9b46b32d5022705377d24ea610730a2bef08930ef200d3cfc2b667cffda3
data/README.md CHANGED
@@ -1,51 +1,30 @@
1
1
  Phpow
2
2
  =====
3
3
 
4
- Develop your legacy PHP applications utilizing POW's TLDs on Mac OS X
4
+ Develop your legacy PHP applications utilizing POW's TLDs on Mac OS X.
5
5
 
6
6
  Installation
7
7
  ------------
8
8
 
9
- Add this line to your application's Gemfile:
10
-
11
- gem 'phpow'
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install phpow
9
+ ```bash
10
+ gem install phpow
11
+ ```
20
12
 
21
13
  Usage
22
14
  -----
23
15
 
24
- `phpow install`
25
-
26
- Creates the apache configuration file that will listen on port 8888
27
-
28
- `phpow uninstall`
16
+ `phpow -h` for all commands and options.
29
17
 
30
- Removes the apache configuration file that will listen on port 8888
31
-
32
- `phpow create`
33
-
34
- Creates symbolic links to phpow's `config.ru` and `.powconfig` files in the current working directory.
18
+ ### Configuration
35
19
 
36
- `phpow destroy`
20
+ By default phpow will set up apache to listen on port 8888, and serve projects from the folder `~/Sites`.
37
21
 
38
- Removes the symbolic links to phpow's `config.ru` and `.powconfig` files in the current working directory.
22
+ Use the `--port PORT` and `--folder FOLDER` options to use a different port/location.
39
23
 
40
- ### Configuration
24
+ POW
25
+ ---
41
26
 
42
- By default phpow will set up apache to listen on port 8888, and serve projects from `/Users/username/Sites`. Either one of these defaults can be overridden by creating a `.phpowconfig` file in your home directory.
43
-
44
- ```
45
- # ~/.phpowconfig Example
46
- export PHPOW_APACHE_PORT=8080
47
- export PHPOW_PROJECTS_DIRECTORY=/Users/username/another/specific/directory
48
- ```
27
+ Set up a POW to portmap to your apache port. If you have the [powder](https://github.com/Rodreegez/powder) gem `powder portmap 8888` will do the trick.
49
28
 
50
29
  Contributing
51
30
  ------------
data/bin/phpow CHANGED
@@ -1,11 +1,39 @@
1
1
  #!/usr/bin/env ruby
2
-
3
- lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
4
- $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
2
+ $:.unshift File.join(File.dirname(__FILE__), '../lib')
5
3
 
6
4
  require 'phpow'
5
+ require 'optparse'
6
+
7
+ args = {}
8
+
9
+ opt_parser = OptionParser.new do |opt|
10
+ opt.banner = "Usage: phpow COMMAND [OPTIONS]"
11
+ opt.separator ""
12
+ opt.separator "Commands"
13
+ opt.separator " preview: preview apache.conf"
14
+ opt.separator " install: install apache.conf"
15
+ opt.separator " uninstall: delete apache.conf"
16
+ opt.separator ""
17
+ opt.separator "Options"
18
+
19
+ opt.on("-p", "--port PORT", "the port apache will listen on") do |port|
20
+ args[:port] = port
21
+ end
22
+
23
+ opt.on("-f", "--folder FOLDER", "the folder that will serve as apache's document root") do |document_root|
24
+ args[:document_root] = document_root
25
+ end
26
+
27
+ opt.on("-h","--help","help") do
28
+ end
29
+ end
30
+
31
+ opt_parser.parse!
7
32
 
8
- args = ARGV.dup
9
- ARGV.clear
33
+ command_name = ARGV.shift
34
+ if %w[preview install uninstall].include?(command_name)
35
+ Phpow::ApacheConfiguration.new(args).send(command_name)
36
+ else
37
+ puts opt_parser
38
+ end
10
39
 
11
- Phpow::Client.run(args)
data/lib/phpow.rb CHANGED
@@ -1 +1 @@
1
- require 'phpow/core'
1
+ require 'phpow/apache_configuration'
@@ -0,0 +1,71 @@
1
+ require 'erb'
2
+
3
+ module Phpow
4
+ class ApacheConfiguration
5
+ attr_accessor :port, :document_root
6
+
7
+ def initialize(args = {})
8
+ @port = args.fetch(:port, 8888)
9
+ @document_root = args.fetch(:document_root, default_document_root)
10
+ end
11
+
12
+ def preview
13
+ puts template_result
14
+ end
15
+
16
+ def install
17
+ puts "You are about to write the file '#{pathname}'?"
18
+ print "Enter 'yes' to confirm: "
19
+ return unless gets.strip == "yes"
20
+
21
+ write_file
22
+ end
23
+
24
+ def uninstall
25
+ puts "You are about to permanently delete the file '#{pathname}'?"
26
+ print "Enter 'yes' to confirm: "
27
+ return unless gets.strip == "yes"
28
+
29
+ File.delete(pathname)
30
+ end
31
+
32
+ private
33
+
34
+ def pathname
35
+ "/etc/apache2/users/#{user}.conf"
36
+ end
37
+
38
+ def user
39
+ %x{whoami}.strip
40
+ end
41
+
42
+ def default_document_root
43
+ "/Users/#{user}/Sites"
44
+ end
45
+
46
+ def ensure_file_has_ideal_permissions
47
+ File.chmod(0644, pathname)
48
+ end
49
+
50
+ def ensure_file_is_writable
51
+ unless File.owned?(pathname)
52
+ puts "'#{File.dirname(pathname)}' is write protected by root. You will have to enter your administrator password in order to create #{pathname}"
53
+ %x{sudo touch #{pathname} && sudo chown #{user} #{pathname}}
54
+ end
55
+ end
56
+
57
+ def write_file
58
+ ensure_file_is_writable
59
+ ensure_file_has_ideal_permissions
60
+ File.write(pathname, template_result)
61
+ end
62
+
63
+ def template_result
64
+ template_source.result(instance_eval { binding })
65
+ end
66
+
67
+ def template_source
68
+ ERB.new(File.read(File.join(File.dirname(__FILE__), "templates", "apache.conf.erb")))
69
+ end
70
+ end
71
+ end
@@ -1,4 +1,4 @@
1
- # Apache configuration
1
+ # Apache configuration generated by phpow
2
2
  # Should be written to /etc/apache2/users/username.conf on Mac OS X
3
3
 
4
4
  # Enable PHP
@@ -11,12 +11,12 @@ LoadModule php5_module libexec/apache2/libphp5.so
11
11
  </IfModule>
12
12
  </IfModule>
13
13
 
14
- # Pow is using port 80. Will forward to apache on <%= apache_port %> using Phpow::RackApp
15
- Listen <%= apache_port %>
14
+ # Pow is using port 80. Will forward to apache on <%= port %>
15
+ Listen <%= port %>
16
16
 
17
17
  # Virtual hosts, piggy-backing on POW's .dev
18
- DocumentRoot <%= projects_directory %>
19
- <Directory "<%= projects_directory %>/">
18
+ DocumentRoot <%= document_root %>
19
+ <Directory "<%= document_root %>/">
20
20
  Options Indexes MultiViews FollowSymLinks
21
21
  AllowOverride All
22
22
  Order allow,deny
@@ -25,5 +25,5 @@ DocumentRoot <%= projects_directory %>
25
25
 
26
26
  NameVirtualHost 127.0.0.1
27
27
  <VirtualHost 127.0.0.1>
28
- VirtualDocumentRoot <%= projects_directory %>/%-2+
28
+ VirtualDocumentRoot <%= document_root %>/%-2+
29
29
  </VirtualHost>
data/lib/phpow/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Phpow
2
- VERSION = "0.0.3"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phpow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
5
- prerelease:
4
+ version: 0.3.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Daniel Ott
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-05-18 00:00:00.000000000 Z
11
+ date: 2013-11-27 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Develop your legacy PHP applications utilizing POW's TLDs on Mac OS X
15
14
  email:
@@ -26,37 +25,32 @@ files:
26
25
  - Rakefile
27
26
  - bin/phpow
28
27
  - lib/phpow.rb
29
- - lib/phpow/client.rb
30
- - lib/phpow/core.rb
31
- - lib/phpow/rack_app.rb
32
- - lib/phpow/templates/.powconfig
28
+ - lib/phpow/apache_configuration.rb
33
29
  - lib/phpow/templates/apache.conf.erb
34
- - lib/phpow/templates/config.ru
35
30
  - lib/phpow/version.rb
36
31
  - phpow.gemspec
37
32
  homepage: http://github.com/danott/phpow
38
33
  licenses: []
34
+ metadata: {}
39
35
  post_install_message:
40
36
  rdoc_options: []
41
37
  require_paths:
42
38
  - lib
43
39
  required_ruby_version: !ruby/object:Gem::Requirement
44
- none: false
45
40
  requirements:
46
- - - ! '>='
41
+ - - '>='
47
42
  - !ruby/object:Gem::Version
48
43
  version: '0'
49
44
  required_rubygems_version: !ruby/object:Gem::Requirement
50
- none: false
51
45
  requirements:
52
- - - ! '>='
46
+ - - '>='
53
47
  - !ruby/object:Gem::Version
54
48
  version: '0'
55
49
  requirements: []
56
50
  rubyforge_project:
57
- rubygems_version: 1.8.17
51
+ rubygems_version: 2.0.3
58
52
  signing_key:
59
- specification_version: 3
53
+ specification_version: 4
60
54
  summary: Having a single TLD for both Rails and PHP development keeps things simple.
61
55
  But both POW and Apache can't listen on port 80. Get around this by running a light
62
56
  weight Rack application in POW as an in-between for Apache/PHP running on a different
data/lib/phpow/client.rb DELETED
@@ -1,108 +0,0 @@
1
- module Phpow
2
-
3
- class Client
4
-
5
- require 'fileutils'
6
- extend Phpow
7
-
8
- ##
9
- # A convenvetion borrowed from powify. Define the allowable command line methods.
10
- #
11
- AVAILABLE_METHODS = %w[create destroy install uninstall help]
12
-
13
- class << self
14
-
15
- ##
16
- # Phpow::Client.run
17
- #
18
- # A wrapper for the command line interface.
19
- #
20
- def run(args = [])
21
-
22
- load_config
23
-
24
- method = args[0].to_s.downcase
25
- begin
26
- raise "The command `#{args[0]}` does not exist for `phpow`!" unless Phpow::Client::AVAILABLE_METHODS.include?(method)
27
- return send(method)
28
- rescue Exception => e
29
- puts e
30
- end
31
- help
32
- end
33
-
34
-
35
- ##
36
- # phpow create
37
- # Create the symbolic links to effectively run Phpow:RackApp.
38
- #
39
- def create
40
- symlink_files.each do |file|
41
- FileUtils.ln_s(File.join(File.dirname(__FILE__), "templates", file), File.join(current_path, file))
42
- end
43
- end
44
-
45
-
46
- ##
47
- # phpow destroy
48
- # Unlink the files that were linked using phpow create.
49
- #
50
- def destroy
51
- symlink_files.each do |file|
52
- symlink_path = File.join(current_path, file)
53
- FileUtils.rm(symlink_path) if File.symlink?(symlink_path)
54
- end
55
- end
56
-
57
-
58
- ##
59
- # phpow install
60
- # Install the apache configuration file in `apache_conf_path`
61
- #
62
- def install
63
- require 'erb'
64
- template = ERB.new(File.read(File.join(File.dirname(__FILE__), "templates", "apache.conf.erb")))
65
- result = template.result(binding)
66
-
67
- # Need the current user to own the file in able to write to it.
68
- unless File.owned?(apache_conf_path)
69
- puts "'#{File.dirname(apache_conf_path)}' is write protected by root. You will have to enter your administrator password in order to create #{apache_conf_path}"
70
- %x{sudo touch #{apache_conf_path} && sudo chown #{user} #{apache_conf_path}}
71
- end
72
-
73
- f = File.new(apache_conf_path, 'w')
74
- f.puts(result)
75
- f.chmod(0644)
76
- f.close
77
- end
78
-
79
-
80
- ##
81
- # phpow uninstall
82
- # Remove the apache configuration file from `apache_conf_path`
83
- #
84
- def uninstall
85
- puts "Are you sure you want to remove the file '#{apache_conf_path}'?"
86
- print "Enter 'yes' to confirm: "
87
-
88
- confirmation = gets.strip.downcase
89
- return unless confirmation == "yes"
90
-
91
- %x{sudo rm #{apache_conf_path}}
92
- end
93
-
94
-
95
- ##
96
- # Print helpful information to the command line.
97
- #
98
- def help
99
- print <<-HELPTEXT
100
- See README at http://github.com/danott/phpow
101
- HELPTEXT
102
- end
103
-
104
- end
105
-
106
- end
107
-
108
- end
data/lib/phpow/core.rb DELETED
@@ -1,50 +0,0 @@
1
- require 'phpow/client'
2
- require 'phpow/rack_app'
3
-
4
- module Phpow
5
-
6
- attr_accessor :apache_port, :projects_directory
7
-
8
- def apache_port
9
- @apache_port || 8888
10
- end
11
-
12
- def projects_directory
13
- @projects_directory || "/Users/#{user}/Sites"
14
- end
15
-
16
- def projects_directory=(directory)
17
- @projects_directory = directory.gsub(/\/*$/, '')
18
- end
19
-
20
- def current_path
21
- %x{pwd}.strip
22
- end
23
-
24
- def user
25
- %x{whoami}.strip
26
- end
27
-
28
- def apache_conf_path
29
- "/etc/apache2/users/#{user}.conf"
30
- end
31
-
32
- def symlink_files
33
- %w[config.ru .powconfig]
34
- end
35
-
36
-
37
- ##
38
- # Configuration variables can be stored in '~/.phpowconfig'
39
- #
40
- # PHPOW_APACHE_PORT: Configure apache to run on a port other than 8888
41
- # PHPOW_PROJECTS_DIRECTORY: Serve your projects out of a directory other than /Users/user/Sites
42
- #
43
- def load_config
44
- if File.exists?(File.expand_path('~/.phpowconfig'))
45
- self.apache_port = %x{source ~/.phpowconfig; echo $PHPOW_APACHE_PORT}.strip unless %x{source ~/.phpowconfig; echo $PHPOW_APACHE_PORT}.strip.empty?
46
- self.projects_directory = %x{source ~/.phpowconfig; echo $PHPOW_PROJECTS_DIRECTORY}.strip unless %x{source ~/.phpowconfig; echo $PHPOW_PROJECTS_DIRECTORY}.strip.empty?
47
- end
48
- end
49
-
50
- end
@@ -1,39 +0,0 @@
1
- module Phpow
2
-
3
- class RackApp
4
-
5
- require 'net/http'
6
- include Phpow
7
-
8
- def initialize
9
- load_config
10
- end
11
-
12
- def call(env)
13
- request = Rack::Request.new(env)
14
- headers = {}
15
-
16
- # Make the POW request to the Apache server
17
- # http://myapp.dev/full/path/goes/here/
18
- # ...will map to...
19
- # http://myapp.dev:8888/full/path/goes/here/
20
- http = Net::HTTP.new(request.host, apache_port)
21
- response = http.send_request(request.request_method, request.fullpath, request.body.read, headers)
22
-
23
- # Map Net::HTTP response back to Rack::Request.call expects
24
- status, headers, body = response.code, response.to_hash, [response.body]
25
-
26
- # Research showed that browsers were choking on this for some reason.
27
- # Probably not the be-all-end-all solution, but works for local development thus far.
28
- headers.delete('transfer-encoding')
29
-
30
- # Send the response back to POW
31
- [status, headers, body]
32
-
33
- rescue Errno::ECONNREFUSED
34
- [500, {}, ["Server is down, try $ sudo apachectl start"]]
35
- end
36
-
37
- end
38
-
39
- end
@@ -1 +0,0 @@
1
- export POW_WORKERS=10
@@ -1,2 +0,0 @@
1
- require 'phpow'
2
- run Phpow::RackApp.new