├── .gitignore ├── LICENSE.md ├── README.md ├── bin ├── .placeholder ├── check-diff.sh ├── install.php ├── my-codeigniter.sh ├── router.php └── server.sh ├── composer.json ├── composer.json.dist ├── dot.htaccess └── src └── Installer.php /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | application/cache/* 4 | !application/cache/index.html 5 | !application/cache/.htaccess 6 | 7 | application/logs/* 8 | !application/logs/index.html 9 | !application/logs/.htaccess 10 | 11 | user_guide_src/build/* 12 | user_guide_src/cilexer/build/* 13 | user_guide_src/cilexer/dist/* 14 | user_guide_src/cilexer/pycilexer.egg-info/* 15 | /vendor/ 16 | 17 | # IDE Files 18 | #------------------------- 19 | /nbproject/ 20 | .idea/* 21 | 22 | ## Sublime Text cache files 23 | *.tmlanguage.cache 24 | *.tmPreferences.cache 25 | *.stTheme.cache 26 | *.sublime-workspace 27 | *.sublime-project 28 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2015 Kenji Suzuki 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CodeIgniter Composer Installer 2 | 3 | [![Latest Stable Version](https://poser.pugx.org/kenjis/codeigniter-composer-installer/v/stable)](https://packagist.org/packages/kenjis/codeigniter-composer-installer) [![Total Downloads](https://poser.pugx.org/kenjis/codeigniter-composer-installer/downloads)](https://packagist.org/packages/kenjis/codeigniter-composer-installer) [![Latest Unstable Version](https://poser.pugx.org/kenjis/codeigniter-composer-installer/v/unstable)](https://packagist.org/packages/kenjis/codeigniter-composer-installer) [![License](https://poser.pugx.org/kenjis/codeigniter-composer-installer/license)](https://packagist.org/packages/kenjis/codeigniter-composer-installer) 4 | 5 | This package installs the offical [CodeIgniter](https://github.com/bcit-ci/CodeIgniter) (version `3.1.*`) with secure folder structure via Composer. 6 | 7 | You can update CodeIgniter system folder to latest version with one command. 8 | 9 | ## Folder Structure 10 | 11 | ``` 12 | codeigniter/ 13 | ├── application/ 14 | ├── composer.json 15 | ├── composer.lock 16 | ├── public/ 17 | │   ├── .htaccess 18 | │   └── index.php 19 | └── vendor/ 20 | └── codeigniter/ 21 |    └── framework/ 22 |    └── system/ 23 | ``` 24 | 25 | ## Requirements 26 | 27 | * PHP 5.3.7 or [later](https://www.php.net/supported-versions.php) 28 | * `composer` command (See [Composer Installation](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx)) 29 | * Git 30 | 31 | ## How to Use 32 | 33 | ### Install CodeIgniter 34 | 35 | ``` 36 | $ composer create-project kenjis/codeigniter-composer-installer codeigniter 37 | ``` 38 | 39 | Above command installs `public/.htaccess` to remove `index.php` in your URL. If you don't need it, please remove it. 40 | 41 | And it changes `application/config/config.php`: 42 | 43 | ~~~ 44 | $config['composer_autoload'] = FALSE; 45 | ↓ 46 | $config['composer_autoload'] = realpath(APPPATH . '../vendor/autoload.php'); 47 | ~~~ 48 | 49 | ~~~ 50 | $config['index_page'] = 'index.php'; 51 | ↓ 52 | $config['index_page'] = ''; 53 | ~~~ 54 | 55 | #### Install Translations for System Messages 56 | 57 | If you want to install translations for system messages: 58 | 59 | ``` 60 | $ cd /path/to/codeigniter 61 | $ php bin/install.php translations 3.1.0 62 | ``` 63 | 64 | #### Install Third Party Libraries 65 | 66 | [Codeigniter Matches CLI](https://github.com/avenirer/codeigniter-matches-cli): 67 | 68 | ``` 69 | $ php bin/install.php matches-cli master 70 | ``` 71 | 72 | [CodeIgniter HMVC Modules](https://github.com/jenssegers/codeigniter-hmvc-modules): 73 | 74 | ``` 75 | $ php bin/install.php hmvc-modules master 76 | ``` 77 | 78 | [Modular Extensions - HMVC](https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc): 79 | 80 | ``` 81 | $ php bin/install.php modular-extensions-hmvc codeigniter-3.x 82 | ``` 83 | 84 | [Ion Auth](https://github.com/benedmunds/CodeIgniter-Ion-Auth): 85 | 86 | ``` 87 | $ php bin/install.php ion-auth 2 88 | ``` 89 | 90 | [CodeIgniter3 Filename Checker](https://github.com/kenjis/codeigniter3-filename-checker): 91 | 92 | ``` 93 | $ php bin/install.php filename-checker master 94 | ``` 95 | 96 | [CodeIgniter Rest Server](https://github.com/chriskacerguis/codeigniter-restserver): 97 | 98 | ``` 99 | $ php bin/install.php restserver 2.7.2 100 | ``` 101 | [CodeIgniter Developer Toolbar](https://github.com/JCSama/CodeIgniter-develbar): 102 | 103 | ``` 104 | $ php bin/install.php codeigniter-develbar master 105 | ``` 106 | 107 | ### Run PHP built-in server (PHP 5.4 or later) 108 | 109 | ``` 110 | $ cd /path/to/codeigniter 111 | $ bin/server.sh 112 | ``` 113 | 114 | ### Update CodeIgniter 115 | 116 | ``` 117 | $ cd /path/to/codeigniter 118 | $ composer update 119 | ``` 120 | 121 | You must update files manually if files in `application` folder or `index.php` change. Check [CodeIgniter User Guide](http://www.codeigniter.com/user_guide/installation/upgrading.html). 122 | 123 | ## Reference 124 | 125 | * [Composer Installation](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx) 126 | * [CodeIgniter](https://github.com/bcit-ci/CodeIgniter) 127 | * [Translations for CodeIgniter System](https://github.com/bcit-ci/codeigniter3-translations) 128 | 129 | ## Related Projects for CodeIgniter 3.x 130 | 131 | * [Cli for CodeIgniter 3.0](https://github.com/kenjis/codeigniter-cli) 132 | * [ci-phpunit-test](https://github.com/kenjis/ci-phpunit-test) 133 | * [CodeIgniter Simple and Secure Twig](https://github.com/kenjis/codeigniter-ss-twig) 134 | * [CodeIgniter Doctrine](https://github.com/kenjis/codeigniter-doctrine) 135 | * [CodeIgniter Deployer](https://github.com/kenjis/codeigniter-deployer) 136 | * [CodeIgniter3 Filename Checker](https://github.com/kenjis/codeigniter3-filename-checker) 137 | * [CodeIgniter Widget (View Partial) Sample](https://github.com/kenjis/codeigniter-widgets) 138 | -------------------------------------------------------------------------------- /bin/.placeholder: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenjis/codeigniter-composer-installer/0b84b24c8dfb70f0699908c4704800421f0a6933/bin/.placeholder -------------------------------------------------------------------------------- /bin/check-diff.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ## Part of CodeIgniter Composer Installer 4 | ## 5 | ## @author Kenji Suzuki 6 | ## @license MIT License 7 | ## @copyright 2015 Kenji Suzuki 8 | ## @link https://github.com/kenjis/codeigniter-composer-installer 9 | 10 | cd `dirname $0` 11 | cd .. 12 | 13 | diff -urN vendor/codeigniter/framework/application application 14 | diff -u vendor/codeigniter/framework/index.php public/index.php 15 | -------------------------------------------------------------------------------- /bin/install.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env php 2 | install($package, $version); 10 | } else { 11 | echo $installer->usage($argv[0]); 12 | } 13 | 14 | 15 | class Installer 16 | { 17 | protected $tmp_dir; 18 | protected $packages = array(); 19 | 20 | public function __construct() { 21 | $this->tmp_dir = __DIR__ . '/tmp'; 22 | @mkdir($this->tmp_dir); 23 | 24 | $this->packages = array( 25 | 'translations' => array( 26 | 'site' => 'github', 27 | 'user' => 'bcit-ci', 28 | 'repos' => 'codeigniter3-translations', 29 | 'name' => 'Translations for CodeIgniter System Messages', 30 | 'dir' => 'language', 31 | 'example_branch' => '3.1.0', 32 | ), 33 | 'restserver' => array( 34 | 'site' => 'github', 35 | 'user' => 'chriskacerguis', 36 | 'repos' => 'codeigniter-restserver', 37 | 'name' => 'CodeIgniter Rest Server', 38 | 'dir' => array('config', 'controllers', 'language', 'libraries', 'views'), 39 | 'pre' => 'application/', 40 | 'msg' => 'See https://github.com/chriskacerguis/codeigniter-restserver', 41 | 'example_branch' => '2.7.2', 42 | ), 43 | 'matches-cli' => array( 44 | 'site' => 'github', 45 | 'user' => 'avenirer', 46 | 'repos' => 'codeigniter-matches-cli', 47 | 'name' => 'Codeigniter Matches CLI', 48 | 'dir' => array('config', 'controllers', 'views'), 49 | 'msg' => 'See http://avenirer.github.io/codeigniter-matches-cli/', 50 | 'example_branch' => 'master', 51 | ), 52 | 'hmvc-modules' => array( 53 | 'site' => 'github', 54 | 'user' => 'jenssegers', 55 | 'repos' => 'codeigniter-hmvc-modules', 56 | 'name' => 'CodeIgniter HMVC Modules (jenssegers)', 57 | 'dir' => array('core', 'third_party'), 58 | 'msg' => 'See https://github.com/jenssegers/codeigniter-hmvc-modules#installation', 59 | 'example_branch' => 'master', 60 | ), 61 | 'modular-extensions-hmvc' => array( 62 | 'site' => 'bitbucket', 63 | 'user' => 'wiredesignz', 64 | 'repos' => 'codeigniter-modular-extensions-hmvc', 65 | 'name' => 'Modular Extensions - HMVC (wiredesignz)', 66 | 'dir' => array('core', 'third_party'), 67 | 'msg' => 'See https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc', 68 | 'example_branch' => 'codeigniter-3.x', 69 | ), 70 | 'ion-auth' => array( 71 | 'site' => 'github', 72 | 'user' => 'benedmunds', 73 | 'repos' => 'CodeIgniter-Ion-Auth', 74 | 'name' => 'Codeigniter Ion Auth', 75 | 'dir' => array( 76 | 'config', 'controllers', 'language', 'libraries', 77 | 'migrations', 'models', 'sql', 'views' 78 | ), 79 | 'msg' => 'See http://benedmunds.com/ion_auth/', 80 | 'example_branch' => '2', 81 | ), 82 | 'filename-checker' => array( 83 | 'site' => 'github', 84 | 'user' => 'kenjis', 85 | 'repos' => 'codeigniter3-filename-checker', 86 | 'name' => 'CodeIgniter3 Filename Checker', 87 | 'dir' => 'controllers', 88 | 'msg' => 'See https://github.com/kenjis/codeigniter3-filename-checker', 89 | 'example_branch' => 'master', 90 | ), 91 | 'codeigniter-develbar' => array( 92 | 'site' => 'github', 93 | 'user' => 'jcsama', 94 | 'repos' => 'CodeIgniter-develbar', 95 | 'name' => 'CodeIgniter Developer Toolbar', 96 | 'dir' => array('config','core', 'third_party','controllers'), 97 | 'msg' => 'See https://github.com/JCSama/CodeIgniter-develbar', 98 | 'example_branch' => 'master', 99 | ), 100 | ); 101 | } 102 | 103 | public function usage($self) 104 | { 105 | $msg = 'You can install:' . PHP_EOL; 106 | 107 | foreach ($this->packages as $key => $value) { 108 | $msg .= ' ' . $value['name'] . ' (' . $key . ')' . PHP_EOL; 109 | } 110 | 111 | $msg .= PHP_EOL; 112 | $msg .= 'Usage:' . PHP_EOL; 113 | $msg .= ' php install.php ' . PHP_EOL; 114 | $msg .= PHP_EOL; 115 | $msg .= 'Examples:' . PHP_EOL; 116 | 117 | foreach ($this->packages as $key => $value) { 118 | $msg .= " php $self $key " . $value['example_branch'] . PHP_EOL; 119 | } 120 | 121 | return $msg; 122 | } 123 | 124 | public function install($package, $version) 125 | { 126 | if (! isset($this->packages[$package])) 127 | { 128 | return 'Error! no such package: ' . $package . PHP_EOL; 129 | } 130 | 131 | // github 132 | if ($this->packages[$package]['site'] === 'github') { 133 | $method = 'downloadFromGithub'; 134 | } elseif ($this->packages[$package]['site'] === 'bitbucket') { 135 | $method = 'downloadFromBitbucket'; 136 | } else { 137 | throw new LogicException( 138 | 'Error! no such repos type: ' . $this->packages[$package]['site'] 139 | ); 140 | } 141 | 142 | list($src, $dst) = $this->$method($package, $version); 143 | 144 | $this->recursiveCopy($src, $dst); 145 | $this->recursiveUnlink($this->tmp_dir); 146 | 147 | $msg = 'Installed: ' . $package .PHP_EOL; 148 | if (isset($this->packages[$package]['msg'])) { 149 | $msg .= $this->packages[$package]['msg'] . PHP_EOL; 150 | } 151 | return $msg; 152 | } 153 | 154 | private function downloadFromGithub($package, $version) 155 | { 156 | $user = $this->packages[$package]['user']; 157 | $repos = $this->packages[$package]['repos']; 158 | $url = "https://github.com/$user/$repos/archive/$version.zip"; 159 | $filepath = $this->download($url); 160 | $this->unzip($filepath); 161 | 162 | $dir = $this->packages[$package]['dir']; 163 | $pre = isset($this->packages[$package]['pre']) ? $this->packages[$package]['pre'] : ''; 164 | 165 | if (is_string($dir)) { 166 | $src = realpath(dirname($filepath) . "/$repos-$version/$pre$dir"); 167 | $dst = realpath(__DIR__ . "/../application/$dir"); 168 | return array($src, $dst); 169 | } 170 | 171 | foreach ($dir as $directory) { 172 | $src[] = realpath(dirname($filepath) . "/$repos-$version/$pre$directory"); 173 | @mkdir(__DIR__ . "/../application/$directory"); 174 | $dst[] = realpath(__DIR__ . "/../application/$directory"); 175 | } 176 | return array($src, $dst); 177 | } 178 | 179 | private function downloadFromBitbucket($package, $version) 180 | { 181 | $user = $this->packages[$package]['user']; 182 | $repos = $this->packages[$package]['repos']; 183 | // https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/get/codeigniter-3.x.zip 184 | $url = "https://bitbucket.org/$user/$repos/get/$version.zip"; 185 | $filepath = $this->download($url); 186 | $dirname = $this->unzip($filepath); 187 | 188 | $dir = $this->packages[$package]['dir']; 189 | 190 | if (is_string($dir)) { 191 | $src = realpath(dirname($filepath) . "/$dirname/$dir"); 192 | $dst = realpath(__DIR__ . "/../application/$dir"); 193 | return array($src, $dst); 194 | } 195 | 196 | foreach ($dir as $directory) { 197 | $src[] = realpath(dirname($filepath) . "/$dirname/$directory"); 198 | @mkdir(__DIR__ . "/../application/$directory"); 199 | $dst[] = realpath(__DIR__ . "/../application/$directory"); 200 | } 201 | return array($src, $dst); 202 | } 203 | 204 | private function download($url) 205 | { 206 | $file = file_get_contents($url); 207 | if ($file === false) { 208 | throw new RuntimeException("Can't download: $url"); 209 | } 210 | echo 'Downloaded: ' . $url . PHP_EOL; 211 | 212 | $urls = parse_url($url); 213 | $filepath = $this->tmp_dir . '/' . basename($urls['path']); 214 | file_put_contents($filepath, $file); 215 | 216 | return $filepath; 217 | } 218 | 219 | private function unzip($filepath) 220 | { 221 | $zip = new ZipArchive(); 222 | if ($zip->open($filepath) === TRUE) { 223 | $tmp = explode('/', $zip->getNameIndex(0)); 224 | $dirname = $tmp[0]; 225 | $zip->extractTo($this->tmp_dir . '/'); 226 | $zip->close(); 227 | } else { 228 | throw new RuntimeException('Failed to unzip: ' . $filepath); 229 | } 230 | 231 | return $dirname; 232 | } 233 | 234 | /** 235 | * Recursive Copy 236 | * 237 | * @param string $src 238 | * @param string $dst 239 | */ 240 | private function recursiveCopy($src, $dst) 241 | { 242 | if ($src === false) { 243 | return; 244 | } 245 | 246 | if (is_array($src)) { 247 | foreach ($src as $key => $source) { 248 | $this->recursiveCopy($source, $dst[$key]); 249 | } 250 | 251 | return; 252 | } 253 | 254 | @mkdir($dst, 0755); 255 | 256 | $iterator = new \RecursiveIteratorIterator( 257 | new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS), 258 | \RecursiveIteratorIterator::SELF_FIRST 259 | ); 260 | 261 | foreach ($iterator as $file) { 262 | if ($file->isDir()) { 263 | @mkdir($dst . '/' . $iterator->getSubPathName()); 264 | } else { 265 | $success = copy($file, $dst . '/' . $iterator->getSubPathName()); 266 | if ($success) { 267 | echo 'copied: ' . $dst . '/' . $iterator->getSubPathName() . PHP_EOL; 268 | } 269 | } 270 | } 271 | } 272 | 273 | /** 274 | * Recursive Unlink 275 | * 276 | * @param string $dir 277 | */ 278 | private function recursiveUnlink($dir) 279 | { 280 | $iterator = new \RecursiveIteratorIterator( 281 | new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS), 282 | \RecursiveIteratorIterator::CHILD_FIRST 283 | ); 284 | 285 | foreach ($iterator as $file) { 286 | if ($file->isDir()) { 287 | rmdir($file); 288 | } else { 289 | unlink($file); 290 | } 291 | } 292 | 293 | rmdir($dir); 294 | } 295 | } 296 | -------------------------------------------------------------------------------- /bin/my-codeigniter.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | cd `dirname $0` 4 | cd .. 5 | 6 | # Install translations 7 | php bin/install.php translations develop 8 | 9 | # Install Roave Security Advisories 10 | composer require roave/security-advisories:dev-master 11 | 12 | # Install CodeIgniter Simple and Secure Twig 13 | composer require kenjis/codeigniter-ss-twig:1.0.x@dev 14 | php vendor/kenjis/codeigniter-ss-twig/install.php 15 | 16 | # Install Codeigniter Matches CLI 17 | php bin/install.php matches-cli master 18 | 19 | # Install Cli for CodeIgniter 20 | composer require kenjis/codeigniter-cli --dev 21 | php vendor/kenjis/codeigniter-cli/install.php 22 | 23 | # Install CI PHPUnit Test 24 | composer require kenjis/ci-phpunit-test --dev 25 | php vendor/kenjis/ci-phpunit-test/install.php 26 | 27 | # Install CodeIgniter Deployer 28 | composer require kenjis/codeigniter-deployer:1.0.x@dev --dev 29 | php vendor/kenjis/codeigniter-deployer/install.php 30 | -------------------------------------------------------------------------------- /bin/router.php: -------------------------------------------------------------------------------- 1 | 6 | * @license MIT License 7 | * @copyright 2015 Kenji Suzuki 8 | * @link https://github.com/kenjis/codeigniter-composer-installer 9 | */ 10 | 11 | /** 12 | * Router script for PHP built-in server 13 | */ 14 | 15 | // See https://bugs.php.net/bug.php?id=67808 16 | $_SERVER = array_merge($_SERVER, $_ENV); 17 | 18 | $file = $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME']; 19 | //echo $file, PHP_EOL; 20 | 21 | if (is_file($file)) { 22 | return false; 23 | } 24 | 25 | $_SERVER['SCRIPT_NAME'] = '/index.php'; 26 | $_SERVER['SCRIPT_FILENAME'] = $_SERVER['DOCUMENT_ROOT'] . '/index.php'; 27 | //echo $_SERVER['SCRIPT_FILENAME'], PHP_EOL; 28 | 29 | chdir($_SERVER['DOCUMENT_ROOT']); 30 | require $_SERVER['SCRIPT_FILENAME']; 31 | -------------------------------------------------------------------------------- /bin/server.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ## Part of CodeIgniter Composer Installer 4 | ## 5 | ## @author Kenji Suzuki 6 | ## @license MIT License 7 | ## @copyright 2015 Kenji Suzuki 8 | ## @link https://github.com/kenjis/codeigniter-composer-installer 9 | 10 | cd `dirname $0`/.. 11 | 12 | ADDR_PORT=${1:-127.0.0.1:8000} 13 | DOC_ROOT=${2:-public} 14 | 15 | php -S "$ADDR_PORT" -t "$DOC_ROOT/" -f bin/router.php 16 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "kenjis/codeigniter-composer-installer", 3 | "description": "Package to install CodeIgniter3 via Composer with secure folder structure.", 4 | "type": "project", 5 | "keywords": [ 6 | "CodeIgniter", 7 | "Composer", 8 | "installer" 9 | ], 10 | "homepage": "https://github.com/kenjis/codeigniter-composer-installer", 11 | "license": "MIT", 12 | "authors": [ 13 | { 14 | "name": "Kenji Suzuki", 15 | "homepage": "https://github.com/kenjis" 16 | } 17 | ], 18 | "require": { 19 | "codeigniter/framework": "3.1.*" 20 | }, 21 | "autoload": { 22 | "psr-4": { 23 | "Kenjis\\CodeIgniter\\": "src/" 24 | } 25 | }, 26 | "scripts" : { 27 | "post-create-project-cmd": [ 28 | "Kenjis\\CodeIgniter\\Installer::postInstall" 29 | ] 30 | }, 31 | "extra": { 32 | "branch-alias": { 33 | "dev-master": "1.0.x-dev" 34 | } 35 | }, 36 | "suggest": { 37 | "kenjis/codeigniter-cli": "A command-line tool for CodeIgniter 3.0", 38 | "kenjis/ci-phpunit-test": "An easier way to use PHPUnit with CodeIgniter 3.0", 39 | "kenjis/codeigniter-ss-twig": "A Simple and Secure Twig integration for CodeIgniter 3.0", 40 | "kenjis/codeigniter-doctrine": "A simple Doctrine integration for CodeIgniter 3.0", 41 | "kenjis/codeigniter-deployer": "A Deployment Tool for CodeIgniter 3.0" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /composer.json.dist: -------------------------------------------------------------------------------- 1 | { 2 | "description" : "The CodeIgniter Application with Composer", 3 | "require": { 4 | "php": ">=5.3.2", 5 | "codeigniter/framework": "3.1.*" 6 | }, 7 | "require-dev": { 8 | "mikey179/vfsstream": "1.1.*" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /dot.htaccess: -------------------------------------------------------------------------------- 1 | # I recommend you remove `IfModule`. Because if you need mod_rewrite, 2 | # you don't need `IfModule`. If you don't need it, you don't need this file 3 | # at all. 4 | 5 | RewriteEngine On 6 | RewriteCond %{REQUEST_FILENAME} !-f 7 | RewriteCond %{REQUEST_FILENAME} !-d 8 | RewriteRule ^(.*)$ index.php/$1 [L] 9 | 10 | -------------------------------------------------------------------------------- /src/Installer.php: -------------------------------------------------------------------------------- 1 | 6 | * @license MIT License 7 | * @copyright 2015 Kenji Suzuki 8 | * @link https://github.com/kenjis/codeigniter-composer-installer 9 | */ 10 | 11 | namespace Kenjis\CodeIgniter; 12 | 13 | use Composer\Script\Event; 14 | 15 | class Installer 16 | { 17 | const DOCROOT = 'public'; 18 | 19 | /** 20 | * Composer post install script 21 | * 22 | * @param Event $event 23 | */ 24 | public static function postInstall(Event $event = null) 25 | { 26 | // Copy CodeIgniter files 27 | self::recursiveCopy('vendor/codeigniter/framework/application', 'application'); 28 | mkdir(static::DOCROOT, 0755); 29 | copy('vendor/codeigniter/framework/index.php', static::DOCROOT . '/index.php'); 30 | copy('dot.htaccess', static::DOCROOT . '/.htaccess'); 31 | copy('vendor/codeigniter/framework/.gitignore', '.gitignore'); 32 | 33 | // Fix paths in index.php 34 | $file = static::DOCROOT . '/index.php'; 35 | $contents = file_get_contents($file); 36 | $contents = str_replace( 37 | '$system_path = \'system\';', 38 | '$system_path = \'../vendor/codeigniter/framework/system\';', 39 | $contents 40 | ); 41 | $contents = str_replace( 42 | '$application_folder = \'application\';', 43 | '$application_folder = \'../application\';', 44 | $contents 45 | ); 46 | file_put_contents($file, $contents); 47 | 48 | // Enable Composer Autoloader 49 | $file = 'application/config/config.php'; 50 | $contents = file_get_contents($file); 51 | $contents = str_replace( 52 | '$config[\'composer_autoload\'] = FALSE;', 53 | '$config[\'composer_autoload\'] = realpath(APPPATH . \'../vendor/autoload.php\');', 54 | $contents 55 | ); 56 | 57 | // Set 'index_page' blank 58 | $contents = str_replace( 59 | '$config[\'index_page\'] = \'index.php\';', 60 | '$config[\'index_page\'] = \'\';', 61 | $contents 62 | ); 63 | file_put_contents($file, $contents); 64 | 65 | // Update composer.json 66 | copy('composer.json.dist', 'composer.json'); 67 | 68 | // Run composer update 69 | self::composerUpdate(); 70 | 71 | // Show message 72 | self::showMessage($event); 73 | 74 | // Delete unneeded files 75 | self::deleteSelf(); 76 | } 77 | 78 | private static function composerUpdate() 79 | { 80 | passthru('composer update'); 81 | } 82 | 83 | /** 84 | * Composer post install script 85 | * 86 | * @param Event $event 87 | */ 88 | private static function showMessage(Event $event = null) 89 | { 90 | $io = $event->getIO(); 91 | $io->write('=================================================='); 92 | $io->write( 93 | '`public/.htaccess` was installed. If you don\'t need it, please remove it.' 94 | ); 95 | $io->write( 96 | 'If you want to install translations for system messages or some third party libraries,' 97 | ); 98 | $io->write('$ cd '); 99 | $io->write('$ php bin/install.php'); 100 | $io->write('The above command will show help message.'); 101 | $io->write('See for details'); 102 | $io->write('=================================================='); 103 | } 104 | 105 | private static function deleteSelf() 106 | { 107 | unlink(__FILE__); 108 | rmdir('src'); 109 | unlink('composer.json.dist'); 110 | unlink('dot.htaccess'); 111 | unlink('LICENSE.md'); 112 | } 113 | 114 | /** 115 | * Recursive Copy 116 | * 117 | * @param string $src 118 | * @param string $dst 119 | */ 120 | private static function recursiveCopy($src, $dst) 121 | { 122 | mkdir($dst, 0755); 123 | 124 | $iterator = new \RecursiveIteratorIterator( 125 | new \RecursiveDirectoryIterator($src, \RecursiveDirectoryIterator::SKIP_DOTS), 126 | \RecursiveIteratorIterator::SELF_FIRST 127 | ); 128 | 129 | foreach ($iterator as $file) { 130 | if ($file->isDir()) { 131 | mkdir($dst . '/' . $iterator->getSubPathName()); 132 | } else { 133 | copy($file, $dst . '/' . $iterator->getSubPathName()); 134 | } 135 | } 136 | } 137 | } 138 | --------------------------------------------------------------------------------