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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 geniv/nette-general-form 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A block that displays featured content - large image, title, description and link.
TYPO3 CMS extension to create gallery content element with preset crop ratios and pagination
Symfony bundle for broadway/broadway.
Nette Framework adapter for I18n package
Build forms from schema
Asynchronous MQTT client built on React
统计信息
- 总下载量: 25.34k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 27
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-02-13