2017 © Pedro Peláez
 

library utilities

image

michaeljennings/utilities

  • Tuesday, July 17, 2018
  • by michaeljennings
  • Repository
  • 1 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Utilities

This package contains a series of utility classes that I use frequently in projects, most of the utilities are built with laravel in mind., (*1)

Installation

Install using composer require michaeljennings/utilities., (*2)

Refinery Caching

Occasionally when using the refinery package you may have templates that are quite intensive to run., (*3)

To fix this you can use the CachesTemplates trait., (*4)

Firstly, you need to install the michaeljennings/broker package., (*5)

Then on the class you want to refine implement the Cacheable interface. See the broker documentation for more information., (*6)

// Item being refined
class ToRefine implements Michaeljennings\Broker\Contracts\Cacheable
{
    /**
     * Get the key to cache the attributes against.
     *
     * @return string
     */
    public function getCacheKey()
    {
        return 'test';
    }

    /**
     * Get the unique key for the cacheable item.
     *
     * @return int|string
     */
    public function getKey()
    {
        return 1;    
    }
}

Finally implement the CachesTemplates trait on your refinery., (*7)

class Example extends Michaeljennings\Refinery\Refinery
{
    use CachesTemplates;

    public function setTemplate($item)
    {
        //
    }
}

Domain Builder

Very frequently I build projects that use multiple subdomains. I also find I need to create links between subdomains quite frequently but I don't want to hard code the links., (*8)

This class allows you to create links between multiple domains, but use the same API throughout your application., (*9)

Firstly you need to define the domains in the utilities.php config file., (*10)

'domains' => [
  'app' => 'http://app.example.com',
  'api' => 'http://api.example.com',
]

Then you can either hit the get method, or dynamically hit the key you have set., (*11)

$url = $domainBuilder->get('app'); // http://app.example.com
$url = $domainBuilder->app(); // http://app.example.com

You can also pass anything you want to be appended to the url as an argument., (*12)

$url = $domainBuilder->get('app', 'foo/bar'); // http://app.example.com/foo/bar
$url = $domainBuilder->get('app', 'foo', 'bar'); // http://app.example.com/foo/bar
$url = $domainBuilder->app('foo/bar'); // http://app.example.com/foo/bar
$url = $domainBuilder->app('foo', 'bar'); // http://app.example.com/foo/bar

I usually resolve class using laravel's IOC container, but if you want to new it up yourself you just need to pass the config to the constructor., (*13)

$domainBuilder = new MichaelJennings\Utilities\DomainBuilder(config('utilities.domains'));

The Versions

17/07 2018

dev-master

9999999-dev

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Jennings

17/07 2018

v1.0.1

1.0.1.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Jennings

17/07 2018

v1.0.0

1.0.0.0

  Sources   Download

MIT

The Requires

 

The Development Requires

by Michael Jennings