evista/compress
Composer 安装命令:
composer require evista/compress
包简介
Composer package manager integration for WordPress
README 文档
README
ComPress is a Wordpress plugin that helps to use composer with a lazy loader service container (dependency injector).
Install
Usage
echo $container->get('twig.templating')->render('index.twig.html', ['hehh' => 'Yeah!']);
Documentation
ComPress plugin makes the marvellous Composer accessible in any WordPress project. If you never heard about it, Composer is a PHP package manager with a very good dependency resolver that makes using of third party libraries a breeze.
Composer transformed the PHP ecosystem recently so you should probably learn it. If you want to use the latest Twig templating engine in your WordPress plugins or themes you only have to
- run composer require twig/twig in the module’s root dir
- add the new package to the lazy loader service container’s setup
Afterwards the Twig rendering engine will be accessible from anywhere this way:
echo $container->get('twig.templating')->render('index.twig.html', ['hehh' => 'Yeah!']);
How to add a package to the container
Every package has a different way of initializing, the container helps collect them under a unified API -- and besides it helps decoupling your code (decoupling makes your code more maintanable and solid)
Twig’s documentation says this is the way you can instantiates Twig after installing it:
$loader = new Twig_Loader_Filesystem('/path/to/templates'); $twig = new Twig_Environment($loader, array( 'cache' => '/path/to/compilation_cache', )); echo $twig->render('index.html', array('name' => 'Fabien'));
So the container needs to instantiate two classes, the Twig_Loader_Filesystem and using it as an argument the Twig_Environment class, that can be used to rendering directly. The container can solve this dependency easily if we define two services, and use the first as an argument of the second:
//wp-content/plugins/evista-composer/Composer.php /** * Add service definitions here: * */ public function setUpServices(){ $this->services = [ 'twig.loader' =>[ 'class' => '\Twig_Loader_Filesystem', 'arguments' => [__DIR__.'/views'] ], 'twig.templating' => [ 'class' => '\Twig_Environment', 'arguments' => ['@twig.loader'] ], ]; }
The Composer::services variable holds all the needed informations. Every one of them requires a unique name, that will identify them throughout WordPress. These names will be the keys of the services array, and the most important properties of the services in an array are the values.
In the above example, ‘twig.templating’ is the name, this is how it can be requested from the container:
$templating = $container->get('twig.templating'); $page = $templating->render('index.twig.html', ['hehh' => 'Yeah!']);
In the configuration array above there are two important key value pairs: class and arguments.
The first tells the container which class should it use to instantiate the service (with namespaces), and second tells what argument to use in what order. So far strings, flat (one level) arrays and other services are supported as argument.
public function setUpServices(){ $this->services = [ 'sample.service' =>[ 'class' => '\SampleService', 'arguments' => ['string', '@other.service', ['first'=>'1', "second" => '2']] ], // .. ]; }
And this is it. After modifying Composer you are ready to use your new package installed via composer.
Change log
Please see CHANGELOG for more information what has changed recently.
Testing
$ phpunit
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email sera.balint@e-vista.hu instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
evista/compress 适用场景与选型建议
evista/compress 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 05 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「composer」 「dependency manager」 「evista」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 evista/compress 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 evista/compress 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 evista/compress 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A fast and intuitive dependency injection container.
This composer plugin enables installation of GravityForms WordPress plugin and its addons.
Simple ASCII output of array data
Dependency injection container for the Monolith framework.
Http Microframework for Hack
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-05-01