定制 geniv/nette-general-form 二次开发

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

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

geniv/nette-general-form

Composer 安装命令:

composer require geniv/nette-general-form

包简介

Form general class for Nette Framework

README 文档

README

Installation

$ composer require geniv/nette-general-form

or

"geniv/nette-general-form": "^1.1"

require:

"php": ">=7.0",
"nette/application": ">=2.4",
"nette/component-model": ">=2.3",
"nette/di": ">=2.4",
"nette/mail": ">=2.4",
"nette/utils": ">=2.4",
"tracy/tracy": ">=2.4"

Include in application

usage IEvent:

class MyEvent implements IEvent

...

public function update(IEventContainer $eventContainer, array $values)

// usage method by IEventContainer
...
$eventContainer->getForm()
$eventContainer->addValues($values)
$eventContainer->setValues($values)
$eventContainer->removeValue($key)
$eventContainer->getComponent()
$eventContainer->getEventIndex()
$eventContainer->getEvents()

usage IFormContainer and IEventContainer (can use magic __invoke method):

private $formContainer;
private $eventContainer;
public $onSuccess, $onException;

public function __construct(IFormContainer $formContainer, array $events)

...

// $this->eventContainer = EventContainer::factory($this, $events, 'onSuccess', 'onException');
$this->eventContainer = EventContainer::factory($this, $events);
$this->formContainer = $formContainer;

...

$form->onSuccess[] = $this->eventContainer;

or the old way without __invoke:

try {
    $this->notify($form, $values);
    $this->onSuccess($values);
} catch (EventException $e) {
    $this->onException($e);
}

usage ITemplatePath (without return type!):

class MyForm extends Control implements ITemplatePath

...

public function setTemplatePath(string $path)
{
    $this->templatePath = $path;
}

Events for use (implements IEvent)

- DumpEvent
- FireLogEvent
- ClearFormEvent
- SetValueEvent     (setValues(array))
- CallbackEvent     (onCallback(IEventContainer, array))
- EmailNotifyEvent  (getMessage(), setTemplatePath(string))

SetValueEvent

- SetValueEvent([active: false, role: guest])

CallbackEvent

- CallbackEvent

usage in presenter:

$callbackEvent->onCallback[] = function (IEventContainer $eventContainer, array $value) {
    if ($this->identityModel->existLogin($value['login'])) {
        throw new EventException('duplicate login');
    }

    if ($this->identityModel->existEmail($value['email'])) {
        throw new EventException('duplicate email');
    }
};

EmailNotifyEvent

admin: Identity\Events\RegistrationEmailNotifyEvent     # email for admin
user: Identity\Events\RegistrationEmailNotifyEvent      # email for user
# or
- Identity\Events\ForgottenEmailNotifyEvent

where self class name (prevents multiple services in DI):

class RegistrationEmailNotifyEvent extends EmailNotifyEvent {}
class ForgottenEmailNotifyEvent extends EmailNotifyEvent {}

usage in presenter:

$emailNotifyEvent->onConfigure[] = function (IEventContainer $eventContainer, array $value) use ($emailNotifyEvent) {
    $emailNotifyEvent->setTemplatePath(__DIR__ . '/templates/Forgotten/emailFormForgotten.latte');

    $message = $emailNotifyEvent->getMessage();
    $message->setFrom('info@email.cz');

    $message->setSubject('informacni email pro uzivatele');
    $message->addTo($value['email']);
};

// or

$emailNotifyEvent->onConfigure[] = function (IEventContainer $eventContainer, array $value) use ($emailNotifyEvent) {
    $message = $emailNotifyEvent->getMessage();
    $message->setFrom('info@email.cz');

    switch ($eventContainer->getEventIndex()) {
        case 'user':
            $emailNotifyEvent->setTemplatePath(__DIR__ . '/templates/Registration/emailFormUser.latte');

            $message->setSubject('informacni email pro uzivatele');
            $message->addTo($value['email']);
            break;

        case 'admin':
            $emailNotifyEvent->setTemplatePath(__DIR__ . '/templates/Registration/emailFormAdmin.latte');

            $message->setSubject('informacni email pro admina');
            $message->addTo('email@email.com');
            break;
    }
};

event in definition is possible use several times, and define like anonymous index or text index

events:
    - DumpEvent
    - DumpEvent
    fire1: FireLogEvent
    fire2: FireLogEvent

Extension

usage GeneralForm:

$formContainer = GeneralForm::getDefinitionFormContainer($this);
$events = GeneralForm::getDefinitionEventContainer($this);

usage GeneralControl:

class MyForm extends GeneralControl {

    public function __construct(IFormContainer $formContainer, array $events, ITranslator $translator = null)
    {
        parent::__construct($formContainer, $events, $translator);

        $this->templatePath = __DIR__ . '/MyPath.latte';    // set path
    }
}

Exception

class: EventException

geniv/nette-general-form 适用场景与选型建议

geniv/nette-general-form 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25.34k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 02 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「event」 「nette」 「content」 「geniv」 「eventContainer」 「formContainer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 geniv/nette-general-form 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 geniv/nette-general-form 我们能提供哪些服务?
定制开发 / 二次开发

基于 geniv/nette-general-form 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-02-13