20160915

How to require autoload in vendor or outside vendor folder

Sometimes when you create a package for composer and want to create some example code you need to execute those examples as an standalone package or once included in a vendor folder of another project.

Use this simple trick in your example php files to require autoload in any location.

$autoload_location=__DIR__.'/../vendor/autoload.php';
if (!is_file($autoload_location)) $autoload_location='../../../autoload.php';
require_once $autoload_location;