Skip to content

Instantly share code, notes, and snippets.

View DarkGhostHunter's full-sized avatar
👨‍💻
Hands full

Italo DarkGhostHunter

👨‍💻
Hands full
View GitHub Profile
@DarkGhostHunter
DarkGhostHunter / preload.php
Created November 27, 2019 05:21
A sample preload file
<?php
// Get the list of files of the main directory and remove the dots
$files = array_diff(scandir(__DIR__ . '/src/'), array('..', '.'));
// Add the helpers file
$files[] = 'helpers/helpers.php';
return $files;
@DarkGhostHunter
DarkGhostHunter / composer.json
Last active November 27, 2019 05:40
Composer JSON with preloadin
{
"name": "application/project",
"description": "This is my root project.",
"require": {
"php": "^7.2",
"ext-json": "*",
"symfony/http-client": "5.*",
"symfony/console": "5.*"
},
"autoload": {
@DarkGhostHunter
DarkGhostHunter / Manager.php
Created November 17, 2019 21:04
Latest 6.x version of the Laravel Manager Class.
<?php
namespace Illuminate\Support;
use Closure;
use Illuminate\Contracts\Container\Container;
use InvalidArgumentException;
abstract class Manager
{
@DarkGhostHunter
DarkGhostHunter / DeliveryController.php
Created November 17, 2019 19:58
An example Controller where a Manager gets called to deliver a package in one line.
<?php
namespace App\Http\Controllers;
use App\Package;
use App\Managers\TransportManager;
class DeliveryController extends Controller
{
/**
@DarkGhostHunter
DarkGhostHunter / TransportManager.php
Last active November 17, 2019 19:46
An example about using the Manager abstract class that comes with Laravel.
<?php
namespace App\Managers;
use App\Transport\Car\Car;
use App\Transport\Car\CarWheels;
use App\Transport\Car\FuelEngine;
use App\Transport\Car\Chassis;
use App\Transport\Bicycle\Bicycle;
use App\Transport\Bicycle\BicycleWheel;
@DarkGhostHunter
DarkGhostHunter / CachesResponses.php
Last active December 11, 2019 02:04
A trait to cache responses or part of the controller logic.
<?php
namespace App\Http\Helpers;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
trait CachesResponses
{
@DarkGhostHunter
DarkGhostHunter / ValidateSignature.php
Created October 25, 2019 15:50
Validates the Signature and consumes it
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Carbon;
use Illuminate\Cache\CacheManager as Cache;
use Illuminate\Routing\Exceptions\InvalidSignatureException;
use Illuminate\Routing\Middleware\ValidateSignature as BaseMiddleware;
@DarkGhostHunter
DarkGhostHunter / ShareByEmailController.php
Last active October 20, 2019 05:23
A given controller
<?php
namespace App\Http\Controllers\Podcast;
use App\Podcast;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Lang;
use App\Http\Helpers\ThrottlesRequests;
use Illuminate\Validation\ValidationException;
@DarkGhostHunter
DarkGhostHunter / ThrottlesRequests.php
Last active November 2, 2019 14:58
An universal and easy copy-pasteable Throttler for Controllers
<?php
namespace App\Http\Helpers;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Cache\RateLimiter;
use Illuminate\Support\Facades\Lang;
use Illuminate\Validation\ValidationException;
<?php
namespace App\Helpers;
use Illuminate\Support\Str;
use Illuminate\Support\HigherOrderTapProxy;
class InfiniteHigherOrderTapProxy extends HigherOrderTapProxy
{
/**