承接 pointybeard/symphony-section-builder 相关项目开发

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

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

pointybeard/symphony-section-builder

Composer 安装命令:

composer require pointybeard/symphony-section-builder

包简介

A set of classes and scripts for automating the creation and updating of sections and their fields.

README 文档

README

A set of classes that assist with the creating and updating of sections and their fields.

Installation

This libary can be used standalone or as part of a Symphony CMS installation (including Extension).

Standalone

Clone desired version from the GitHub repository with git clone https://github.com/pointybeard/symphony-section-builder.git then run composer update within that folder. Note, this will install dev library symphonycms/symphony-2 by default. Use --no-dev when running composer update to skip this.

Using Composer

To install via Composer, use composer require pointybeard/symphony-section-builder or add "pointybeard/pointybeard/symphony-section-builder": "^0.2.0" to your composer.json file.

And run composer to update your dependencies, for example:

$ curl -s http://getcomposer.org/installer | php
$ php composer.phar update

Note that this method will NOT install any dev libraries, specifically symphonycms/symphony-2. Generally this is the desired behaviour, however, should the core Symphony CMS library not get included anywhere via composer (e.g. Section Builder is being used as part of a library that doesn't already include Symphony CMS), be use to use the --dev flag (e.g. composer update --dev) to ensure symphonycms/symphony-2 is also installed, or, use the --symphony=PATH option to tell Section Builder where to load the Symphony CMS core from.

Usage

Quick example of how to use this library:

<?php
use pointybeard\Symphony\SectionBuilder;
use pointybeard\Symphony\SectionBuilder\Models;

try {
    $categories = Models\Section::loadFromHandle('categories');
    if(!($categories instanceof Models\Section)) {
        $categories = (new Models\Section)
            ->name("Categories")
            ->handle("categories")
            ->navigationGroup("Content")
            ->allowFiltering(true)
            ->hideFromBackendNavigation(false)
            ->addField(
                (new Models\Fields\Input)
                    ->label("Name")
                    ->elementName("name")
                    ->location(SectionBuilder\AbstractField::PLACEMENT_MAIN_CONTENT)
                    ->required(true)
                    ->showColumn(true)
                    ->validator("")
            )
            ->commit();
        ;
    }

    $articles = Models\Section::loadFromHandle('articles');
    if(!($articles instanceof Models\Section)) {
        $articles = (new Models\Section)
            ->name("Articles")
            ->handle("articles")
            ->navigationGroup("Content")
            ->allowFiltering(true)
            ->hideFromBackendNavigation(false)
            ->addField(
                (new Models\Fields\Input)
                    ->label("Title")
                    ->elementName("title")
                    ->location(SectionBuilder\AbstractField::PLACEMENT_MAIN_CONTENT)
                    ->required(true)
                    ->showColumn(true)
                    ->validator("")
            )
            ->addField(
                (new Models\Fields\Textarea)
                    ->label("Body")
                    ->elementName("body")
                    ->location(SectionBuilder\AbstractField::PLACEMENT_MAIN_CONTENT)
                    ->required(true)
                    ->showColumn(true)
                    ->size(10)
                    ->formatter(null)
            )
            ->addField(
                (new Models\Fields\Date)
                    ->label("Created At")
                    ->elementName("date_created_at")
                    ->location(SectionBuilder\AbstractField::PLACEMENT_SIDEBAR)
                    ->required(true)
                    ->showColumn(true)
                    ->prePopulate("now")
                    ->calendar(false)
                    ->time(true)
            )
            ->addField(
                (new Models\Fields\Select)
                    ->label("Categories")
                    ->elementName("categories")
                    ->location(SectionBuilder\AbstractField::PLACEMENT_SIDEBAR)
                    ->required(true)
                    ->showColumn(true)
                    ->allowMultipleSelection(true)
                    ->sortOptions(true)
                    ->staticOptions(null)
                    ->dynamicOptions(
                        $categories->findFieldByElementName("name")
                    )
            )
            ->commit()
        ;
    }

    print "Success!!" . PHP_EOL;

} catch (\Exception $ex) {
    print "FAILED: " . $ex->getMessage() . PHP_EOL;
}

Importing JSON

Run bin/import from the command line or use code like this:

<?php
use pointybeard\Symphony\SectionBuilder;
SectionBuilder\Import::fromJsonFile('/path/to/some/file.json');

Use flag FLAG_SKIP_ORDERING if importing partial section JSON. This helps to avoid a circular dependency exception being thrown. Flags are supported by fromJsonFile(), fromJsonString(), and fromObject(). For example:

<?php
SectionBuilder\Import::fromJsonFile('/path/to/some/file.json', SectionBuilder\Import::FLAG_SKIP_ORDERING);

JSON must be an array of sections and look like this:

{
    "sections": [
        {
            "name": "Providers",
            "handle": "providers",
            "sortOrder": 39,
            "hideFromBackendNavigation": false,
            "allowFiltering": false,
            "navigationGroup": "Shipping",
            "associations": [],
            "fields": [
                {
                    "label": "Name",
                    "elementName": "name",
                    "type": "input",
                    "required": true,
                    "sortOrder": 0,
                    "location": "sidebar",
                    "showColumn": true,
                    "custom": {
                        "validator": null
                    }
                },
                {
                    "label": "UUID",
                    "elementName": "uuid",
                    "type": "uuid",
                    "required": true,
                    "sortOrder": 1,
                    "location": "sidebar",
                    "showColumn": true,
                    "custom": []
                }
            ]
        }
    ]
}

Exporting

Run bin/export from the command line or use the __toString(), __toJson(), and/or __toArray() methods provided by AbstractField and Section. For example:

<?php
use pointybeard\Symphony\SectionBuilder\Models;
$section = Models\Section::loadFromHandle('categories');

print (string)$section;
print $section->__toJson();
print_r($section->__toArray());

If a full export is necessary, use the all() method and build the array before encoding it to JSON. e.g.

<?php
$output = ["sections" => []];
foreach(Models\Section::all() as $section) {
    // We use json_decode() to ensure ids (id and sectionId) are removed
    // from the output. To keep ids, use __toArray()
    $output["sections"][] = json_decode((string)$section, true);
}

print json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);

Note that IDs (specifically Section and Field id and Field sectionId properties) are automatically stripped out by __toString() and __toJson(). To keep them, either use __toArray() and encode to JSON yourself, or using __toJson() but set $excludeIds to false. e.g. $section->__toJson(false). See this implementation in the Trait hasToStringToJsonTrait.

Diff

You can compare a database with a JSON export via bin/diff from the command line or use code like this:

<?php
use pointybeard\Symphony\SectionBuilder;

foreach(SectionBuilder\Diff::fromJsonFile('/path/to/some/file.json')){
    // Print changes found here ...
}

Support

If you believe you have found a bug, please report it using the GitHub issue tracker, or better yet, fork the library and submit a pull request.

Contributing

We encourage you to contribute to this project. Please check out the Contributing documentation for guidelines about how to get involved.

License

"Symphony CMS: Section Builder" is released under the MIT License.

pointybeard/symphony-section-builder 适用场景与选型建议

pointybeard/symphony-section-builder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 602 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 11 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 pointybeard/symphony-section-builder 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-19