在没有编写器的情况下使用klein.php?
有代码示例吗?以下是我得到的:在没有编写器的情况下使用klein.php?,php,routing,klein-mvc,Php,Routing,Klein Mvc,有代码示例吗?以下是我得到的: // index.php require_once __DIR__ . '/Klein/Klein.php'; $klein = new \Klein\Klein(); $klein->respond(function () { return 'All the things'; }); 在PHP5.3上,这将返回一个错误(致命错误:在中找不到类“Klein\ServiceProvider”)。如果不想使用composer加载,可能需要查看另一
// index.php
require_once __DIR__ . '/Klein/Klein.php';
$klein = new \Klein\Klein();
$klein->respond(function () {
return 'All the things';
});
在PHP5.3上,这将返回一个错误(致命错误:在中找不到类“Klein\ServiceProvider”)。如果不想使用composer加载,可能需要查看另一个库 我目前正在开发一个php路由器,其目标是实现极高的性能。没有额外的依赖。您可能想看看: 供参考: Pux在静态路由调度方面比symfony路由器快48.5倍, 正则表达式调度速度提高31倍。(带pux扩展) (已安装) Pux尝试不消耗计算时间来构建所有路由 动态(如Symfony/路由)。相反,Pux编译您的路由 为了使PHP数组简单化以进行缓存,可以从 缓存非常快 通过Pux-PHP扩展支持,您可以加载和分派路由 比纯PHP Pux快1.5~2倍
好的,我找到了一些代码,看起来很有效。不能说我推荐它,但它加载Klein时没有错误,至少现在是这样
<?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';
});
遇到了另一个自动加载生成器,您可以使用它来实现无需编写器的自动加载: