Class: Rack::Legacy::Php::HtAccess

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/legacy/php.rb

Overview

For processing .htaccess files to tweak PHP environment. Represents a single .htaccess file that might affect PHP

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (HtAccess) initialize(file)

New instance to process the given file for PHP config



44
45
46
# File 'lib/rack/legacy/php.rb', line 44

def initialize(file)
  @file = file
end

Instance Attribute Details

- (Object) file (readonly)

The .htaccess file being processed



41
42
43
# File 'lib/rack/legacy/php.rb', line 41

def file
  @file
end

Class Method Details

+ (Object) find_all(path, root)

Will return all .htaccess files that affect a given path stopping when it reaches the root directory.



59
60
61
62
63
64
65
66
67
68
# File 'lib/rack/legacy/php.rb', line 59

def self.find_all(path, root)
  dir = ::File.dirname(path)
  ret = if dir.start_with?(root)
    find_all(dir, root)
  else
    []
  end 
  ret << new("#{dir}/.htaccess") if ::File.exist? "#{dir}/.htaccess"
  ret
end

+ (Object) merge_all(path, root)

Finds all .htaccess files that affect the given path stopping at the given root and merge them into one big hash.



72
73
74
# File 'lib/rack/legacy/php.rb', line 72

def self.merge_all(path, root)
  find_all(path, root).inject({}) {|ret, hsh| ret.merge hsh}
end

Instance Method Details

- (Object) to_hash

Returns a hash of the PHP config that needs to be set.



49
50
51
52
53
54
55
# File 'lib/rack/legacy/php.rb', line 49

def to_hash
  ret = {}
  ::File.readlines(@file).each do |line|
    ret[$1] = $2 if line.chomp =~ /^php_\S+ (\S+) (.*)$/
  end
  ret
end