Welcome Guest, Not a member yet? Register   Sign In
Best way to integrate composer with CodeIgniter 3.0
#3

[eluser]ivantcholakov[/eluser]
Since you start using Composer, here is what I can recommend. Forget for now about CodeIgniter as a Composer package. It won't happen soon, or maybe it would never happen.

Using Composer will require at least PHP 5.3.2, probably it is not a problem for you. Let me show an example how this could be done in CodeIgniter:

0. Install Composer on your dev computer, find their installation instructions.
1. You can download CodeIgniter 3 dev and install it on your dev computer. After you see the "welcome" page within the browser, create the folder application/vendor/
2. Open application/config/config.php, find the setting $config['composer_autoload']. Set it to TRUE.
3. Create the file application/composer.json with some simple content, for example, require some package:
Code:
{
    "require": {
        "fg/multiplayer": "1.1.0"
    }
}

4. Open the terminal and with cd commands go to the folder application/ (let it be the current terminal folder). Type the command composer install (or php composer.phar install , it depends on how you installed Composer). After that you will see that the directory application/vendor/ is no longer empty, and you have got one package installed.

Next, there are some optional things to be done. I very often see that developers use component APIs directly, this may be not very convenient. It would be better if some class with its interface to be placed between the component and your application. Then you can switch to other component in the future, to make some hacks, and to use more convenient API for your taste. So...

5. Make a CodeIgniter library that exploits the installer component - within application/libraries/ make the file Multiplayer.php with the following content:

Code:
<?php defined('BASEPATH') OR exit('No direct script access allowed.');

/**
* @author Ivan Tcholakov <[email protected]>, 2014
* @license The MIT License, http://opensource.org/licenses/MIT
*/

class Multiplayer extends \Multiplayer\Multiplayer {

    public function __construct($config = array()) {

        if (!is_array($config)) {
            $config = array();
        }

        parent::__construct($config);
    }

}

The \Multiplayer\Multiplayer class can be used as a singleton (this a case by coincidence) and our library does that. We can inject configuration options to it once. Here is how:

6. Under the directory application/config/ create the file multiplayer.php with the following content:

Code:
&lt;?php defined('BASEPATH') OR exit('No direct script access allowed');

/**
* @author Ivan Tcholakov <[email protected]>, 2014
* @license The MIT License, http://opensource.org/licenses/MIT
*/

$config['vbox7'] = array(
    'id' => '#vbox7\.com/play\:(?<id>[a-z0-9_-]+)#i',
    'url' => 'http://vbox7.com/emb/external.php?vid=%s',
    'map' => array(),
);

\Multiplayer\Multiplayer component supports only 3 video sources, by this configuration file I am adding one more. By using the configuration file I am extending a component's feature.

7. Testing all this: Within the welcome page view, place this code for testing:

Code:
$this->load->library('multiplayer);
echo $this->multiplayer->html('https://www.youtube.com/watch?v=NRhVcTTMlrM');

Reload the welcome page in the browser. You should see a video player. This is it.

If you commit your project within a version control system (Git, Mercurial, SVN, ...), among other things, commit the whole folder application/vendor/, your file application/composer.json and the file application/composer.lock (Created by Composer).


Messages In This Thread
Best way to integrate composer with CodeIgniter 3.0 - by El Forum - 09-21-2014, 10:18 AM
Best way to integrate composer with CodeIgniter 3.0 - by El Forum - 09-21-2014, 12:47 PM
Best way to integrate composer with CodeIgniter 3.0 - by El Forum - 09-21-2014, 02:18 PM
Best way to integrate composer with CodeIgniter 3.0 - by El Forum - 09-22-2014, 02:59 AM
Best way to integrate composer with CodeIgniter 3.0 - by El Forum - 09-22-2014, 05:27 AM
Best way to integrate composer with CodeIgniter 3.0 - by El Forum - 09-22-2014, 11:31 AM



Theme © iAndrew 2016 - Forum software by © MyBB