Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package type common-webroot #53

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Composer/Installers/BaseInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public function getInstallPath(PackageInterface $package, $frameworkType = '')
}

$availableVars = $this->inflectPackageVars(compact('name', 'vendor', 'type'));
$availableVars['webroot'] = '';

$extra = $package->getExtra();
if (!empty($extra['installer-name'])) {
Expand All @@ -50,12 +51,17 @@ public function getInstallPath(PackageInterface $package, $frameworkType = '')

if ($this->composer->getPackage()) {
$extra = $this->composer->getPackage()->getExtra();
if (!empty($extra['installer-webroot'])) {
$availableVars['webroot'] = $extra['installer-webroot'];
}
if (!empty($extra['installer-paths'])) {
$customPath = $this->mapCustomInstallPaths($extra['installer-paths'], $prettyName);
if ($customPath !== false) {
return $this->templatePath($customPath, $availableVars);
}
}
} elseif ('common-webroot' === $type) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be better to implement a hook for installers to validate package configuration instead of adding this into base installer here.

throw new \InvalidArgumentException(sprintf('Package "%s" requires "installer-webroot" to be configured', $prettyName));
}

$packageType = substr($type, strlen($frameworkType) + 1);
Expand Down
9 changes: 9 additions & 0 deletions src/Composer/Installers/CommonInstaller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
namespace Composer\Installers;

class CommonInstaller extends BaseInstaller
{
protected $locations = array(
'webroot' => '{$webroot}/',
);
}
3 changes: 2 additions & 1 deletion src/Composer/Installers/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ class Installer extends LibraryInstaller
'symfony1' => 'Symfony1Installer',
'wordpress' => 'WordPressInstaller',
'zend' => 'ZendInstaller',
'typo3-flow' => 'TYPO3FlowInstaller'
'typo3-flow' => 'TYPO3FlowInstaller',
'common' => 'CommonInstaller'
);

/**
Expand Down
34 changes: 34 additions & 0 deletions tests/Composer/Installers/Test/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,40 @@ public function testGetCakePHPInstallPathException()
$package->setType('cakephp-whoops');
$result = $installer->getInstallPath($package);
}

/**
* testCommonWebrootPackage
*/
public function testCommonWebrootPackage()
{
$installer = new Installer($this->io, $this->composer);
$package = new Package('slbmeh/my_application', '1.0.0', '1.0.0');

$package->setType('common-webroot');
$consumerPackage = new RootPackage('foo/bar', '1.0.0', '1.0.0');
$this->composer->setPackage($consumerPackage);
$consumerPackage->setExtra(array(
'installer-webroot' => 'webroot'
));
$result = $installer->getInstallPath($package);
$this->assertEquals('webroot/', $result);
}

/**
* testCommonWebrootPackage
*
* @return void
*
* @expectedException \InvalidArgumentException
*/
public function testCommonWebrootPathException()
{
$installer = new Installer($this->io, $this->composer);
$package = new Package('slbmeh/my_application', '1.0.0', '1.0.0');

$package->setType('common-webroot');
$result = $installer->getInstallPath($package);
}

/**
* testCustomInstallPath
Expand Down