forked from willfarrell/alfred-pkgman-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Composer.php
69 lines (56 loc) · 1.88 KB
/
Composer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
namespace WillFarrell\AlfredPkgMan;
require_once('Cache.php');
require_once('Repo.php');
class Composer extends Repo
{
protected $id = 'composer';
protected $kind = 'packages';
protected $url = 'https://packagist.org';
public function search($query)
{
if (!$this->hasMinQueryLength($query)) {
return $this->xml();
}
$this->pkgs = $this->cache->get_query_json(
$this->id,
$query,
"{$this->url}/search.json?q={$query}"
)->results;
// foreach ($this->pkgs as $pkg) {
// // make params
// preg_match('/<a(.*?)<\/a>/i', $pkg, $matches);
// $title = strip_tags($matches[0]);
// preg_match('/<p class="package-description">([\s\S]*?)<\/p>/i', $pkg, $matches);
// $details = strip_tags($matches[1]);
// $this->cache->w->result(
// $title,
// $this->makeArg($title, "{$this->url}/packages/{$title}"),
// $title,
// $details,
// "icon-cache/{$this->id}.png"
// );
foreach ($this->pkgs as $pkg) {
$title = $pkg->name;
$this->cache->w->result(
$pkg->name,
$this->makeArg(
$pkg->name,
$pkg->url
),
$title,
$pkg->description,
"icon-cache/{$this->id}.png"
);
// only search till max return reached
if (count($this->cache->w->results()) == $this->max_return) {
break;
}
}
$this->noResults($query, "{$this->url}/?q={$query}");
return $this->xml();
}
}
// Test code, uncomment to debug this script from the command-line
// $repo = new Composer();
// echo $repo->search('c');