nubs/sensible
Composer 安装命令:
composer require nubs/sensible
包简介
A library for finding sensible user programs, like editor, pager, and browser.
README 文档
README
A PHP library for finding sensible user programs, like editor, pager, and browser.
Requirements
This library requires PHP 5.6, or newer.
Installation
This package uses composer so you can just add
nubs/sensible as a dependency to your composer.json file or execute the
following command:
composer require nubs/sensible
Supported Program Types
This library supports opening a text editor (like vim), a pager (like more), and a browser (like firefox).
Program Factories
The recommended way to initialize one of the supported program loaders is to use the included factories.
Browser Factory
The browser factory uses a command locator (via which) to determine which browsers are available. The default list of browsers is
- sensible-browser
- firefox
- chromium-browser
- chrome
- elinks
A simple example for creating a browser object:
$commandLocatorFactory = new Nubs\Which\LocatorFactory\PlatformLocatorFactory(); $browserFactory = new Nubs\Sensible\CommandFactory\BrowserFactory( $commandLocatorFactory->create() ); $browser = $browserFactory->create();
If you want to override the default list of browsers:
$commandLocatorFactory = new Nubs\Which\LocatorFactory\PlatformLocatorFactory(); $browserFactory = new Nubs\Sensible\CommandFactory\BrowserFactory( $commandLocatorFactory->create(), ['my-favorite-browser', 'some-fallback-browser'] ); $browser = $browserFactory->create();
Editor Factory
The editor factory uses your EDITOR environment variable if set, otherwise it
uses a command locator (via which) to determine which editors are available.
The default list of editors is
- sensible-editor
- nano
- vim
- ed
A simple example for creating a editor object:
$commandLocatorFactory = new Nubs\Which\LocatorFactory\PlatformLocatorFactory(); $editorFactory = new Nubs\Sensible\CommandFactory\EditorFactory( $commandLocatorFactory->create() ); $editor = $editorFactory->create();
If you want to override the default list of editors:
$commandLocatorFactory = new Nubs\Which\LocatorFactory\PlatformLocatorFactory(); $editorFactory = new Nubs\Sensible\CommandFactory\EditorFactory( $commandLocatorFactory->create(), ['my-favorite-editor', 'some-fallback-editor'] ); $editor = $editorFactory->create();
Pager Factory
The pager factory uses your PAGER environment variable if set, otherwise it
uses a command locator (via which) to determine which pagers are available.
The default list of pagers is
- sensible-pager
- less
- more
A simple example for creating a pager object:
$commandLocatorFactory = new Nubs\Which\LocatorFactory\PlatformLocatorFactory(); $pagerFactory = new Nubs\Sensible\CommandFactory\PagerFactory( $commandLocatorFactory->create() ); $pager = $pagerFactory->create();
If you want to override the default list of pagers:
$commandLocatorFactory = new Nubs\Which\LocatorFactory\PlatformLocatorFactory(); $pagerFactory = new Nubs\Sensible\CommandFactory\PagerFactory( $commandLocatorFactory->create(), ['my-favorite-pager', 'some-fallback-pager'] ); $pager = $pagerFactory->create();
Using the programs
Once you've created the program type with its strategy for locating the sensible command for the user, you can use it to work with files/data/etc.
Browser
A browser can be executed to load a supported URI. For example:
$browser->viewURI( new Symfony\Component\Process\ProcessBuilder(), 'http://www.google.com' );
Editor
The editor can be used to edit files. For example:
$process = $editor->editFile( new Symfony\Component\Process\ProcessBuilder(), '/path/to/a/file' ); if ($process->isSuccessful()) { // continue }
There is also a convenient shorthand for editing a string in an editor by means of a temporary file. For example:
$updatedMessage = $editor->editData( new Symfony\Component\Process\ProcessBuilder(), 'a message' );
This will return the input unaltered if the process does not exit successfully.
Pager
The pager passes the file or string to the configured pager for convenient viewing. For example, for a file source:
$process = $pager->viewFile( new Symfony\Component\Process\ProcessBuilder(), '/path/to/a/file' );
Or for a string source:
$process = $pager->viewData( new Symfony\Component\Process\ProcessBuilder(), 'a message' );
CLI Interface
There is also a CLI interface for Linux systems that imitates Ubuntu's
sensible-* commands. It is available as nubs/sensible-cli.
License
sensible is licensed under the MIT license. See LICENSE for the full license text.
nubs/sensible 适用场景与选型建议
nubs/sensible 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7.42k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2014 年 05 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「browser」 「user」 「pager」 「editor」 「environment」 「sensible」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nubs/sensible 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nubs/sensible 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nubs/sensible 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Give your JS App some Backbone with Models, Views, Collections, and Events.
Instrument headless chrome/chromium instances from php5.6
Selenium4 (WebDriver) driver for Mink framework
Doctrine Collections adapter for Rekapager pagination library
Core functionality of Rekapager pagination library
Common classes for Symfony integration.
统计信息
- 总下载量: 7.42k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 20
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-05-28