Lens

autoload.php

If you’re using Composer to manage your dependencies, then you don’t need this “autoload.php” file. Lens will use your Composer autoloader automatically.

If you’re not using Composer, or if you’d like a faster autoloader, then go ahead and create this file in your Lens directory. Lens will use the custom “autoload.php” file that you create.

Here’s an example:

autoload.php
<?php

call_user_func(function () {
	$projectDirectory = dirname(__DIR__);

	$classes = array(
		'Example' => "{$projectDirectory}/src"
	);

	foreach ($classes as $namespacePrefix => $libraryPath) {
		$namespacePrefix .= '\\';
		$namespacePrefixLength = strlen($namespacePrefix);

		$autoloader = function ($class) use ($namespacePrefix, $namespacePrefixLength, $libraryPath) {
			if (strncmp($class, $namespacePrefix, $namespacePrefixLength) !== 0) {
				return;
			}

			$relativeClassName = substr($class, $namespacePrefixLength);
			$relativeFilePath = strtr($relativeClassName, '\\', '/') . '.php';
			$absoluteFilePath = "{$libraryPath}/{$relativeFilePath}";

			if (is_file($absoluteFilePath)) {
				include $absoluteFilePath;
			}
		};

		spl_autoload_register($autoloader);
	}
});

Your “settings.ini” file will show you which autoloader Lens is using, and you can modify the “autoload” path there.