oscarotero / fol
构建网站的基 App 类
v1.0.1
2021-12-16 17:50 UTC
Requires
- php: ^7.2|^8.0
- container-interop/service-provider: ^0.4.0
- psr/container: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- laminas/laminas-diactoros: ^2.8
- phpunit/phpunit: ^8.0
README
这是一个简单的类,包含一些用于构建网站的实用工具,具有以下特性:
路径和 URI
使用来自 PSR-7 的 UriInterface
管理应用路径和公开 URI
use Fol\App; use Zend\Diactoros\Uri; $path = '/var/www/my-website'; $uri = new Uri('http://localhost/my-website'); $app = new App($path, $uri); //Get the path $app->getPath(); // /var/www/my-website $app->getPath('dir/subdir', '../other'); // /var/www/my-website/dir/other //Get the uri (string) $app->getUri(); // http://localhost/my-website (string) $app->getUri('post/1', 'details'); // http://localhost/my-website/post/1/details
PSR-11
它与 PSR-11 和 container-interop/service-provider 兼容,并允许嵌套其他容器
use Fol\App; use Zend\Diactoros\Uri; $app = new App(__DIR__, new Uri('http://localhost/my-website')); //Set a value $app->set('database.config', [ 'user' => 'foo', 'pass' => 'bar' ]); //Get the value $config = $app->get('database.config'); //Set a service $app->addService('database', function ($app) { return new DatabaseClass($app->get('database.config')); }); //Get the service value $database = $app->get('database'); //And add ServiceProviderInterface instances to register several dependencies $app->addServiceProvider(new MyServiceProvider());
有关最近更改的更多信息,请参阅 CHANGELOG
MIT 许可证 (MIT)。有关更多信息,请参阅 LICENSE