Download the PHP package mtownsend/read-time without Composer

On this page you can find all versions of the php package mtownsend/read-time. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package read-time

A PHP package to show users how long it takes to read content.

Installation

Install via composer:

This package is designed to work with any PHP 7.0+ application but has special support for Laravel.

Registering the service provider (Laravel)

For Laravel 5.4 and lower, add the following line to your config/app.php:

For Laravel 5.5 and greater, the package will auto register the provider for you.

Using Lumen

To register the service provider, add the following line to app/bootstrap/app.php:

Publishing the config file (Laravel)

ReadTime has special configuration support for Laravel applications. You can publish a single config file and customize how you want your read time text to be displayed.

`

These are the contents of the read-time.php config file:

Publishing the translation files (Laravel)

ReadTime supports localization with Laravel. If you are using Laravel you'll likely want to use the premade translations.

`

Quick start

Using the class

Here is an example of the most basic usage:

You may also pass several arguments to the constructor if you wish to change settings on the fly:

The ReadTime class is able to accept a string of content or a flat array of multiple pieces of content. This may come in handy if you are attempting to display the total read time of body content along with sidebar content. For example:

Methods, and arguments

Method

->abbreviated(bool $abbreviated = true)

Abbreviate the words 'minute' and 'second' to 'min' and 'sec'.

->get()

Retrieve the read time. Note: you may also invoke the class as a function or cast it as a string to retrieve the same result as get().

->getTranslation($key = null)

You may return the current translation array the class is using by omitting any argument from this method or get a specific translation key by passing it as an argument.

->ltr(bool $ltr = true)

Set the text direction of the read time result to left (default) with true, and right with false. Alternatively, you may simply call the ->rtl() method without any argument.

->omitSeconds(bool $omitSeconds = true)

Have the read time display omit seconds. Pass false to include seconds.

->rtl(bool $rtl = true)

Set the text direction of the read time result to right (default) with true, and left with false. Alternatively, you may simply call the ->ltr() method without any argument.

->setTranslation(array $translations)

Manually set the translation text for the class to use. If no key is passed it will default to the English counterpart. A complete translation array will contain the following:

->timeOnly(bool $timeOnly = true)

Omit any words from the read time result. Pass false to include words.

->toArray()

Get the contents and settings of the class as an array.

->toJson()

Get the contents and settings of the class as a json string.

->wpm(int $wordsPerMinute)

Set the average pace of words read per minute.

Using the global helper (Laravel)

If you are using Laravel, this package provides a convenient helper function which is globally accessible.

The global helper is exceptionally useful in your Laravel application. It can be used in views (remember, it outputs the read time if invoked or cast as a string, which Blade's double curly braces does):

`

The global helper will also attempt to intelligently detect the information you are passing it. For example, if you pass it a non-associative array it will assume you are passing an array of content.

`

But you are still free to customize the ReadTime class settings on the fly using the global helper. Simply pass an associative array of settings:

`

Purpose

Sites like Medium.com have popularized the concept of giving users an estimate for the amount of time it will take them to read the content. With this convenience in mind, ReadTime gives PHP developers the same tool for their readable content. It's a simple feature that will give a nice touch to your PHP application.

Contributing translations

Pull requests for translations are encouraged. Please be sure to follow the existing format.

Credits

Testing

You can run the tests with:

License

The MIT License (MIT). Please see License File for more information.


All versions of read-time with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mtownsend/read-time contains the following files

Loading the files please wait ....