vinelab/assistant

An assistant package consisted of helper classes
10,469 4
Install
composer require vinelab/assistant
Latest Version:v1.2.0
PHP:>=5.3.0
License:MIT
Last Updated:Mar 18, 2016
Links: GitHub  ·  Packagist
Maintainer: Vinelab

Build Status

Assistant

A bunch of helper classes that provides:

  • Device detection (mobile, browser, bot, social network crawlers, etc.)
  • String formatting
  • Generating UUIDs (v4 compliant) and random IDs

Supports UTF-8 Character sets.

Installation

Dependencies

  • php 5.3+
  • mbstring (extension)

via Composer

composer require vinelab/assistant

Or add it to your composer.json

{
     "require": {
         "vinelab/assistant": "*"
     }
 }

Laravel

Edit app.php and add 'Vinelab\Assistant\AssistantServiceProvider' to the 'providers' array.

It will automatically alias the classes Formatter, DeviceDetector and Generator, In case you would like to customize their names, edit the aliases array in app.php with the following:

array(
	'...',
	'MyFormatter' => 'Vinelab\Assistant\Facades\Formatter',
	'MyGenerator' => 'Vinelab\Assistant\Facades\Generator',
	'MyDeviceDetector' => 'Vinelab\Assistant\Facades\DeviceDetector',
)

Formatter

	Formatter::snakify('my word to make a snake'); // output: my_word_to_make_a_snake

	Formatter::camelify('hakuna matata'); //output: hakunaMatata

	Formatter::neutralize('I hAtE whEn sOmEoNe wRites thInGs LIKE tHiS');
	// output: ihatewhensomeonewritesthingslikethis

	Formatter::dashit('bash cash slash'); // output: bash-cash-slash

	Formatter::date('10-02-2010 12:13:00'); // output: 10/02/10

	Formatter::date('10-02-2010 12:13:00', 'd-m-y'); // output: 10-02-10

	// Turn a camelCase string into dash-separated string
	Formatter::aliasify('simpleTest'); // output: simple-test

	Formatter::br2nl('a<br>b'); // output: a\nb

	// Clean up HTML formatting to be saved in the database or used as plain text
	// keeping links only as anchor tags. Solves an issue with editors when pasting
	// in text from word processors or web pages. PS: removes all sorts of media.
	Formatter::cleanHTML('<p>some</p><br><a href="#html">HTML</a><div>cleaned</div><img src="http://come.img" />');
	// output: some\n\n<a href="#html">HTML</a>\ncleaned\n

DeviceDetector

	$user_agent = $_SERVER['HTTP_USER_AGENT'];

	// or in case of laravel
	$user_agent = Request::server('HTTP_USER_AGENT');

	DeviceDetector::isMobile($user_agent); // true|false

	DeviceDetector::isBrowser($user_agent); // true|false

	DeviceDetector::isBot($user_agent); // true|false - also detects sharing bots

	DeviceDetector::isSharingBot($user_agent) // true|false

	DeviceDetector::whatIs($user_agent); // mobile|browser|bot|sharing-bot

	DeviceDetector::os($user_agent); // ios|android|blackberry|windows|other

Generator

	// Generate a UUID v4 compliant.
	$uuid = Generator::uuid();

	// unique identifier that does not exceed 30 chars
	$id = Generator::randomId(); // 907927051cdd15588d36

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

631,580,251 9,707
laravel/framework

The Laravel Framework.

580,311,802 34,925
laravel/tinker

Powerful REPL for the Laravel framework.

489,754,436 7,444
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

404,034,618 608
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

384,821,166 4,658