dluwang / navigator
导航管理服务
v1.3.1
2019-04-12 01:58 UTC
Requires
- tightenco/collect: 5.8.*
Requires (Dev)
- fzaninotto/faker: ^1.7
- kastengel/packdev: 1.3.*
- mockery/mockery: ^1.2
- phpunit/phpunit: ^7
README
这是一个提供导航管理服务的包
注意
安装
composer require dluwang/navigation
用法
定义导航
Dluwang/Navigator/Navigation
是一个定义导航的类。构造函数有两个必填参数和四个可选参数
public function __construct($id, $url, $order = 1, $parent = null, array $attributes = [], array $childs = [])
-
$id
是导航的 ID -
$url
是导航的 URL -
$order
是排序导航的数字 -
$parent
是导航的父级 -
$attributes
是导航的附加属性 -
$childs
是导航的子项
以上所有属性都可以通过对象实例访问。
注册子项
注册导航子项有两种方式。
- 急切子项注册
$navigation->registerChild($childNavigation) // single child registration` $navigation->registerChild([$childNavigation2, $childNavigation2]) // multiple childs registration
- 延迟子项注册
有时你想要挂钩导航并在你的应用程序中的某个位置注册子项。你只需指定带有你想要挂钩的 navigation-id
的父级参数。
$navigation = new Navigation('navigation-id', 'the-url', 'the-order', 'the-parent-navigation-id');
检索所有子项
$navigation->childs()
通过 ID 检索子项
$navigation->child('navigation-id-wanted')
定义导航器
Dluwang/Navigator/BaseNavigator
是一个作为导航存储库的类。所有导航实现都应该实现 Dluwang/Navigator/Navigator
接口。
$navigator = new BaseNavigator()
构造函数有一个可选参数,即你想要注册的导航。
注册导航
$navigator->register($navigation) // single navigation registration
$navigator->register([$navigation1, $navigation2]) // mutiple navigations
如上所述,延迟子项可以随意注册到导航器。
检索原始已注册导航
此包在底层进行一些数据处理,如排序和收集延迟子项。要获取原始数据,可以使用。
$navigator->raw();
要指定父级,使用
$navigator->raw('parent-id');
要获取准备好的数据,可以使用以下方法。
检索所有导航
$navigator->navigations()
你可以指定通过父级加载的导航。
$navigator->navigations('parent-id');
通过 ID 检索导航
$navigator->navigation('navigation-id')
集成
目前,此包仅与 laravel 框架 集成。你可以在应用程序的服务提供器的 boot 方法中注册你定义的导航。此集成在构建导航时添加了缓存机制
public function boot() { // define navigation $navigation = ... $this->app->navigator->register($navigation); }
测试
要运行测试,请运行以下命令
vendor/bin/phpunit