digitalunited/components
Composer 安装命令:
composer require digitalunited/components
包简介
Component manager
关键字:
README 文档
README
Installation
- Install via composer
- Activate plugin
- Configure grunt
Usage
A component folder should be placed in the theme-directory following this structure:
└── components
├── SomeComponent
│ ├── assets
| | └── some-jpgs-or-whatever.jpg
│ ├── component.php
│ ├── one-or-more-less-files.less
│ ├── one-or-more-coffee-files.coffee
│ ├── view.php
│ └── _somePartialView.view.php
└── SomeOtherComponent
├── component.php
├── one-or-more-less-files.less
├── one-or-more-coffee-files.coffee
└── view.php
Every component will have their short-code registered and vc_mapping set up.
component.php
A VCComponent have the following structure:
namespace Component; class Text extends \DigitalUnited\Components\VcComponent { // This is a VC-mapping array // https://wpbakery.atlassian.net/wiki/pages/viewpage.action?pageId=524332 protected function getComponentConfig() { return [ 'name' => __('Text', 'components'), 'description' => __('Standard textmodul', 'components'), 'params' => [ [ "type" => "textfield", "holder" => "div", "class" => "", "heading" => __( "Headline", "components" ), "param_name" => "headline", "value" => "", "description" => "" ], [ "type" => "textarea_html", "holder" => "div", "class" => "", "heading" => __( "Content", "components" ), "param_name" => "content", "value" => "", "description" => "" ], ] ]; } // If you want to you can have diferent views for deferent cases. // If you do you can override the following method. // // If view is not specified they will be rendered in the following // order: [view].view.php, view.php // // default is __DIR__.'/view.php' protected function getViewFileName() { return parent::getViewFileName(); } // Before the parameters of the components is sent to rendering // you may modify their values here protected function sanetizeDataForRendering($data) { return $data; } // If you want to change what kind of element is rendered // You could override this method protected function getWrapperElementType() { return 'div'; } // Add classes to the wrapping element. Should be an array // If a param named view exists it will be added automaticly protected function getExtraWrapperClasses() { return $this->param('headline') ? ['has-headline'] : ['no-headline']; } // Add attribute to the wrapper. if 'class' is specified it will be merged in // with classes from getExtraWrapperClasses protected function getWrapperAttributes() { return ['href' => 'myhref foobar', 'role' => 'button']; } // May be used to implement logic such as post-type registering or whatever public function main() { } } ?>
A Standard component have the following structure:
namespace Component; class Sidebar extends \DigitalUnited\Components\Component { // Return key value pair with the accepted parameters for this // view file protected function getDefaultParams() { return [ 'param1' => 'default value1', 'param2' => '', 'view' => 'default', ]; } //Same as a VcComponent protected function getViewFileName() { ... } protected function sanetizeDataForRendering($data) { ... } public function main() { ... } } ?>
View
In the views, all values returned from "sanetizeDataForRendering" will be accessible.
eg. ['foo' => 'bar'] will be available like
<?= $foo // outputs 'bar' ?>
You may also use the component class, referenced as $component. eg:
<?= $component->myFancyPublicFunction() ?>
You may use separate view files depending on the $view-param, if "view" param is specified, $view.view.php will be rendered. Default: view.php
It is possible to split a view file into partials:
<?= $component->renderPartial('_listItem') // renders _listItem.view.php ?>
Performance
When a slow registration of a component is detected the plugin will show an admin notice. Slow registration could be caused by by 2 reasons:
- Dynamic population of params
- Execution of tasks in the components main method.
If the problem is due to Dynamic population of params there is an easy solution. Just add the following code as an early abort in the function that generates the dynamic params:
if (!$this->shouldGenerateParams()) { return []; }
It the code above doesn't help the problem probably is that code is executed in the components main function.
Less and coffe, assets
Could be handled with with Grunt/gulp or whatever. See https://github.com/digitalunited/roots for example
digitalunited/components 适用场景与选型建议
digitalunited/components 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.7k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2015 年 02 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「plugin」 「wordpress」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 digitalunited/components 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 digitalunited/components 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 digitalunited/components 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
Plugin for YOURLS. Default tools to use in some laemmi plugins
Must-use plugin integrating WordPress with the Upsun platform: environment awareness, router-cache friendliness, safe preview clones, deploy migrations, Site Health checks, and a wp upsun CLI command.
Allows polling user for event dates and times.
Support swipe touch gestures to navigate in paginated lists and on Tidypics image pages.
Add a postscript to every email notification sent out to users.
统计信息
- 总下载量: 11.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 8
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-02-03