2017 © Pedro Peláez
 

library sensible

A library for finding sensible user programs, like editor, pager, and browser.

image

nubs/sensible

A library for finding sensible user programs, like editor, pager, and browser.

  • Monday, July 24, 2017
  • by nubs
  • Repository
  • 2 Watchers
  • 0 Stars
  • 77 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

sensible

A PHP library for finding sensible user programs, like editor, pager, and browser., (*1)

Build Status Scrutinizer Code Quality Code Coverage, (*2)

Latest Stable Version Total Downloads License, (*3)

Dependency Status, (*4)

Requirements

This library requires PHP 5.6, or newer., (*5)

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:, (*6)

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)., (*7)

Program Factories

The recommended way to initialize one of the supported program loaders is to use the included factories., (*8)

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, (*9)

A simple example for creating a browser object:, (*10)

$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:, (*11)

$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, (*12)

A simple example for creating a editor object:, (*13)

$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:, (*14)

$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, (*15)

A simple example for creating a pager object:, (*16)

$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:, (*17)

$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., (*18)

Browser

A browser can be executed to load a supported URI. For example:, (*19)

$browser->viewURI(
    new Symfony\Component\Process\ProcessBuilder(), 
    'http://www.google.com'
);

Editor

The editor can be used to edit files. For example:, (*20)

$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:, (*21)

$updatedMessage = $editor->editData(
    new Symfony\Component\Process\ProcessBuilder(), 
    'a message'
);

This will return the input unaltered if the process does not exit successfully., (*22)

Pager

The pager passes the file or string to the configured pager for convenient viewing. For example, for a file source:, (*23)

$process = $pager->viewFile(
    new Symfony\Component\Process\ProcessBuilder(), 
    '/path/to/a/file'
);

Or for a string source:, (*24)

$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., (*25)

License

sensible is licensed under the MIT license. See LICENSE for the full license text., (*26)

The Versions

24/07 2017

dev-update-dependencies

dev-update-dependencies

A library for finding sensible user programs, like editor, pager, and browser.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Spencer Rinehart

user editor environment browser pager sensible

20/09 2016

dev-master

9999999-dev

A library for finding sensible user programs, like editor, pager, and browser.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Spencer Rinehart

user editor environment browser pager sensible

23/05 2016

v0.5.0

0.5.0.0

A library for finding sensible user programs, like editor, pager, and browser.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Spencer Rinehart

user editor environment browser pager sensible

15/07 2014

v0.4.0

0.4.0.0

A library for finding sensible user programs, like editor, pager, and browser.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Spencer Rinehart

user editor environment browser pager sensible

07/07 2014

v0.3.0

0.3.0.0

A library for finding sensible user programs, like editor, pager, and browser.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Spencer Rinehart

user editor environment browser pager sensible

03/06 2014

v0.2.0

0.2.0.0

A library for finding sensible user programs, like editor, pager, and browser.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Spencer Rinehart

user editor environment browser pager sensible

29/05 2014

v0.1.0

0.1.0.0

A library for finding sensible user programs, like editor, pager, and browser.

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Spencer Rinehart

user editor environment browser pager sensible