totten/pogo
Composer 安装命令:
composer require totten/pogo
包简介
Run PHP scripts with inline dependencies
README 文档
README
Pogo allows you to write small PHP scripts which use PHP libraries (courtesy
of composer/packagist)... but it doesn't require you setup a
special-purpose folder, project, or repository. To use a dependency, simply
add a small pragma into your script. For example:
#!require symfony/yaml: ~4.4
This makes it easier to use PHP libraries for glue-scripts, throw-away scripts, quick experiments, etc.
Example
Let's pick a small task that requires a few libraries -- suppose we want
to generate a pretty PDF from a source-code file (*.php, *.json, etc).
We'll need a pretty-printer (scrivo/highlight.php)
and a PDF generator (dompdf/dompdf).
Skimming the README for each library, one finds a few introductory snippets.
I took these, added the #!require pragmas, and improvised a little on the
$html variable. This becomes a small script, code2pdf.php:
<?php $code = file_get_contents('php://stdin'); #!require scrivo/highlight.php: ~9.15 $hl = new \Highlight\Highlighter(); $hl->setAutodetectLanguages(['php', 'css', 'yaml', 'json', 'js']); $highlighted = $hl->highlightAuto($code); $html = sprintf('<link rel="stylesheet" href="file://%s"/>', \HighlightUtilities\getStyleSheetPath('sunburst.css')); $html .= sprintf("<pre><code class=\"hljs %s\">%s</code></pre>", $highlighted->language, $highlighted->value); #!require dompdf/dompdf: ~0.8.3 $dompdf = new \Dompdf\Dompdf(); $dompdf->loadHtml($html); $dompdf->setPaper('A4', 'landscape'); $dompdf->render(); $dompdf->stream();
To run this script in the CLI, just use:
pogo code2pdf.php
Of course, this script expects some content as input (e.g. myfile.yml) and produces a PDF as output (e.g. myfile.pdf), so a more realistic command would be
cat myfile.yml | pogo code2pdf.php > myfile.pdf
That's it!
More examples
The examples folder has several examples of using other libraries and frameworks, such as ReactPHP, Symfony Console, Clippy, and Robo. Each example is an executable program.
Motivation
Most of my day-to-day work is in PHP, JS, and bash. From time-to-time, one needs a bit of glue-code for one-offs, and
I find myself avoiding PHP for that task... because using a library in PHP still requires bits of administrativa.
pogo is an experiment to reduce that administrativa. Just create a .php file and run it.
Documentation
- Installation: System requirements and install steps
- Composer integration: How
pogoworks withcomposer - Execution: Ways to invoke scripts via
pogo - Compile to PHAR: How to create a
pharusingpogo - FAQ: Frequently asked questions
- Pragmas: List of all supported pragmas
- Todo: Misc things that should be done
Related
- Clippy: A variant of
symfony/consoleoptimized for scripting.
totten/pogo 适用场景与选型建议
totten/pogo 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 44, 最近一次更新时间为 2019 年 12 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 totten/pogo 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 totten/pogo 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 44
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-04