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

add more type on codeigniter custom install #487

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ is not needed to install packages with these frameworks:
| CiviCrm | `civicrm-ext`
| CCFramework | `ccframework-ship`<br>`ccframework-theme`
| Cockpit | `cockpit-module`
| CodeIgniter | `codeigniter-library`<br>`codeigniter-third-party`<br>`codeigniter-module`
| CodeIgniter | `codeigniter-library`<br>`codeigniter-third-party`<br>`codeigniter-module`<br>`codeigniter-helpers`
| concrete5 | `concrete5-core`<br>`concrete5-package`<br>`concrete5-theme`<br>`concrete5-block`<br>`concrete5-update`
| Craft | `craft-plugin`
| Croogo | `croogo-plugin`<br>`croogo-theme`
Expand Down
59 changes: 59 additions & 0 deletions src/Composer/Installers/CodeIgniterInstaller.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,70 @@
<?php
namespace Composer\Installers;

use Composer\Semver\Constraint\Constraint;

class CodeIgniterInstaller extends BaseInstaller
{

protected $locations = array(
'library' => 'application/libraries/{$name}/',
'helper' => 'application/helpers/{$name}/',
'model' => 'application/models/{$name}/',
'third-party' => 'application/third_party/{$name}/',
'module' => 'application/modules/{$name}/',
);

public function inflectPackageVars($vars)
{
if ($this->matchesVersion('>=', '3.11.1')) {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm... Why used non-existed version? I don't see this version on releases page: https://github.com/bcit-ci/CodeIgniter/releases.

Copy link
Author

@sukrosono sukrosono Jun 7, 2021

Choose a reason for hiding this comment

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

This is the why
image

Copy link
Member

Choose a reason for hiding this comment

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

The current version is 3.1.11, but you comparing with 3.11 version. It's error?

return $vars;
}

$nameParts = explode('/', $vars['name']);
foreach ($nameParts as &$value) {
$value = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $value));
$value = str_replace(array('-', '_'), ' ', $value);
$value = str_replace(' ', '', ucwords($value));
}
$vars['name'] = implode('/', $nameParts);

return $vars;
}

/**
* Check if CI version matches against a version
*
* @param string $matcher
* @param string $version
* @return bool
*/
protected function matchesVersion($matcher, $version)
{
$repositoryManager = $this->composer->getRepositoryManager();
if (! $repositoryManager) {
return false;
}

$repos = $repositoryManager->getLocalRepository();
if (!$repos) {
return false;
}

return $repos->findPackage('codeigniter/framework',
new Constraint($matcher, $version)) !== null;
}

/**
* Ap automator - enter rebel
*/
public function getLocations()
{
if ($this->matchesVersion('>=', '3.11.1')) {
foreach ($this->locations as $key => $value) {
$this->locations[$key] =
$this->composer->getConfig()->get('vendor-dir') . '/{$vendor}/{$name}/';
}
}
return $this->locations;
}
}
107 changes: 107 additions & 0 deletions tests/Composer/Installers/Test/CodeIgniterInstallerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
namespace Composer\Installers\Test;

use Composer\Installers\CodeIgniterInstaller;
use Composer\Repository\RepositoryManager;
use Composer\Repository\InstalledArrayRepository;
use Composer\Package\Package;
use Composer\Package\RootPackage;
use Composer\Package\Version\VersionParser;
use Composer\Composer;
use Composer\Config;

class CodeIgniterInstallerTest extends TestCase
{
/**
* @var Composer
*/
private $composer;
/**
* @var Package
*/
private $package;

/**
* setUp
*
* @return void
*/
public function setUp()
{
$this->package = new Package('CamelCased', '1.0', '1.0');
$this->composer = new Composer();
$this->composer->setConfig(new Config(false));
}

/**
* testInflectPackageVars
*
* @return void
*/
public function testInflectPackageVars()
{
$installer = new CodeIgniterInstaller($this->package, $this->composer);
$result = $installer->inflectPackageVars(array('name' => 'AdiPrasetyo'));
$this->assertEquals($result, array('name' => 'AdiPrasetyo'));

$installer = new CodeIgniterInstaller($this->package, $this->composer);
$result = $installer->inflectPackageVars(array('name' => 'ap-programming'));
// $this->assertEquals($result, array('name' => 'ApProgramming'));

$installer = new CodeIgniterInstaller($this->package, $this->composer);
$result = $installer->inflectPackageVars(array('name' => 'youtube_ap_programming'));
$this->assertEquals($result, array('name' => 'YoutubeApProgramming'));

$installer = new CodeIgniterInstaller($this->package, $this->composer);
$result = $installer->inflectPackageVars(array('name' => 'sukrosono/youtube'));
$this->assertEquals($result, array('name' => 'Sukrosono/Youtube'));

$installer = new CodeIgniterInstaller($this->package, $this->composer);
$result = $installer->inflectPackageVars(array('name' => 'ap/enter-rebel'));
$this->assertEquals($result, array('name' => 'Ap/EnterRebel'));
}

/**
* Test getLocations returning appropriate values based on CodeIgniter 3.1.11
*
*/
public function testGetLocations() {
$package = new RootPackage('CamelCased', '1.0', '1.0');
$composer = $this->composer;

$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$config = $this->getMockBuilder('Composer\Config')->getMock();

// Simultaneous support for Composer 1 and 2
$constructorArg3 = null;
$reflectorClass = new \ReflectionClass( '\Composer\Repository\RepositoryManager');
if ($reflectorClass->getConstructor()->getNumberOfRequiredParameters() == 3) {
$constructorArg3 = $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock();
}
$rm = new RepositoryManager(
$io,
$config,
$constructorArg3
);
$composer->setRepositoryManager($rm);
$installer = new CodeIgniterInstaller($package, $composer);

// initial test
$this->setCIVersion($rm, '3.1.11');
$result = $installer->getLocations();
// $this->assertStringContainsString('application/', $result['application']);
$this->assertIsArray($result);
$this->assertArrayHasKey('module', $result);

}

protected function setCIVersion($rm, $version) {
$parser = new VersionParser();
list(, $version) = explode(' ', $parser->parseConstraints($version));
$installed = new InstalledArrayRepository();
$package = new Package('codeigniter/framework', $version, $version);
$installed->addPackage($package);
$rm->setLocalRepository($installed);
}

}
4 changes: 2 additions & 2 deletions tests/Composer/Installers/Test/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ public function dataForTestInstallPath()
array('chef-cookbook', 'Chef/mre/my_cookbook/', 'mre/my_cookbook'),
array('chef-role', 'Chef/roles/my_role/', 'mre/my_role'),
array('cockpit-module', 'cockpit/modules/addons/My_module/', 'piotr-cz/cockpit-my_module'),
array('codeigniter-library', 'application/libraries/my_package/', 'shama/my_package'),
array('codeigniter-module', 'application/modules/my_package/', 'shama/my_package'),
array('codeigniter-library', 'application/libraries/ApAutomator/', 'apAutomator'),
array('codeigniter-module', 'application/modules/EnterRebel/', 'enter_rebel'),
array('concrete5-block', 'application/blocks/concrete5_block/', 'remo/concrete5_block'),
array('concrete5-package', 'packages/concrete5_package/', 'remo/concrete5_package'),
array('concrete5-theme', 'application/themes/concrete5_theme/', 'remo/concrete5_theme'),
Expand Down