mtrdesign / logo-fetcher by andonovn

Fetching companies' logos by their domain names
563
0
9
Package Data
Maintainer Username: andonovn
Maintainer Contact: office@mtr-design.com (MTR Design)
Package Create Date: 2017-06-08
Package Last Update: 2017-06-22
Language: PHP
License: MIT
Last Refreshed: 2024-04-25 15:08:00
Package Statistics
Total Downloads: 563
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 0
Total Watchers: 9
Total Forks: 0
Total Open Issues: 0

Laravel Logo Fetcher

Installation

Require this package with composer:

composer require mtr-design/laravel-logo-fetcher

Add the ServiceProvider to the providers array in config/app.php

MTRDesign\LaravelLogoFetcher\ServiceProvider::class,

Copy the package config to your local config with the publish command:

php artisan vendor:publish --provider="MTRDesign\LaravelLogoFetcher\ServiceProvider"

You now should have config/logo_fetcher.php file. You can open and tweak the configuration options

Usage

  1. Resolve the \MTRDesign\LaravelLogoFetcher\LogoFetcher class from the container
  2. Set a provider using the provider() method
  3. Call the fetch() method to get the logo
  4. You can chain with store() to save it using your default storage disk

If you want to directly store the logo:

$logoFetcher = app(\MTRDesign\LaravelLogoFetcher\LogoFetcher::class);
$logoFetcher->provider(Clearbit::class)
    ->fetch($domain)
    ->store();

If you want to just fetch the logo:

$logoFetcher = app(\MTRDesign\LaravelLogoFetcher\LogoFetcher::class);
$logo = $logoFetcher
    ->provider(Clearbit::class)
    ->fetch($domain)
    ->logo;

One extra example to illustrate the domain() helper and the path property, assuming that you injected the logo fetcher class:

$path = $this->logoFetcher
    ->provider(Clearbit::class)
    ->domain($domain)
    ->fetch()
    ->store()
    ->path;

Providers

You can define your own providers - just create a class and implement the MTRDesign\LaravelLogoFetcher\Providers\ProviderContract

Error handling

Different exceptions will be raised if the fetching fails but they all inherit from the \MTRDesign\LaravelLogoFetcher\Exceptions\LogoFetcherException. All are having human-readable messages and can be safely output to the client. You can find all the exceptions in the \MTRDesign\LaravelLogoFetcher\Exceptions namespace.