Is there any code example? Here's what I got:
// index.php
require_once __DIR__ . '/Klein/Klein.php';
$klein = new \Klein\Klein();
$klein->respond(function () {
return 'All the things';
});
On PHP 5.3 this returns an error (Fatal error: Class 'Klein\ServiceProvider' not found in).
Okay, I got some code together that seems to work. Can't say I recommend it, but it loads Klein without errors, at least for now.
<?php
function include_dir($path) {
if(is_dir($path)) {
foreach (glob($path.'*') as $filename) {
if(is_file($filename) && pathinfo($filename, PATHINFO_EXTENSION) == 'php') {
require_once $filename;
} elseif(is_dir($filename)) {
include_dir($filename.'/');
}
}
}
}
require_once __DIR__ . '/Klein/Exceptions/KleinExceptionInterface.php';
require_once __DIR__ . '/Klein/Exceptions/HttpExceptionInterface.php';
include_dir(__DIR__ . '/Klein/');
$klein = new \Klein\Klein();
$klein->respond(function () {
return 'All the things';
});
I started with a little loop on the Klein source directory, I picked up from here: https://stackoverflow.com/a/599694/1004008
However, the code has internal dependencies which expect to be fulfilled by an autoloader. Those files will be included by the loop thing up there, but not in the order desired. So I manually included the two exception interfaces above, before running the loop. It's a little brittle, because the dev could rearrange those dependencies at any time, but it does work.
The more correct answer would be to use an autoloader. I'm not sure why you don't like Composer's autoloader, but it's pretty nifty and easy to use. The autoload stuff is cached, so it doesn't really impact performance. You can use the autoloader independent of the package manager. Composer doesn't dictate your project structure much , other than placing the composer.json and vendors/ directory in the project root. Meanwhile, you can automatically install all sorts of PHP libraries with Composer, lock the version down, or grab updates. It's a nice tool. If you have shared hosting, you can run Composer on your project locally, and then upload the results. Sorry, I'm sure you have your reasons, it's just that Composer is quite possibly the coolest thing to happen in PHP-land in many years.
But if you don't like Composer, or can't use it because of some external constraint, there are other PSR-0/PSR-4 autoloaders:
https://gist.github.com/jwage/221634
https://stackoverflow.com/a/12836587/1004008
Or you can roll your own: http://zaemis.blogspot.fr/2012/05/writing-minimal-psr-0-autoloader.html
Looks like it's only a few lines of code.
Failing that, yeah, I'd probably look for another routing library. Maybe try GluePHP?
It's a single file, with pretty much zero dependencies. You don't get the trendy Sinatra-style closure-based routing. Instead you create a very simple class for each route. Not sure if that's negotiable for you. But it is small and self-contained.
Slim Framework might be an option as well:
They offer Composer and non-Composer installation methods. The non-Composer method uses its own autoloader. Not a bad approach, but I'm not sure if meets your criteria.