carrooi/contactable
Composer 安装命令:
composer require carrooi/contactable
包简介
Contactable module for Nette framework and Doctrine
README 文档
README
Contactable module for Nette framework and Doctrine.
Installation
$ composer require carrooi/contactable
$ composer update
Configuration
extensions: contactable: Carrooi\Contactable\DI\ContactableExtension contactable: contactItemClass: App\Model\Entities\ContactItem associations: App\Model\Entities\User: user
- contactItemClass: entity with associations between contact types and eg. user entity
- associations: list of contactable entities with field names which are manyToOne associations in
contactItemClass
Contactable entity
Entity which implements Carrooi\Contactable\Model\Entities\IContactableEntity interface with these methods:
getId(): returns identifiergetContacts(): returns array ofCarrooi\Contactable\Model\Entities\IContactItementitiesaddContact(): adds newCarrooi\Contactable\Model\Entities\IContactItementity to collectionremoveContact(): removesCarrooi\Contactable\Model\Entities\IContactItementity from collection
Of course you don't need to implement all required methods on your own (except for getId() method). Just use prepared trait Carrooi\Contactable\Model\Entities\TContactable.
namespace App\Model\Entities; use Carrooi\Contactable\Model\Entities\IContactableEntity; use Carrooi\Contactable\Model\Entities\TContactable; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @author David Kudera */ class User implements IContactableEntity { use TContactable; // ... /** * @return int */ public function getId() { return $this->id; } }
Contact item entity
Entity which holds the actual value of contact, eg. actual email address of user. This entity must implement Carrooi\Contactable\Model\Entities\IContactItem interface with these methods:
getId(): returns identifiergetContactType()returnsCarrooi\Contactable\Model\Entities\IContactTypeentitysetContactType()setsCarrooi\Contactable\Model\Entities\IContactTypeentitygetValue(): returns value of contactsetValue(): sets value of contactvalidateValue()validate value against pattern in contact type
Again, you can use prepared trait Carrooi\Contactable\Model\Entities\TContactItem.
namespace App\Model\Entities; use Carrooi\Contactable\Model\Entities\IContactItem; use Carrooi\Contactable\Model\Entities\TContactItem; use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity * @author David Kudera */ class ContactItem implements IContactItem { use TContactItem; /** * @ORM\Id * @ORM\Column(type="integer") * @var int */ private $id; /** * @ORM\ManyToOne(targetEntity="\App\Model\Entities\User") * @var \App\Model\Entities\User */ private $user; // ... some getters and setters for all fields }
As you can see, we've got user field which corresponding with associations setup in your configuration.
Contact types
You can create as many types as you want, eg. mails, facebook, phone numbers etc.
There is already prepared service for that: Carrooi\Contactable\Model\Facades\ContactTypesFacade.
Create contact type:
$type = $types->create('mail', 'Email', [ 'pattern' => '[a-z]+@[a-z]+\.[a-z]{2,3}', // really naive mail regex 'url' => 'mail.org', ]);
arguments:
name: required "system" nametitle: required "public" namevalues:- not required list of other values
pattern: not required pattern for all contact values of this typeurl: not required url to contact
Update contact type:
$types->update($type, [ 'name' => 'email', 'title' => 'Email address', 'pattern' => '.+', // no more naive, just stupid 'url' => 'mail.com', ]);
Remove contact type:
$types->remove($type);
Get all contact types:
foreach ($types->findAll() as $type) { // ... }
Get id => names pairs:
foreach ($types->findAllNames() as $id => $name) { // ... }
Find contact type by id:
$type = $types->findOneById($id);
Find contact type by name:
$type = $types->findOneByName($name);
Contact items facade
There is also service Carrooi\Contactable\Model\Facades\ContactItemsFacade which can be used for adding contacts to contactable entities.
Add contact:
$item = $items->addContact($user, $type, 'lorem@ipsum.com');
Update contact:
$items->update($item, [ 'contactType' => $anotherType, 'value' => '999888777', ]);
Remove contact:
$items->remove($item);
Find by id:
$item = $items->findOneById($id);
Find all by entity:
foreach ($items->findAllByEntity($user) as $item) { // ... }
Changelog
- 1.0.0
- Initial version
carrooi/contactable 适用场景与选型建议
carrooi/contactable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 02 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「nette」 「contacts」 「carrooi」 「contactable」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 carrooi/contactable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 carrooi/contactable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 carrooi/contactable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-12