File tree 3 files changed +72
-28
lines changed
3 files changed +72
-28
lines changed Original file line number Diff line number Diff line change @@ -25,33 +25,40 @@ Features:
25
25
Channel operations:
26
26
27
27
``` php
28
- <?php
29
- use CacheKit\FileSystemCache;
30
-
31
- $channel = new PEARX\Channel($host);
32
- $categories = $channel->getCategories();
33
-
34
- foreach( $categories as $category ) {
35
- // $category->name
36
- // $category->infoUrl
37
-
38
- $packages = $category->getPackages();
39
- foreach( $packages as $package ) {
40
- $package->name;
41
- $package->summary;
42
- $package->desc;
43
- $package->channel;
44
- $package->license;
45
- $package->deps;
46
- $package->releases;
47
-
48
- $package->stable; // version string
49
- $package->alpha; // version string
50
- $package->latest; // version string
51
-
52
- $stability = $package->getRelease('0.0.1');
53
- }
28
+ use CacheKit\FileSystemCache;
29
+
30
+ $channel = new PEARX\Channel($host);
31
+
32
+
33
+ // find package from the remote pear host
34
+ $package = $channel->findPackage('PEAR');
35
+
36
+
37
+
38
+ // traverse pear channel categories
39
+ $categories = $channel->getCategories();
40
+
41
+ foreach( $categories as $category ) {
42
+ // $category->name
43
+ // $category->infoUrl
44
+
45
+ $packages = $category->getPackages();
46
+ foreach( $packages as $package ) {
47
+ $package->name;
48
+ $package->summary;
49
+ $package->desc;
50
+ $package->channel;
51
+ $package->license;
52
+ $package->deps;
53
+ $package->releases;
54
+
55
+ $package->stable; // version string
56
+ $package->alpha; // version string
57
+ $package->latest; // version string
58
+
59
+ $stability = $package->getRelease('0.0.1');
54
60
}
61
+ }
55
62
```
56
63
57
64
Original file line number Diff line number Diff line change @@ -85,6 +85,28 @@ public function getRestBaseUrl($version = null)
85
85
return rtrim ($ this ->primary [ $ this ->rest ],'/ ' );
86
86
}
87
87
88
+ public function fetchPackageReleaseXml ($ packageName , $ version = 'stable ' )
89
+ {
90
+ $ baseUrl = $ this ->getRestBaseUrl ();
91
+ $ url = "$ baseUrl/r/ " . strtolower ($ packageName );
92
+
93
+ if ( $ version === 'stable '
94
+ || $ version === 'latest '
95
+ || $ version === 'beta ' )
96
+ {
97
+ // get version info
98
+ $ version = file_get_contents ($ url . '/ ' . $ version . '.txt ' );
99
+ }
100
+ $ url = $ url . '/ ' . $ version . '.xml ' ;
101
+ $ xmlStr = $ this ->core ->request ($ url );
102
+
103
+ // libxml_use_internal_errors(true);
104
+ $ xml = Utils::create_dom ();
105
+ if ( false === $ xml ->loadXml ( $ xmlStr ) ) {
106
+ throw new Exception ("Error in XMl document: $ url " );
107
+ }
108
+ return $ xml ;
109
+ }
88
110
89
111
/**
90
112
* fetch channel.xml from PEAR channel server.
@@ -151,6 +173,12 @@ public function getCategories()
151
173
return $ list ;
152
174
}
153
175
176
+
177
+ /**
178
+ * Get all packages from this channel.
179
+ *
180
+ * @return Package[]
181
+ */
154
182
public function getPackages ()
155
183
{
156
184
$ packages = array ();
@@ -160,6 +188,7 @@ public function getPackages()
160
188
return $ packages ;
161
189
}
162
190
191
+
163
192
public function findPackage ($ name )
164
193
{
165
194
foreach ( $ this ->getCategories () as $ category ) {
Original file line number Diff line number Diff line change 3
3
class ChannelTest extends PHPUnit_Framework_TestCase
4
4
{
5
5
6
+ public function testPackageReleaseInfoFinderWithLatest ()
7
+ {
8
+ $ channel = new PEARX \Channel ('pecl.php.net ' );
9
+ ok ($ channel );
10
+
11
+ $ xml = $ channel ->fetchPackageReleaseXml ('apc ' ,'latest ' );
12
+ ok ($ xml );
13
+ }
6
14
7
- public function testPackageFindPear ()
15
+ public function testPackageFindPearWithFileSystemCache ()
8
16
{
9
17
$ cache = new CacheKit \FileSystemCache (array (
10
18
'expiry ' => 10 ,
@@ -27,7 +35,7 @@ public function testPackageFindPear()
27
35
ok ( $ package ->license );
28
36
}
29
37
30
- public function testPackageFind ()
38
+ public function testPackageFindWithFileSystemCache ()
31
39
{
32
40
$ cache = new CacheKit \FileSystemCache (array (
33
41
'expiry ' => 10 ,
You can’t perform that action at this time.
0 commit comments