2017 © Pedro Peláez
 

library autotune

Tune your autoloader

image

linkorb/autotune

Tune your autoloader

  • Monday, February 1, 2016
  • by joostfaassen
  • Repository
  • 3 Watchers
  • 5 Stars
  • 1,194 Installations
  • PHP
  • 13 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 6 % Grown

The README.md

AutoTune for Composer

, (*1)

Why use AutoTune for Composer?

AutoTune is great for library developers., (*2)

Often you're working on a library and the calling application at the same time., (*3)

Before AutoTune there were 2 things you could do to test your library in your application:, (*4)

  1. Commit new version of the library for all changes, wait for packagist to re-index, and update your composer.lock in the calling application and test.
  2. Add a "repository" to your calling application's composer.json (which you shouldn't forget to remove during commit, and put back after)

Both are cumbersome. This is where AutoTune comes in!, (*5)

How does autotune work?

AutoTune expects to find a autotune.json in your calling application's path, next to composer.json. Here's an example:, (*6)

{
    "autoload": {
        "psr-4": {
            "Monolog\\": "~/git/monolog/monolog/src/Monolog"
        }
    }
}

If this file is found, it will read the contents, and override any psr-0 or psr-4 namespaces with the local version as defined in your autotune.json file., (*7)

You can add the autotune.json to your .gitignore file, so that you can keep your code directory clean and in sync with the remote repository., (*8)

Making your own application ready for AutoTune

Making your own application ready for AutoTune takes 3 simple steps:, (*9)

1. Include linkorb/autotune from Packagist in your composer.json file

require-dev": {
   "linkorb/autotune": "~1.0"
}

Then run composer update, (*10)

2. Initialize AutoTune in your app

Somewhere in your application, you're including vendor/autoload.php. Sometimes it's in web/index.php or bin/console. Find this location, and modify add these lines:, (*11)

$loader = require_once __DIR__.'/../vendor/autoload.php';
if (class_exists('AutoTune\Tuner')) {
    \AutoTune\Tuner::init($loader);
}

Wrapping the call to init in the class_exists block ensures autotune is only used if AutoTune is installed in your (development) environment (installed from the require-dev block in composer.json). In production environments it won't be called if you install your dependencies with --no-dev), (*12)

3. Add an autotune.json file to your project root.

Example content:, (*13)

{
    "autoload": {
        "psr-4": {
            "Monolog\\": "~/git/monolog/monolog/src/Monolog"
        }
    }
}

Ideally you'd add the autotune.json to your .gitignore file., (*14)

Done

Whenever your application is doing something like the following, it will load the "local" version of a library, instead of the one in your vendor/ directory., (*15)

$logger = new \Monolog\Logger('example');

So from now on, no changes are required to your main application. Everything is managed by your local autotune.json file., (*16)

License

MIT (see LICENSE.md), (*17)

Brought to you by the LinkORB Engineering team


Check out our other projects at linkorb.com/engineering., (*18)

Btw, we're hiring!, (*19)

The Versions

01/02 2016

dev-master

9999999-dev https://github.com/linkorb/autotune

Tune your autoloader

  Sources   Download

MIT

The Development Requires

composer packagist autoloader autoload tune

01/02 2016

v1.2.0

1.2.0.0 https://github.com/linkorb/autotune

Tune your autoloader

  Sources   Download

MIT

The Development Requires

composer packagist autoloader autoload tune

24/01 2016

v1.1.0

1.1.0.0 https://github.com/linkorb/autotune

Tune your autoloader

  Sources   Download

MIT

The Development Requires

composer packagist autoloader autoload tune

17/01 2016

v1.0.1

1.0.1.0 https://github.com/linkorb/autotune

Tune your autoloader

  Sources   Download

MIT

The Development Requires

composer packagist autoloader autoload tune