2017 © Pedro Peláez
 

library belt

A utility belt

image

mover-io/belt

A utility belt

  • Friday, June 1, 2018
  • by derekdowling
  • Repository
  • 10 Watchers
  • 5 Stars
  • 29,372 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 14 Versions
  • 4 % Grown

The README.md

# belt

A PHP developer toolbelt full of rainbows and awesome output!, (*1)

Created with love by @jacobstr and tried and trusted at @mover., (*2)

Classes

Trace

Provides Error, Logging, and CLI debugging tools through intelligent and colorized stack, source, and result formatted outputs. Better than straight up error_log because: 1. You always know the line number where the log statement took place, so it's easier to remove later. 2. With a larger traceDepth, you can identity the call sites of your code. 3. The tinting options help during console-debugging sessions that escalate to the stage that you're dumping a lot of data and need a way to visually scan for particular messages., (*3)

Example:, (*4)

Belt\Trace::debug($your_result);
// with Stack Trace
Belt\Trace::traceDepth(7)->debug($your_result);

Text

Provides string format helpers for frequent string helpers., (*5)

Example:, (*6)

$route = Belt\Text::ensureNoPrefix($route, "/v2/");
$route = Belt\Text::ensureNoSuffix($route, "/");

Arrays

Provides array helpers for common actions., (*7)

Example:, (*8)

// Safe getter that returns null if no value for key
$value = Belt\Array::get($array, 'key', null)

Profile

Provides run time profiling for memory and execution time on function calls., (*9)

SchemaObject

Facebook's React has a similar concept, known as a shape. SchemaObject is useful when you want to wrap a plain old array with a type. This in turn, is useful when you want to type hint a function. Instead of declaring a $user_info parameter, you can specify UserInfo $user_info. Cross-referencing UserInfo immediately tells you the key/value pairs that your object should have. Further, the SchemaObject may assist in validation so that the values corresponding to a given key have the correct type., (*10)

<?php namespace Mover\Connectors\Sharing;

use Belt\SchemaObject;
use Belt\Arrays;

class UserInfo extends SchemaObject
{
    protected static $attribute_spec = array(
        'first_name'  => array('type' => 'string'),
        'last_name'   => array('type' => 'string'),
        'email'       => array('type' => 'string'),
        // E.g. this could be an id from the migration source system.
        'external_id' => array('type' => 'string'),
        // The users id' in the active connector.
        'id'          => array('type' => 'string'),
        // The raw data from the third party if available. This is optional.
        // Code should never rely on a raw field. We may use it for debugging
        // and introspection.
        'raw'         => array('type' => 'array')
    );

    public function fullname()
    {
        return implode(
            ' ',
            array_filter(
                array($this->first_name, $this->last_name)
            )
        );
    }

    /**
     * Splits a full name (first + last name) into an array of two parts, the
     * first and last name. Note that this assumes only a single space separates
     * the first and last name.
     */
    public static function splitName($fullname)
    {
          $name_parts = explode(" ", $fullname, 2);
          $first_name = Arrays::get($name_parts, 0, "");
          $last_name  = Arrays::get($name_parts, 1, "");
          return array($first_name, $last_name);
    }
}

The Versions

01/06 2018

dev-master

9999999-dev

A utility belt

  Sources   Download

MIT

The Development Requires

01/06 2018

1.0.8

1.0.8.0

A utility belt

  Sources   Download

MIT

The Development Requires

01/06 2018

dev-stop_clipping_stack_trace

dev-stop_clipping_stack_trace

A utility belt

  Sources   Download

MIT

The Development Requires

01/08 2017

1.0.7

1.0.7.0

A utility belt

  Sources   Download

MIT

The Development Requires

16/02 2017

1.0.6

1.0.6.0

A utility belt

  Sources   Download

MIT

The Development Requires

30/08 2016

1.0.5

1.0.5.0

A utility belt

  Sources   Download

MIT

The Development Requires

27/07 2016

v1.0.4

1.0.4.0

A utility belt

  Sources   Download

MIT

The Development Requires

27/07 2016

v2.0.1

2.0.1.0

A utility belt

  Sources   Download

MIT

The Development Requires

27/07 2016

dev-dehumanize_profile_info

dev-dehumanize_profile_info

A utility belt

  Sources   Download

MIT

The Development Requires

22/03 2016

1.0.3

1.0.3.0

A utility belt

  Sources   Download

MIT

The Development Requires

17/02 2016

v1.0.2

1.0.2.0

A utility belt

  Sources   Download

MIT

The Development Requires

17/02 2016

v2.0.0

2.0.0.0

A utility belt

  Sources   Download

MIT

The Development Requires

16/01 2015

1.0.1

1.0.1.0

A utility belt

  Sources   Download

MIT

The Development Requires

19/09 2014

1.0

1.0.0.0

A utility belt

  Sources   Download

MIT

The Development Requires