Skip to content

Commit de04334

Browse files
committed
Add Modular Extensions - HMVC (wiredesignz)
1 parent d56c6ea commit de04334

2 files changed

Lines changed: 57 additions & 4 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ $ php bin/install.php matches-cli master
5656
$ php bin/install.php hmvc-modules master
5757
```
5858

59+
[Modular Extensions - HMVC](https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc):
60+
61+
```
62+
$ php bin/install.php modular-extensions-hmvc codeigniter-3.x
63+
```
64+
5965
### Run PHP built-in server (PHP 5.4 or later)
6066

6167
```

bin/install.php

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,36 @@ public function __construct() {
2323

2424
$this->packages = [
2525
'translations' => array(
26-
'repos' => 'github',
26+
'site' => 'github',
2727
'user' => 'bcit-ci',
2828
'repos' => 'codeigniter3-translations',
2929
'name' => 'Translations for CodeIgniter System Messages',
3030
'dir' => 'language',
3131
),
3232
'matches-cli' => array(
33-
'repos' => 'github',
33+
'site' => 'github',
3434
'user' => 'avenirer',
3535
'repos' => 'codeigniter-matches-cli',
3636
'name' => 'Codeigniter Matches CLI',
3737
'dir' => array('config', 'controllers', 'views'),
3838
'msg' => 'See http://avenirer.github.io/codeigniter-matches-cli/',
3939
),
4040
'hmvc-modules' => array(
41-
'repos' => 'github',
41+
'site' => 'github',
4242
'user' => 'jenssegers',
4343
'repos' => 'codeigniter-hmvc-modules',
4444
'name' => 'CodeIgniter HMVC Modules (jenssegers)',
4545
'dir' => array('core', 'third_party'),
4646
'msg' => 'See https://github.com/jenssegers/codeigniter-hmvc-modules#installation',
4747
),
48+
'modular-extensions-hmvc' => array(
49+
'site' => 'bitbucket',
50+
'user' => 'wiredesignz',
51+
'repos' => 'codeigniter-modular-extensions-hmvc',
52+
'name' => 'Modular Extensions - HMVC (wiredesignz)',
53+
'dir' => array('core', 'third_party'),
54+
'msg' => 'See https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc',
55+
),
4856
];
4957
}
5058

@@ -65,6 +73,7 @@ public function usage($self)
6573
$msg .= " php $self translations develop" . PHP_EOL;
6674
$msg .= " php $self matches-cli master" . PHP_EOL;
6775
$msg .= " php $self hmvc-modules master" . PHP_EOL;
76+
$msg .= " php $self modular-extensions-hmvc codeigniter-3.x" . PHP_EOL;
6877

6978
return $msg;
7079
}
@@ -77,7 +86,17 @@ public function install($package, $version)
7786
}
7887

7988
// github
80-
list($src, $dst) = $this->downloadFromGithub($package, $version);
89+
if ($this->packages[$package]['site'] === 'github') {
90+
$method = 'downloadFromGithub';
91+
} elseif ($this->packages[$package]['site'] === 'bitbucket') {
92+
$method = 'downloadFromBitbucket';
93+
} else {
94+
throw new LogicException(
95+
'Error! no such repos type: ' . $this->packages[$package]['site']
96+
);
97+
}
98+
99+
list($src, $dst) = $this->$method($package, $version);
81100

82101
$this->recursiveCopy($src, $dst);
83102
$this->recursiveUnlink($this->tmp_dir);
@@ -112,6 +131,30 @@ private function downloadFromGithub($package, $version)
112131
return [$src, $dst];
113132
}
114133

134+
private function downloadFromBitbucket($package, $version)
135+
{
136+
$user = $this->packages[$package]['user'];
137+
$repos = $this->packages[$package]['repos'];
138+
// https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/get/codeigniter-3.x.zip
139+
$url = "https://bitbucket.org/$user/$repos/get/$version.zip";
140+
$filepath = $this->download($url);
141+
$dirname = $this->unzip($filepath);
142+
143+
$dir = $this->packages[$package]['dir'];
144+
145+
if (is_string($dir)) {
146+
$src = realpath(dirname($filepath) . "/$dirname/$dir");
147+
$dst = realpath(__DIR__ . "/../application/$dir");
148+
return [$src, $dst];
149+
}
150+
151+
foreach ($dir as $directory) {
152+
$src[] = realpath(dirname($filepath) . "/$dirname/$directory");
153+
$dst[] = realpath(__DIR__ . "/../application/$directory");
154+
}
155+
return [$src, $dst];
156+
}
157+
115158
private function download($url)
116159
{
117160
$file = file_get_contents($url);
@@ -131,11 +174,15 @@ private function unzip($filepath)
131174
{
132175
$zip = new ZipArchive();
133176
if ($zip->open($filepath) === TRUE) {
177+
$tmp = explode('/', $zip->getNameIndex(0));
178+
$dirname = $tmp[0];
134179
$zip->extractTo($this->tmp_dir . '/');
135180
$zip->close();
136181
} else {
137182
throw new RuntimeException('Failed to unzip: ' . $filepath);
138183
}
184+
185+
return $dirname;
139186
}
140187

141188
/**

0 commit comments

Comments
 (0)