Skip to content

Commit 98b34f8

Browse files
authored
Add installer for TastyIgniter extensions and themes (#478)
1 parent df100b0 commit 98b34f8

File tree

6 files changed

+133
-0
lines changed

6 files changed

+133
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ is not needed to install packages with these frameworks:
115115
| Sylius | `sylius-theme`
116116
| symfony1 | **`symfony1-plugin`**
117117
| TAO | `tao-extension`
118+
| TastyIgniter | **`tastyigniter-extension`<br>`tastyigniter-theme`**
118119
| Tusk | `tusk-task`<br>`tusk-command`<br>`tusk-asset`
119120
| TYPO3 Flow | `typo3-flow-package`<br>`typo3-flow-framework`<br>`typo3-flow-plugin`<br>`typo3-flow-site`<br>`typo3-flow-boilerplate`<br>`typo3-flow-build`
120121
| TYPO3 CMS | `typo3-cms-extension` (Deprecated in this package, use the [TYPO3 CMS Installers](https://packagist.org/packages/typo3/cms-composer-installers) instead)

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"SyDES",
6969
"Sylius",
7070
"symfony",
71+
"TastyIgniter",
7172
"Thelia",
7273
"TYPO3",
7374
"WHMCS",

src/Composer/Installers/Installer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class Installer extends LibraryInstaller
5050
'fuelphp' => 'FuelphpInstaller',
5151
'grav' => 'GravInstaller',
5252
'hurad' => 'HuradInstaller',
53+
'tastyigniter' => 'TastyIgniterInstaller',
5354
'imagecms' => 'ImageCMSInstaller',
5455
'itop' => 'ItopInstaller',
5556
'joomla' => 'JoomlaInstaller',
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Composer\Installers;
4+
5+
class TastyIgniterInstaller extends BaseInstaller
6+
{
7+
protected $locations = array(
8+
'extension' => 'extensions/{$vendor}/{$name}/',
9+
'theme' => 'themes/{$name}/',
10+
);
11+
12+
/**
13+
* Format package name.
14+
*
15+
* Cut off leading 'ti-ext-' or 'ti-theme-' if present.
16+
* Strip vendor name of characters that is not alphanumeric or an underscore
17+
*
18+
*/
19+
public function inflectPackageVars($vars)
20+
{
21+
if ($vars['type'] === 'tastyigniter-extension') {
22+
$vars['vendor'] = preg_replace('/[^a-z0-9_]/i', '', $vars['vendor']);
23+
$vars['name'] = preg_replace('/^ti-ext-/', '', $vars['name']);
24+
}
25+
26+
if ($vars['type'] === 'tastyigniter-theme') {
27+
$vars['name'] = preg_replace('/^ti-theme-/', '', $vars['name']);
28+
}
29+
30+
return $vars;
31+
}
32+
}

tests/Composer/Installers/Test/InstallerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ public function dataForTestSupport()
223223
array('sydes-theme', true),
224224
array('sylius-theme', true),
225225
array('symfony1-plugin', true),
226+
array('tastyigniter-extension', true),
227+
array('tastyigniter-theme', true),
226228
array('thelia-module', true),
227229
array('thelia-frontoffice-template', true),
228230
array('thelia-backoffice-template', true),
@@ -435,6 +437,8 @@ public function dataForTestInstallPath()
435437
array('sylius-theme', 'themes/my_theme/', 'shama/my_theme'),
436438
array('symfony1-plugin', 'plugins/sfShamaPlugin/', 'shama/sfShamaPlugin'),
437439
array('symfony1-plugin', 'plugins/sfShamaPlugin/', 'shama/sf-shama-plugin'),
440+
array('tastyigniter-extension', 'extensions/shama/my_extension/', 'shama/my_extension'),
441+
array('tastyigniter-theme', 'themes/my_theme/', 'shama/my_theme'),
438442
array('thelia-module', 'local/modules/my_module/', 'shama/my_module'),
439443
array('thelia-frontoffice-template', 'templates/frontOffice/my_template_fo/', 'shama/my_template_fo'),
440444
array('thelia-backoffice-template', 'templates/backOffice/my_template_bo/', 'shama/my_template_bo'),
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
namespace Composer\Installers\Test;
4+
5+
use Composer\Composer;
6+
use Composer\Installers\TastyIgniterInstaller;
7+
use Composer\Package\Package;
8+
use PHPUnit\Framework\TestCase as BaseTestCase;
9+
10+
class TastyIgniterInstallerTest extends BaseTestCase
11+
{
12+
/**
13+
* @var TastyIgniterInstaller
14+
*/
15+
private $installer;
16+
17+
/**
18+
* setUp
19+
*
20+
* @return void
21+
*/
22+
public function setUp()
23+
{
24+
$this->installer = new TastyIgniterInstaller(
25+
new Package('NyanCat', '4.2', '4.2'),
26+
new Composer()
27+
);
28+
}
29+
30+
/**
31+
* @dataProvider packageNameInflectionProvider
32+
*
33+
* @return void
34+
*/
35+
public function testInflectPackageVars($type, $vendor, $name, $expectedVendor, $expectedName)
36+
{
37+
$this->assertEquals(
38+
$this->installer->inflectPackageVars(array(
39+
'vendor' => $vendor,
40+
'name' => $name,
41+
'type' => $type,
42+
)),
43+
array(
44+
'vendor' => $expectedVendor,
45+
'name' => $expectedName,
46+
'type' => $type
47+
)
48+
);
49+
}
50+
51+
public function packageNameInflectionProvider()
52+
{
53+
return array(
54+
array(
55+
'tastyigniter-extension',
56+
'acme',
57+
'pages',
58+
'acme',
59+
'pages',
60+
),
61+
array(
62+
'tastyigniter-extension',
63+
'acme',
64+
'ti-ext-pages',
65+
'acme',
66+
'pages',
67+
),
68+
// tests vendor name containing a hyphen
69+
array(
70+
'tastyigniter-extension',
71+
'foo-bar-co',
72+
'blog',
73+
'foobarco',
74+
'blog',
75+
),
76+
// tests that exactly one '-theme' is cut off
77+
array(
78+
'tastyigniter-theme',
79+
'acme',
80+
'ti-theme-theme',
81+
'acme',
82+
'theme',
83+
),
84+
// tests that names without '-theme' suffix stay valid
85+
array(
86+
'tastyigniter-theme',
87+
'acme',
88+
'someothertheme',
89+
'acme',
90+
'someothertheme',
91+
),
92+
);
93+
}
94+
}

0 commit comments

Comments
 (0)