Skip to content

Commit

Permalink
init setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Gummibeer committed Jan 14, 2020
1 parent 3739764 commit 2fd9086
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/vendor/
/build/
/composer.lock
/phpunit.xml
/.phpunit.result.cache
51 changes: 50 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,50 @@
# laravel-mime
# Laravel Mime

[![Latest Version](http://img.shields.io/packagist/v/astrotomic/laravel-mime.svg?label=Release&style=for-the-badge&cacheSeconds=600)](https://packagist.org/packages/astrotomic/laravel-mime)
[![MIT License](https://img.shields.io/github/license/Astrotomic/laravel-mime.svg?label=License&color=blue&style=for-the-badge&cacheSeconds=600)](https://github.com/Astrotomic/laravel-mime/blob/master/LICENSE)
[![Offset Earth](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-green?style=for-the-badge&cacheSeconds=600)](https://offset.earth/treeware)

This package provides Laravel service bindings for [symfony/mime](https://symfony.com/doc/current/components/mime.html).

## Installation

You can install the package via composer:

```bash
composer require astrotomic/laravel-mime
```

## Usage

``` php
// facade
use Astrotomic\LaravelMime\Facades\MimeTypes;

// container bindings
app('laravel-mime');
app(\Symfony\Component\Mime\MimeTypes::class);
app(\Symfony\Component\Mime\MimeTypesInterface::class);
app(\Symfony\Component\Mime\MimeTypeGuesserInterface::class);
```

## Credits

- [Tom Witkowski](https://github.com/Gummibeer)
- [All Contributors](../../contributors)

## License

The MIT License (MIT). Please see [License File](LICENSE) for more information.

## Treeware

You're free to use this package, but if it makes it to your production environment I would highly appreciate you buying the world a tree.

It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to [plant trees](https://www.bbc.co.uk/news/science-environment-48870920). If you contribute to my forest you’ll be creating employment for local families and restoring wildlife habitats.

You can buy trees at https://offset.earth/treeware

Read more about Treeware at https://treeware.earth

[![We offset our carbon footprint via Offset Earth](https://toolkit.offset.earth/carbonpositiveworkforce/badge/5e186e68516eb60018c5172b?black=true&landscape=true)](https://offset.earth/treeware)

47 changes: 47 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"name": "astrotomic/laravel-mime",
"description": "Laravel wrapper for symfony/mime",
"keywords": [
"astrotomic",
"laravel-mime"
],
"homepage": "https://github.com/astrotomic/laravel-mime",
"license": "MIT",
"type": "library",
"authors": [
{
"name": "Tom Witkowski",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"php": "^7.4",
"illuminate/support": "^6.0",
"symfony/mime": "^5.0"
},
"require-dev": {
"orchestra/testbench": "^4.5",
"phpunit/phpunit": "^8.0"
},
"autoload": {
"psr-4": {
"Astrotomic\\LaravelMime\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Astrotomic\\LaravelMime\\Tests\\": "tests"
}
},
"config": {
"sort-packages": true
},
"extra": {
"laravel": {
"providers": [
"Astrotomic\\LaravelMime\\MimeTypesServiceProvider"
]
}
}
}
8 changes: 8 additions & 0 deletions config/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

/*
* You can place your custom package configuration in here.
*/
return [

];
22 changes: 22 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
</phpunit>
24 changes: 24 additions & 0 deletions src/Facades/MimeTypes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Astrotomic\LaravelMime\Facades;

use Illuminate\Support\Facades\Facade;
use Symfony\Component\Mime\MimeTypesInterface;

/**
* @method static bool isGuesserSupported()
* @method static null|string guessMimeType(string $path)
* @method static string[] getExtensions(string $mimeType)
* @method static string[] getMimeTypes(string $ext)
*
* @see \Symfony\Component\Mime\MimeTypeGuesserInterface
* @see \Symfony\Component\Mime\MimeTypesInterface
* @see \Symfony\Component\Mime\MimeTypes
*/
class MimeTypes extends Facade
{
protected static function getFacadeAccessor(): string
{
return MimeTypesInterface::class;
}
}
29 changes: 29 additions & 0 deletions src/MimeTypesServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Astrotomic\LaravelMime;

use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\ServiceProvider;
use Symfony\Component\Mime\MimeTypeGuesserInterface;
use Symfony\Component\Mime\MimeTypes;
use Symfony\Component\Mime\MimeTypesInterface;

class MimeTypesServiceProvider extends ServiceProvider implements DeferrableProvider
{
public function register(): void
{
$this->app->singleton('laravel-mime',MimeTypes::class);
$this->app->alias('laravel-mime', MimeTypesInterface::class);
$this->app->alias('laravel-mime', MimeTypeGuesserInterface::class);
}

public function provides(): array
{
return [
'laravel-mime',
MimeTypes::class,
MimeTypesInterface::class,
MimeTypeGuesserInterface::class,
];
}
}
38 changes: 38 additions & 0 deletions tests/MimeTypesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Astrotomic\LaravelMime\Tests;

use Astrotomic\LaravelMime\MimeTypesServiceProvider;
use Orchestra\Testbench\TestCase;
use Symfony\Component\Mime\MimeTypeGuesserInterface;
use Symfony\Component\Mime\MimeTypes;
use Symfony\Component\Mime\MimeTypesInterface;

class MimeTypesTest extends TestCase
{
protected function getPackageProviders($app)
{
return [
MimeTypesServiceProvider::class,
];
}

/**
* @test
* @dataProvider serviceBindings
*/
public function it_can_instantiate_service(string $service): void
{
$this->assertInstanceOf(MimeTypes::class, $this->app->make($service));
}

public function serviceBindings(): array
{
return [
['laravel-mime'],
[MimeTypes::class],
[MimeTypesInterface::class],
[MimeTypeGuesserInterface::class],
];
}
}

0 comments on commit 2fd9086

Please sign in to comment.