承接 constpb/amo-placeholder 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

constpb/amo-placeholder

最新稳定版本:1.0.0

Composer 安装命令:

composer require constpb/amo-placeholder

包简介

The library is designed for working with placeholders of custom fields of AmoCRM entity models, needed to make dynamic message text

README 文档

README

Main purpose of this lib is to provide functionality of creating text messages for client mailing, depending on given AmoCRM entity models.

Amo model supported

  • LeadModel
  • ContactModel

How to use

Localization

Before use set necessary localization (at now supported only en and ru).

LocaleService::setLocale('ru');

Basic usage

$this->typeFactory = new CommonTypeFactory(); // creates inner representation of AmoCRM custom fields

$this->handlerFactory = new HandlerFactory($this->logger); // creates handler decides placeholder of given custom field looks like
$this->placeholderFactory = new PlaceholderFactory(); // creates placeholder of given custom field representing entity (like 'Lead') and name (like 'Name of lead')

$this->placeholderBuilder = new CommonPlaceholderBuilder($this->logger, $this->handlerFactory, $this->placeholderFactory); // creates an array of placeholders strings of given entity type

$this->customFieldMapper = new CustomFieldMapper($this->logger); // creates an inner representation of AmoCRM custom fields from Amocrm custom field model
$this->entityMapperFactory = new CommonEntityMapperFactory( $this->typeFactory, $this->logger); // creates an inner representation of AmoCRM entity from Amocrm entity model
$this->replacer = new CommonReplacer($this->logger, $this->handlerFactory, $this->placeholderFactory); // creates an array with placeholders values as key and model values as values

/**
 * parses given string template with placeholders and substitutes given model values
 */
$this->templateProcessor = new MessageTemplateProcessorService( 
    $this->logger,
    $this->placeholderBuilder,
    $this->customFieldMapper,
    $this->entityMapperFactory,
    $this->replacer
);

$contactCustomFields = $amocrmClient->customFields(EntityTypesInterface::CONTACTS)->get();

$placeholders = $this->templateProcessor->getVariables(EntityTypeEnum::CONTACT, $contactCustomFields) // managers may choose placeholders from list during client message creation

// then

$contact = new ContactModel();
$contact->setName('John');

$template = 'Hello, {{Contact / Name of contact}}!';

$message = $this->templateProcessor->replaceVariables($template, $contact); // results in Hello, John!

Explanations

  1. If there is no value for given placeholder, it will be replaced with empty string.
  2. Placeholders pattern consists of entity type and field name divided by '/' like {{Lead / Custom field name}}, so it may result in string of Lead entity even if there is no custom field named 'Custom field name' if getVariables method is used with type Lead but custom fields of Contact entity.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固