php-composer 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +10 -10
- data/Gemfile +15 -15
- data/LICENSE.txt +21 -21
- data/README.md +35 -35
- data/Rakefile +1 -1
- data/lib/composer.rb +52 -52
- data/lib/composer/error.rb +8 -8
- data/lib/composer/json/json_file.rb +270 -270
- data/lib/composer/package/alias_package.rb +273 -273
- data/lib/composer/package/base_package.rb +130 -130
- data/lib/composer/package/complete_package.rb +55 -55
- data/lib/composer/package/dumper/hash_dumper.rb +169 -169
- data/lib/composer/package/link.rb +51 -51
- data/lib/composer/package/link_constraint/base_constraint.rb +35 -35
- data/lib/composer/package/link_constraint/empty_constraint.rb +34 -34
- data/lib/composer/package/link_constraint/multi_constraint.rb +66 -66
- data/lib/composer/package/link_constraint/specific_constraint.rb +40 -40
- data/lib/composer/package/link_constraint/version_constraint.rb +220 -220
- data/lib/composer/package/loader/hash_loader.rb +316 -316
- data/lib/composer/package/loader/json_loader.rb +47 -47
- data/lib/composer/package/loader/project_attributes_loader.rb +71 -71
- data/lib/composer/package/loader/project_root_package_loader.rb +28 -28
- data/lib/composer/package/package.rb +118 -118
- data/lib/composer/package/root_alias_package.rb +37 -37
- data/lib/composer/package/root_package.rb +37 -37
- data/lib/composer/package/version/version_parser.rb +583 -583
- data/lib/composer/package/version/version_selector.rb +106 -106
- data/lib/composer/repository/filesystem_repository.rb +84 -85
- data/lib/composer/repository/{array_repository.rb → hash_repository.rb} +195 -195
- data/lib/composer/repository/{writeable_array_repository.rb → writeable_hash_repository.rb} +57 -59
- data/lib/composer/version.rb +3 -3
- data/php-composer.gemspec +31 -31
- metadata +4 -4
@@ -1,130 +1,130 @@
|
|
1
|
-
#
|
2
|
-
# This file was ported to ruby from Composer php source code.
|
3
|
-
# Original Source: Composer\Package\BasePackage.php
|
4
|
-
#
|
5
|
-
# (c) Nils Adermann <naderman@naderman.de>
|
6
|
-
# Jordi Boggiano <j.boggiano@seld.be>
|
7
|
-
#
|
8
|
-
# For the full copyright and license information, please view the LICENSE
|
9
|
-
# file that was distributed with this source code.
|
10
|
-
#
|
11
|
-
|
12
|
-
module Composer
|
13
|
-
module Package
|
14
|
-
|
15
|
-
# Base class for packages providing name storage
|
16
|
-
# and default match implementation
|
17
|
-
# @php_author Nils Adermann <naderman@naderman.de>
|
18
|
-
# @author Ioannis Kappas <ikappas@devworks.gr>
|
19
|
-
class BasePackage
|
20
|
-
|
21
|
-
# base package attributes
|
22
|
-
attr_accessor :id, :repository, :transport_options
|
23
|
-
attr_reader :name, :pretty_name, :version, :pretty_version, :stability
|
24
|
-
|
25
|
-
STABILITY_STABLE = 0
|
26
|
-
STABILITY_RC = 5
|
27
|
-
STABILITY_BETA = 10
|
28
|
-
STABILITY_ALPHA = 15
|
29
|
-
STABILITY_DEV = 20
|
30
|
-
|
31
|
-
SUPPORTED_LINK_TYPES = {
|
32
|
-
'require' => {
|
33
|
-
'description' => 'requires',
|
34
|
-
'method' => 'requires'
|
35
|
-
},
|
36
|
-
'conflict' => {
|
37
|
-
'description' => 'conflicts',
|
38
|
-
'method' => 'conflicts'
|
39
|
-
},
|
40
|
-
'provide' => {
|
41
|
-
'description' => 'provides',
|
42
|
-
'method' => 'provides'
|
43
|
-
},
|
44
|
-
'replace' => {
|
45
|
-
'description' => 'replaces',
|
46
|
-
'method' => 'replaces'
|
47
|
-
},
|
48
|
-
'require-dev' => {
|
49
|
-
'description' => 'requires (for development)',
|
50
|
-
'method' => 'dev_requires'
|
51
|
-
}
|
52
|
-
}.freeze()
|
53
|
-
|
54
|
-
class << self
|
55
|
-
|
56
|
-
def stabilities
|
57
|
-
@stabilities ||= {
|
58
|
-
'stable' => STABILITY_STABLE,
|
59
|
-
'RC' => STABILITY_RC,
|
60
|
-
'beta' => STABILITY_BETA,
|
61
|
-
'alpha' => STABILITY_ALPHA,
|
62
|
-
'dev' => STABILITY_DEV,
|
63
|
-
}.freeze()
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
# Creates a new in memory package.
|
69
|
-
# Param: string name The package's name
|
70
|
-
# Param: string version The package's version
|
71
|
-
# Param: string pretty_version The package's non-normalized version
|
72
|
-
def initialize(name)
|
73
|
-
@pretty_name = name
|
74
|
-
@name = name.downcase
|
75
|
-
@id = -1
|
76
|
-
@transport_options = []
|
77
|
-
end
|
78
|
-
|
79
|
-
def attributes
|
80
|
-
dumper = Composer::Package::Dumper::HashDumper.new
|
81
|
-
dumper.dump(self)
|
82
|
-
end
|
83
|
-
|
84
|
-
# Set package type
|
85
|
-
# Param: string type
|
86
|
-
def type=(type)
|
87
|
-
@type = type
|
88
|
-
end
|
89
|
-
|
90
|
-
# Get package type
|
91
|
-
# Return: string
|
92
|
-
def type
|
93
|
-
@type ? @type : 'library'
|
94
|
-
end
|
95
|
-
|
96
|
-
# Set package repository
|
97
|
-
def repository=(repository)
|
98
|
-
if (@repository && repository != @repository)
|
99
|
-
raise LogicError, 'A package can only be added to one repository'
|
100
|
-
end
|
101
|
-
@repository = repository
|
102
|
-
end
|
103
|
-
|
104
|
-
# Get package repository
|
105
|
-
def repository
|
106
|
-
@repository
|
107
|
-
end
|
108
|
-
|
109
|
-
# def is_platform?
|
110
|
-
# @repository && @repository.instance_of?(PlatformRepository)
|
111
|
-
# end
|
112
|
-
|
113
|
-
# Returns package unique name, constructed from name, version and
|
114
|
-
# release type.
|
115
|
-
# Return: string
|
116
|
-
def unique_name
|
117
|
-
"#{name}-#{version}"
|
118
|
-
end
|
119
|
-
|
120
|
-
def pretty_string
|
121
|
-
"#{pretty_name} #{pretty_version}"
|
122
|
-
end
|
123
|
-
|
124
|
-
def to_s
|
125
|
-
unique_name
|
126
|
-
end
|
127
|
-
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
1
|
+
#
|
2
|
+
# This file was ported to ruby from Composer php source code.
|
3
|
+
# Original Source: Composer\Package\BasePackage.php
|
4
|
+
#
|
5
|
+
# (c) Nils Adermann <naderman@naderman.de>
|
6
|
+
# Jordi Boggiano <j.boggiano@seld.be>
|
7
|
+
#
|
8
|
+
# For the full copyright and license information, please view the LICENSE
|
9
|
+
# file that was distributed with this source code.
|
10
|
+
#
|
11
|
+
|
12
|
+
module Composer
|
13
|
+
module Package
|
14
|
+
|
15
|
+
# Base class for packages providing name storage
|
16
|
+
# and default match implementation
|
17
|
+
# @php_author Nils Adermann <naderman@naderman.de>
|
18
|
+
# @author Ioannis Kappas <ikappas@devworks.gr>
|
19
|
+
class BasePackage
|
20
|
+
|
21
|
+
# base package attributes
|
22
|
+
attr_accessor :id, :repository, :transport_options
|
23
|
+
attr_reader :name, :pretty_name, :version, :pretty_version, :stability
|
24
|
+
|
25
|
+
STABILITY_STABLE = 0
|
26
|
+
STABILITY_RC = 5
|
27
|
+
STABILITY_BETA = 10
|
28
|
+
STABILITY_ALPHA = 15
|
29
|
+
STABILITY_DEV = 20
|
30
|
+
|
31
|
+
SUPPORTED_LINK_TYPES = {
|
32
|
+
'require' => {
|
33
|
+
'description' => 'requires',
|
34
|
+
'method' => 'requires'
|
35
|
+
},
|
36
|
+
'conflict' => {
|
37
|
+
'description' => 'conflicts',
|
38
|
+
'method' => 'conflicts'
|
39
|
+
},
|
40
|
+
'provide' => {
|
41
|
+
'description' => 'provides',
|
42
|
+
'method' => 'provides'
|
43
|
+
},
|
44
|
+
'replace' => {
|
45
|
+
'description' => 'replaces',
|
46
|
+
'method' => 'replaces'
|
47
|
+
},
|
48
|
+
'require-dev' => {
|
49
|
+
'description' => 'requires (for development)',
|
50
|
+
'method' => 'dev_requires'
|
51
|
+
}
|
52
|
+
}.freeze()
|
53
|
+
|
54
|
+
class << self
|
55
|
+
|
56
|
+
def stabilities
|
57
|
+
@stabilities ||= {
|
58
|
+
'stable' => STABILITY_STABLE,
|
59
|
+
'RC' => STABILITY_RC,
|
60
|
+
'beta' => STABILITY_BETA,
|
61
|
+
'alpha' => STABILITY_ALPHA,
|
62
|
+
'dev' => STABILITY_DEV,
|
63
|
+
}.freeze()
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
# Creates a new in memory package.
|
69
|
+
# Param: string name The package's name
|
70
|
+
# Param: string version The package's version
|
71
|
+
# Param: string pretty_version The package's non-normalized version
|
72
|
+
def initialize(name)
|
73
|
+
@pretty_name = name
|
74
|
+
@name = name.downcase
|
75
|
+
@id = -1
|
76
|
+
@transport_options = []
|
77
|
+
end
|
78
|
+
|
79
|
+
def attributes
|
80
|
+
dumper = Composer::Package::Dumper::HashDumper.new
|
81
|
+
dumper.dump(self)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Set package type
|
85
|
+
# Param: string type
|
86
|
+
def type=(type)
|
87
|
+
@type = type
|
88
|
+
end
|
89
|
+
|
90
|
+
# Get package type
|
91
|
+
# Return: string
|
92
|
+
def type
|
93
|
+
@type ? @type : 'library'
|
94
|
+
end
|
95
|
+
|
96
|
+
# Set package repository
|
97
|
+
def repository=(repository)
|
98
|
+
if (@repository && repository != @repository)
|
99
|
+
raise LogicError, 'A package can only be added to one repository'
|
100
|
+
end
|
101
|
+
@repository = repository
|
102
|
+
end
|
103
|
+
|
104
|
+
# Get package repository
|
105
|
+
def repository
|
106
|
+
@repository
|
107
|
+
end
|
108
|
+
|
109
|
+
# def is_platform?
|
110
|
+
# @repository && @repository.instance_of?(PlatformRepository)
|
111
|
+
# end
|
112
|
+
|
113
|
+
# Returns package unique name, constructed from name, version and
|
114
|
+
# release type.
|
115
|
+
# Return: string
|
116
|
+
def unique_name
|
117
|
+
"#{name}-#{version}"
|
118
|
+
end
|
119
|
+
|
120
|
+
def pretty_string
|
121
|
+
"#{pretty_name} #{pretty_version}"
|
122
|
+
end
|
123
|
+
|
124
|
+
def to_s
|
125
|
+
unique_name
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
@@ -1,55 +1,55 @@
|
|
1
|
-
#
|
2
|
-
# This file was ported to ruby from Composer php source code file.
|
3
|
-
# Original Source: Composer\Package\CompletePackage.php
|
4
|
-
#
|
5
|
-
# (c) Nils Adermann <naderman@naderman.de>
|
6
|
-
# Jordi Boggiano <j.boggiano@seld.be>
|
7
|
-
#
|
8
|
-
# For the full copyright and license information, please view the LICENSE
|
9
|
-
# file that was distributed with this source code.
|
10
|
-
#
|
11
|
-
|
12
|
-
module Composer
|
13
|
-
module Package
|
14
|
-
|
15
|
-
# Package containing additional metadata that is not used by the solver
|
16
|
-
class CompletePackage < Composer::Package::Package
|
17
|
-
|
18
|
-
attr_accessor :scripts, :repositories, :license, :keywords, :authors,
|
19
|
-
:description, :homepage, :support
|
20
|
-
|
21
|
-
# Creates a new in memory package.
|
22
|
-
# Param: string name The package's name
|
23
|
-
# Param: string version The package's version
|
24
|
-
# Param: string prettyVersion The package's non-normalized version
|
25
|
-
def initialize(name, version, pretty_version)
|
26
|
-
super(name, version, pretty_version)
|
27
|
-
|
28
|
-
@license = []
|
29
|
-
@scripts = []
|
30
|
-
@support = []
|
31
|
-
@abandoned = false
|
32
|
-
end
|
33
|
-
|
34
|
-
# Determine if package is abandoned
|
35
|
-
# Return: true if package is abandoned; Otherwise false.
|
36
|
-
def is_abandoned?
|
37
|
-
@abandoned
|
38
|
-
end
|
39
|
-
|
40
|
-
# Set abandoned
|
41
|
-
# Param boolean|string $abandoned
|
42
|
-
def abandoned=(abandoned)
|
43
|
-
@abandoned = abandoned
|
44
|
-
end
|
45
|
-
|
46
|
-
# If the package is abandoned and has a suggested replacement,
|
47
|
-
# this method returns it
|
48
|
-
# @return string|nil
|
49
|
-
def replacement_package
|
50
|
-
return @abandoned.kind_of?(String) ? @abandoned : nil
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
1
|
+
#
|
2
|
+
# This file was ported to ruby from Composer php source code file.
|
3
|
+
# Original Source: Composer\Package\CompletePackage.php
|
4
|
+
#
|
5
|
+
# (c) Nils Adermann <naderman@naderman.de>
|
6
|
+
# Jordi Boggiano <j.boggiano@seld.be>
|
7
|
+
#
|
8
|
+
# For the full copyright and license information, please view the LICENSE
|
9
|
+
# file that was distributed with this source code.
|
10
|
+
#
|
11
|
+
|
12
|
+
module Composer
|
13
|
+
module Package
|
14
|
+
|
15
|
+
# Package containing additional metadata that is not used by the solver
|
16
|
+
class CompletePackage < Composer::Package::Package
|
17
|
+
|
18
|
+
attr_accessor :scripts, :repositories, :license, :keywords, :authors,
|
19
|
+
:description, :homepage, :support
|
20
|
+
|
21
|
+
# Creates a new in memory package.
|
22
|
+
# Param: string name The package's name
|
23
|
+
# Param: string version The package's version
|
24
|
+
# Param: string prettyVersion The package's non-normalized version
|
25
|
+
def initialize(name, version, pretty_version)
|
26
|
+
super(name, version, pretty_version)
|
27
|
+
|
28
|
+
@license = []
|
29
|
+
@scripts = []
|
30
|
+
@support = []
|
31
|
+
@abandoned = false
|
32
|
+
end
|
33
|
+
|
34
|
+
# Determine if package is abandoned
|
35
|
+
# Return: true if package is abandoned; Otherwise false.
|
36
|
+
def is_abandoned?
|
37
|
+
@abandoned
|
38
|
+
end
|
39
|
+
|
40
|
+
# Set abandoned
|
41
|
+
# Param boolean|string $abandoned
|
42
|
+
def abandoned=(abandoned)
|
43
|
+
@abandoned = abandoned
|
44
|
+
end
|
45
|
+
|
46
|
+
# If the package is abandoned and has a suggested replacement,
|
47
|
+
# this method returns it
|
48
|
+
# @return string|nil
|
49
|
+
def replacement_package
|
50
|
+
return @abandoned.kind_of?(String) ? @abandoned : nil
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -1,169 +1,169 @@
|
|
1
|
-
#
|
2
|
-
# This file was ported to ruby from Composer php source code.
|
3
|
-
# Original Source: Composer\Package\Dumper\ArrayDumper.php
|
4
|
-
#
|
5
|
-
# (c) Nils Adermann <naderman@naderman.de>
|
6
|
-
# Jordi Boggiano <j.boggiano@seld.be>
|
7
|
-
#
|
8
|
-
# For the full copyright and license information, please view the LICENSE
|
9
|
-
# file that was distributed with this source code.
|
10
|
-
#
|
11
|
-
|
12
|
-
module Composer
|
13
|
-
module Package
|
14
|
-
module Dumper
|
15
|
-
# Dumps a hash from a package
|
16
|
-
#
|
17
|
-
# PHP Authors:
|
18
|
-
# Konstantin Kudryashiv <ever.zet@gmail.com>
|
19
|
-
# Jordi Boggiano <j.boggiano@seld.be>
|
20
|
-
#
|
21
|
-
# Ruby Authors:
|
22
|
-
# Ioannis Kappas <ikappas@devworks.gr>
|
23
|
-
class HashDumper
|
24
|
-
def dump(package)
|
25
|
-
keys = {
|
26
|
-
'binaries' => 'bin',
|
27
|
-
'type' => 'type',
|
28
|
-
'extra' => 'extra',
|
29
|
-
'installation_source' => 'installation-source',
|
30
|
-
'autoload' => 'autoload',
|
31
|
-
'dev_autoload' => 'autoload-dev',
|
32
|
-
'notification_url' => 'notification-url',
|
33
|
-
'include_paths' => 'include-path',
|
34
|
-
}
|
35
|
-
|
36
|
-
data = {}
|
37
|
-
data['name'] = package.pretty_name
|
38
|
-
data['version'] = package.pretty_version
|
39
|
-
data['version_normalized'] = package.version
|
40
|
-
|
41
|
-
if package.target_dir
|
42
|
-
data['target-dir'] = package.target_dir
|
43
|
-
end
|
44
|
-
|
45
|
-
if package.source_type
|
46
|
-
data['source'] = {}
|
47
|
-
data['source']['type'] = package.source_type
|
48
|
-
data['source']['url'] = package.source_url
|
49
|
-
data['source']['reference'] = package.source_reference
|
50
|
-
if mirrors = package.source_mirrors
|
51
|
-
data['source']['mirrors'] = mirrors
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
if package.dist_type
|
56
|
-
data['dist'] = {}
|
57
|
-
data['dist']['type'] = package.dist_type
|
58
|
-
data['dist']['url'] = package.dist_url
|
59
|
-
data['dist']['reference'] = package.dist_reference
|
60
|
-
data['dist']['shasum'] = package.dist_sha1_checksum
|
61
|
-
if mirrors = package.dist_mirrors
|
62
|
-
data['dist']['mirrors'] = mirrors
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
unless package.archive_excludes.nil? || package.archive_excludes.empty?
|
67
|
-
data['archive'] = {}
|
68
|
-
data['archive']['exclude'] = package.archive_excludes
|
69
|
-
end
|
70
|
-
|
71
|
-
Composer::Package::BasePackage::SUPPORTED_LINK_TYPES.each do |type, opts|
|
72
|
-
next unless links = package.send(opts['method'])
|
73
|
-
next if links.nil?
|
74
|
-
next if links.is_a?(Array) && links.empty?
|
75
|
-
next if links.is_a?(Hash) && links.empty?
|
76
|
-
data[type] = {} unless data.key?(type)
|
77
|
-
values = links.is_a?(Hash) ? links.values : links
|
78
|
-
values.each do |link|
|
79
|
-
data[type][link.target] = link.pretty_constraint
|
80
|
-
end
|
81
|
-
data[type].keys.sort.each do |k|
|
82
|
-
data[type][k] = data[type].delete k
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
if packages = package.suggests
|
87
|
-
unless packages.nil? || packages.empty?
|
88
|
-
packages.keys.sort.each do |k|
|
89
|
-
packages[k] = packages.delete k
|
90
|
-
end
|
91
|
-
data['suggest'] = packages
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
if package.release_date && !package.release_date.nil?
|
96
|
-
data['time'] = package.release_date.strftime('%Y-%m-%d %H:%M:%S')
|
97
|
-
end
|
98
|
-
|
99
|
-
data = dump_values(package, keys, data)
|
100
|
-
|
101
|
-
# if data.key?('type') && data['type'] === 'library'
|
102
|
-
# data.delete('type')
|
103
|
-
# end
|
104
|
-
|
105
|
-
if package.is_a?(Composer::Package::CompletePackage)
|
106
|
-
keys = %w{scripts license authors description homepage keywords repositories support}
|
107
|
-
data = dump_values(package, keys, data)
|
108
|
-
|
109
|
-
if data.key?('keywords') && is_array?(data, 'keywords')
|
110
|
-
data['keywords'].sort!
|
111
|
-
end
|
112
|
-
|
113
|
-
if package.is_abandoned?
|
114
|
-
replacement = package.replacement_package
|
115
|
-
data['abandoned'] = replacement ? replacement : true
|
116
|
-
end
|
117
|
-
end
|
118
|
-
|
119
|
-
if package.is_a?(Composer::Package::RootPackage)
|
120
|
-
minimum_stability = package.minimum_stability
|
121
|
-
unless minimum_stability.nil? || minimum_stability.empty?
|
122
|
-
data['minimum-stability'] = minimum_stability
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
if !package.transport_options.nil? && package.transport_options.length > 0
|
127
|
-
data['transport-options'] = package.transport_options
|
128
|
-
end
|
129
|
-
|
130
|
-
data
|
131
|
-
end
|
132
|
-
|
133
|
-
private
|
134
|
-
|
135
|
-
def dump_values(package, keys, data)
|
136
|
-
keys.each do |method, key|
|
137
|
-
key = method unless key
|
138
|
-
next unless value = package.send(method)
|
139
|
-
next if value.nil?
|
140
|
-
next if value.is_a?(Array) && value.empty?
|
141
|
-
next if value.is_a?(Hash) && value.empty?
|
142
|
-
data[key] = value
|
143
|
-
end
|
144
|
-
data
|
145
|
-
end
|
146
|
-
|
147
|
-
def is_numeric?(value)
|
148
|
-
true if Float(value) rescue false
|
149
|
-
end
|
150
|
-
|
151
|
-
def is_empty?(config, key)
|
152
|
-
config.key?(key) ? config[key].empty? : true
|
153
|
-
end
|
154
|
-
|
155
|
-
def is_hash?(config, key)
|
156
|
-
config.key?(key) ? config[key].is_a?(Hash) : false
|
157
|
-
end
|
158
|
-
|
159
|
-
def is_array?(config, key)
|
160
|
-
config.key?(key) ? config[key].is_a?(Array) : false
|
161
|
-
end
|
162
|
-
|
163
|
-
def is_string?(config, key)
|
164
|
-
config.key?(key) ? config[key].is_a?(String) : false
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
1
|
+
#
|
2
|
+
# This file was ported to ruby from Composer php source code.
|
3
|
+
# Original Source: Composer\Package\Dumper\ArrayDumper.php
|
4
|
+
#
|
5
|
+
# (c) Nils Adermann <naderman@naderman.de>
|
6
|
+
# Jordi Boggiano <j.boggiano@seld.be>
|
7
|
+
#
|
8
|
+
# For the full copyright and license information, please view the LICENSE
|
9
|
+
# file that was distributed with this source code.
|
10
|
+
#
|
11
|
+
|
12
|
+
module Composer
|
13
|
+
module Package
|
14
|
+
module Dumper
|
15
|
+
# Dumps a hash from a package
|
16
|
+
#
|
17
|
+
# PHP Authors:
|
18
|
+
# Konstantin Kudryashiv <ever.zet@gmail.com>
|
19
|
+
# Jordi Boggiano <j.boggiano@seld.be>
|
20
|
+
#
|
21
|
+
# Ruby Authors:
|
22
|
+
# Ioannis Kappas <ikappas@devworks.gr>
|
23
|
+
class HashDumper
|
24
|
+
def dump(package)
|
25
|
+
keys = {
|
26
|
+
'binaries' => 'bin',
|
27
|
+
'type' => 'type',
|
28
|
+
'extra' => 'extra',
|
29
|
+
'installation_source' => 'installation-source',
|
30
|
+
'autoload' => 'autoload',
|
31
|
+
'dev_autoload' => 'autoload-dev',
|
32
|
+
'notification_url' => 'notification-url',
|
33
|
+
'include_paths' => 'include-path',
|
34
|
+
}
|
35
|
+
|
36
|
+
data = {}
|
37
|
+
data['name'] = package.pretty_name
|
38
|
+
data['version'] = package.pretty_version
|
39
|
+
data['version_normalized'] = package.version
|
40
|
+
|
41
|
+
if package.target_dir
|
42
|
+
data['target-dir'] = package.target_dir
|
43
|
+
end
|
44
|
+
|
45
|
+
if package.source_type
|
46
|
+
data['source'] = {}
|
47
|
+
data['source']['type'] = package.source_type
|
48
|
+
data['source']['url'] = package.source_url
|
49
|
+
data['source']['reference'] = package.source_reference
|
50
|
+
if mirrors = package.source_mirrors
|
51
|
+
data['source']['mirrors'] = mirrors
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
if package.dist_type
|
56
|
+
data['dist'] = {}
|
57
|
+
data['dist']['type'] = package.dist_type
|
58
|
+
data['dist']['url'] = package.dist_url
|
59
|
+
data['dist']['reference'] = package.dist_reference
|
60
|
+
data['dist']['shasum'] = package.dist_sha1_checksum
|
61
|
+
if mirrors = package.dist_mirrors
|
62
|
+
data['dist']['mirrors'] = mirrors
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
unless package.archive_excludes.nil? || package.archive_excludes.empty?
|
67
|
+
data['archive'] = {}
|
68
|
+
data['archive']['exclude'] = package.archive_excludes
|
69
|
+
end
|
70
|
+
|
71
|
+
Composer::Package::BasePackage::SUPPORTED_LINK_TYPES.each do |type, opts|
|
72
|
+
next unless links = package.send(opts['method'])
|
73
|
+
next if links.nil?
|
74
|
+
next if links.is_a?(Array) && links.empty?
|
75
|
+
next if links.is_a?(Hash) && links.empty?
|
76
|
+
data[type] = {} unless data.key?(type)
|
77
|
+
values = links.is_a?(Hash) ? links.values : links
|
78
|
+
values.each do |link|
|
79
|
+
data[type][link.target] = link.pretty_constraint
|
80
|
+
end
|
81
|
+
data[type].keys.sort.each do |k|
|
82
|
+
data[type][k] = data[type].delete k
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
if packages = package.suggests
|
87
|
+
unless packages.nil? || packages.empty?
|
88
|
+
packages.keys.sort.each do |k|
|
89
|
+
packages[k] = packages.delete k
|
90
|
+
end
|
91
|
+
data['suggest'] = packages
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
if package.release_date && !package.release_date.nil?
|
96
|
+
data['time'] = package.release_date.strftime('%Y-%m-%d %H:%M:%S')
|
97
|
+
end
|
98
|
+
|
99
|
+
data = dump_values(package, keys, data)
|
100
|
+
|
101
|
+
# if data.key?('type') && data['type'] === 'library'
|
102
|
+
# data.delete('type')
|
103
|
+
# end
|
104
|
+
|
105
|
+
if package.is_a?(Composer::Package::CompletePackage)
|
106
|
+
keys = %w{scripts license authors description homepage keywords repositories support}
|
107
|
+
data = dump_values(package, keys, data)
|
108
|
+
|
109
|
+
if data.key?('keywords') && is_array?(data, 'keywords')
|
110
|
+
data['keywords'].sort!
|
111
|
+
end
|
112
|
+
|
113
|
+
if package.is_abandoned?
|
114
|
+
replacement = package.replacement_package
|
115
|
+
data['abandoned'] = replacement ? replacement : true
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
if package.is_a?(Composer::Package::RootPackage)
|
120
|
+
minimum_stability = package.minimum_stability
|
121
|
+
unless minimum_stability.nil? || minimum_stability.empty?
|
122
|
+
data['minimum-stability'] = minimum_stability
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
if !package.transport_options.nil? && package.transport_options.length > 0
|
127
|
+
data['transport-options'] = package.transport_options
|
128
|
+
end
|
129
|
+
|
130
|
+
data
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
def dump_values(package, keys, data)
|
136
|
+
keys.each do |method, key|
|
137
|
+
key = method unless key
|
138
|
+
next unless value = package.send(method)
|
139
|
+
next if value.nil?
|
140
|
+
next if value.is_a?(Array) && value.empty?
|
141
|
+
next if value.is_a?(Hash) && value.empty?
|
142
|
+
data[key] = value
|
143
|
+
end
|
144
|
+
data
|
145
|
+
end
|
146
|
+
|
147
|
+
def is_numeric?(value)
|
148
|
+
true if Float(value) rescue false
|
149
|
+
end
|
150
|
+
|
151
|
+
def is_empty?(config, key)
|
152
|
+
config.key?(key) ? config[key].empty? : true
|
153
|
+
end
|
154
|
+
|
155
|
+
def is_hash?(config, key)
|
156
|
+
config.key?(key) ? config[key].is_a?(Hash) : false
|
157
|
+
end
|
158
|
+
|
159
|
+
def is_array?(config, key)
|
160
|
+
config.key?(key) ? config[key].is_a?(Array) : false
|
161
|
+
end
|
162
|
+
|
163
|
+
def is_string?(config, key)
|
164
|
+
config.key?(key) ? config[key].is_a?(String) : false
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|