michaeljennings / utilities
Installs: 2 588
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >=7.1.3
- illuminate/support: >=5.1
Requires (Dev)
- illuminate/cache: >=5.1
- michaeljennings/broker: ^1.0
- michaeljennings/refinery: ^1.2
- orchestra/testbench: >=3.6
README
This package contains a series of utility classes that I use frequently in projects, most of the utilities are built with laravel in mind.
Installation
Install using composer require michaeljennings/utilities
.
Refinery Caching
Occasionally when using the refinery package you may have templates that are quite intensive to run.
To fix this you can use the CachesTemplates
trait.
Firstly, you need to install the michaeljennings/broker package.
Then on the class you want to refine implement the Cacheable
interface. See the broker documentation for more information.
// 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.
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.
This class allows you to create links between multiple domains, but use the same API throughout your application.
Firstly you need to define the domains in the utilities.php
config file.
'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.
$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.
$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.
$domainBuilder = new MichaelJennings\Utilities\DomainBuilder(config('utilities.domains'));