定制 scylabs/hook-bundle 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

scylabs/hook-bundle

最新稳定版本:1.0.6

Composer 安装命令:

composer require scylabs/hook-bundle

包简介

Templates and fonctionnal Hooks for symfony

README 文档

README

Dynamic templating hook system for symfony.

Installation

To install this package, use composer .

composer require scylabs/hook-bundle

Usage

The operation is very simple. First, you need to create entry points in your template, then connect PHP classes to these entry points.
I will explain in detail.

Create an entry point to connect hooks in twig

Okay , for the rest of the tutorial, we will say that the "entry point" is a door.
You can use the TwigExtension provided in this package.
The extension function has two parameters.

public function showHook(string $template,string $hookName)

The first parameter is the target template NameSpace. Ex : layout.html.twig
The second parameter is the hook name and it is used to connect PHP classes in this door.

You can send _self in first parameter. _self is the current template NameSpace
It is important to add "raw" filter to interprete Hook's html.

{{ showHook(_self,'my_custom_hook')) | raw }}

You don't use twig ?

If you don't use twig , you can tell directly HooksFounder Service.
It works exactly like the extension, except that it directly returns an array of instantiated Hooks objects instead of hooks contents.

Connect Hooks to an entry point (door).

You can create an infinity of doors and an infinity of hooks to connect this doors.
To connect a hook to one door , you need to create a PHP class that extends AbstractHook class
I'ts the minimal code to connect a hook to a door. PS : You can connect one hook to many doors.

<?php

namespace App\Hook;


use ScyLabs\HookBundle\Model\AbstractHook;

class MyHook extends AbstractHook
{

    // name of the doors where the hook will be injected
    public function getNames(): array {
        return [
            'my_custom_hook'
        ];
    }

    // A priority 0 hook will be placed before a priority 1 hook
    public function getPriority(): int {
        return 0;
    }

    // Hook result. The result are injected in door template. You can also do anything you sant in this function.
    public function showHook() {
        // $this->render() controller function equivalent.
        return $this->render('hook/menu.html.twig',[]);
    }
}

Last step : Add your Hook directory to the Container

# config/services.yaml
services: 
    App\Hook\:
        resource: '../src/Hook/*'
        public: true

I'ts done.

You can also show any hooks in your controller result in your SymfonyToolbar.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

统计信息

  • 总下载量: 3.83k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 7
  • 点击次数: 2
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-02-18

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固