-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1bf8105
commit b352881
Showing
23 changed files
with
514 additions
and
244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
<?php | ||
|
||
// specify the paths to fix, as normal... | ||
|
||
$finder = PhpCsFixer\Finder::create() | ||
->in(__DIR__.'/src') | ||
->in(__DIR__.'/tests'); | ||
|
||
return TiMacDonald\styles($finder); | ||
// then call and return the following global function... | ||
|
||
return TiMacDonald\styles($finder); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TiMacDonald\Multiformat\Checkers\Concerns; | ||
|
||
use function preg_match; | ||
|
||
trait DetectValidMethodStrings | ||
{ | ||
private static function doesntContainAnyValidMethodCharacters(string $characters): bool | ||
{ | ||
return ! self::containsSomeValidMethodCharacters($characters); | ||
} | ||
|
||
private static function containsSomeValidMethodCharacters(string $characters): bool | ||
{ | ||
return preg_match('/[a-zA-Z0-9_\\x80-\\xff]/', $characters) === 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TiMacDonald\Multiformat\Contracts; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
interface FallbackResponse | ||
{ | ||
public function __invoke(Request $request, object $response): callable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TiMacDonald\Multiformat\Contracts; | ||
|
||
use Illuminate\Support\Collection; | ||
|
||
interface TypesToCallback | ||
{ | ||
public function __invoke(Collection $options): callable; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TiMacDonald\Multiformat\Functions; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Http\Response; | ||
use function method_exists; | ||
use TiMacDonald\Multiformat\Contracts\FallbackResponse as FallbackResponseContract; | ||
|
||
class FallbackResponse implements FallbackResponseContract | ||
{ | ||
public function __invoke(Request $request, object $response): callable | ||
{ | ||
return static function () use ($request, $response) { | ||
if (method_exists($response, 'unsupportedResponse')) { | ||
return $response->unsupportedResponse($request); | ||
} | ||
|
||
return new Response(null, 406); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TiMacDonald\Multiformat\Functions; | ||
|
||
use Symfony\Component\Mime\MimeTypes; | ||
use TiMacDonald\Multiformat\Contracts\MimeToType as MimeToTypeContract; | ||
|
||
class MimeToType implements MimeToTypeContract | ||
{ | ||
/** | ||
* @var MimeTypes | ||
*/ | ||
private $mimeTypes; | ||
|
||
public function __construct(MimeTypes $mimeTypes) | ||
{ | ||
$this->mimeTypes = $mimeTypes; | ||
} | ||
|
||
public function __invoke(string $mime): ?string | ||
{ | ||
return $this->mimeTypes->getExtensions($mime)[0] ?? null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace TiMacDonald\Multiformat\Functions; | ||
|
||
use function app; | ||
use function assert; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Collection; | ||
use function is_callable; | ||
use TiMacDonald\Multiformat\Contracts\TypeCheck as TypeCheckContract; | ||
use TiMacDonald\Multiformat\ResponseType; | ||
|
||
class TypeCheck implements TypeCheckContract | ||
{ | ||
public function __invoke(Request $request, array $checkers): Collection | ||
{ | ||
return Collection::make($checkers) | ||
->map( | ||
/** @param callable|string $checker */ | ||
static function ($checker): callable { | ||
if (is_callable($checker)) { | ||
return $checker; | ||
} | ||
|
||
$checker = app()->make($checker); | ||
|
||
assert(is_callable($checker)); | ||
|
||
return $checker; | ||
} | ||
)->map(static function (callable $checker) use ($request): ResponseType { | ||
$responseTypes = $checker($request); | ||
|
||
assert($responseTypes instanceof ResponseType); | ||
|
||
return $responseTypes; | ||
}); | ||
} | ||
} |
Oops, something went wrong.