anned20 / strix
遵循PSR11标准的现代PHP应用的极简容器
v1.0.2
2017-10-02 15:42 UTC
Requires
- php: >= 5.5.0
- psr/container: ^1.0
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is not auto-updated.
Last update: 2024-09-25 02:08:16 UTC
README
Strix
遵循PSR-11标准的现代PHP应用的极简容器
安装
composer require anned20/strix
使用
<?php require __DIR__.'/vendor/autoload.php'; use anned20\Strix\Container; use anned20\Strix\Exception\AlreadyInContainerException; use anned20\Strix\Exception\NotFoundException; // Create new container $container = new Container(); // Use the container for variables $container->add('config', ['hello' => 'world']); // Use the container for closures $container->add('function', function () { return rand(); }); // Let's use the config $hello = $container->get('config')['hello']; // And the function $rand = $container->get('function')(); // Factories can be made too! $container->add('factory', function () { return new SomeClass(); }); // Just like services $myService = new SomeClass(); $container->add('service', $myService); // Whoops! $container->add('config', ['foo' => 'bar']); // AlreadyInContainerException thrown // Let's check before adding if (!$container->has('config')) { $container->add('config', ['foo' => 'bar']); } // But I want to overwrite the old one! No problem! if ($container->has('config')) { $container->delete('config'); } $container->add('config', ['foo' => 'bar']); // Whoops! $bye = $container->get('bye'); // NotFoundException thrown
贡献
- Fork它!
- 创建你的功能分支:
git checkout -b my-new-feature - 提交你的更改:
git commit -am '添加一些功能' - 推送到分支:
git push origin my-new-feature - 提交拉取请求 :D
许可证
Strix是一个符合PSR-11规范的容器
版权所有 © 2017 Anne Douwe Bouma
特此授予任何人,免费且无限制地获得本软件及其相关文档文件(“软件”)的副本(“软件”),在软件上不受限制地处理,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或出售软件的副本,并允许向软件提供副本的个人这样做,前提是遵守以下条件
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
软件按“原样”提供,没有任何形式的保证,明示或暗示,包括但不限于适销性、特定用途适用性和非侵权性保证。在任何情况下,作者或版权所有者不对任何索赔、损害或其他责任负责,无论是在合同、侵权或其他行为中产生的,是否与软件或其使用或其他方式有关。