2017 © Pedro Peláez
 

library named-sprintf

Enhance PHP sprintf with Python-style named parameters

image

lightster/named-sprintf

Enhance PHP sprintf with Python-style named parameters

  • Saturday, July 7, 2018
  • by lightster
  • Repository
  • 1 Watchers
  • 2 Stars
  • 6,346 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 4 Open issues
  • 10 Versions
  • 8 % Grown

The README.md

named-sprintf

Build Status Test Coverage Code Climate, (*1)

Enhance PHP sprintf with Python-style named parameters, (*2)

Requirements

  • PHP >= 7.0
  • Composer

Installation

composer require lightster/named-sprintf:dev-master

Basic Usage

sprintf(
    "Hello %(first_name)s %(last_name)s\n",
    ['first_name' => 'Matt', 'last_name' => 'Light']
);
?>

Type Usage

Similar to PHP's built-in sprintf, types and format options can be passed after the named parameter:, (*3)

sprintf(
    "PI is approximately %(pi).5f, or %(pi).8f if you need more accuracy\n",
    ['pi' => pi()]
);

echo $sprintf->sprintf(
    "The type is optional and defaults to string (e.g. 's'): %(name)\n",
    ['name' => 'Typeless!']
);
?>

Middleware

Values can be processed before they are formatted by passing middleware to the constructor of Sprintf. The middleware can be any sort of PHP callable and will be passed the parameter name that is about to be formatted and a callable that gives the middleware access to all of the values passed to $sprintf->sprintf()., (*4)

The below example takes any parameter passed in as an array and converts it to a space-delimited string of words before passing the value to the sprintf string formatter:, (*5)

sprintf(
    "Middleware %(action_words) to pre-process %(what)!\n",
    [
        'action_words' => ['can', 'be', 'used'],
        'what'         => 'parameters',
    ]
);
?>

Reusable Middleware

Reusable, chainable middleware can be developed by extending the AbstractInvokable class. Some reusable middleware is shipped with named-sprintf., (*6)

Cli\Bundle Middleware

The Cli\Bundle middleware is a series of middleware that is bundled together to allow for easy command line string generation., (*7)

sprintf(
    "php bin/some-cli %(sub-command) %(long-options) %(short-options)",
    [
        'sub-command'  => 'commit',
        'long-options' => [
            'message' => 'Showing off a CLI command',
            'author'  => 'Matt',
        ],
        'short-options' => [
            'a' => null,
        ],
    ]
) . "\n";
?>

The Versions

07/07 2018

dev-master

9999999-dev http://github.com/lightster/named-sprintf

Enhance PHP sprintf with Python-style named parameters

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php python named params sprintf

07/07 2018

dev-stop-building-branches-without-a-pr

dev-stop-building-branches-without-a-pr http://github.com/lightster/named-sprintf

Enhance PHP sprintf with Python-style named parameters

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php python named params sprintf

07/07 2018

dev-switch-dev-docker-to-alpine

dev-switch-dev-docker-to-alpine http://github.com/lightster/named-sprintf

Enhance PHP sprintf with Python-style named parameters

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php python named params sprintf

07/07 2018

dev-add-drone-config

dev-add-drone-config http://github.com/lightster/named-sprintf

Enhance PHP sprintf with Python-style named parameters

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php python named params sprintf

04/07 2018

v0.2.0

0.2.0.0 http://github.com/lightster/named-sprintf

Enhance PHP sprintf with Python-style named parameters

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php python named params sprintf

04/07 2018

dev-issue-55-update-dependencies-to-php72

dev-issue-55-update-dependencies-to-php72 http://github.com/lightster/named-sprintf

Enhance PHP sprintf with Python-style named parameters

  Sources   Download

MIT

The Requires

  • php ^7.0

 

The Development Requires

php python named params sprintf

20/09 2016

v0.1.2

0.1.2.0 http://github.com/lightster/named-sprintf

Enhance PHP sprintf with Python-style named parameters

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

php python named params sprintf

28/05 2016

v0.1.1

0.1.1.0 http://github.com/lightster/named-sprintf

Enhance PHP sprintf with Python-style named parameters

  Sources   Download

The Requires

  • php >=5.5.0

 

The Development Requires

php python named params sprintf

17/05 2016

v0.1.0

0.1.0.0 http://github.com/lightster/named-sprintf

Enhance PHP sprintf with Python-style named parameters

  Sources   Download

The Requires

  • php >=5.5.0

 

The Development Requires

php python named params sprintf

08/05 2016

v0.0.1

0.0.1.0 http://github.com/lightster/named-sprintf

Enhance PHP sprintf with Python-style named parameters

  Sources   Download

The Requires

  • php >=5.5.0

 

The Development Requires

php python named params sprintf