Skip to content

Instantly share code, notes, and snippets.

View mansha99's full-sized avatar

Manish Sharma mansha99

View GitHub Profile
@mansha99
mansha99 / Solr.postman_collection.json
Created August 13, 2023 09:13
Postman collection for Apache Solr steps
{
"info": {
"_postman_id": "ec150c09-8955-48d4-b682-7d27d09c7a08",
"name": "Solr",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "353871"
},
"item": [
{
"name": "01-collection-employee",
@mansha99
mansha99 / GetGithubUserCommand.php
Created August 11, 2023 17:53
Console Command as Client
<?php
namespace App\Console\Commands;
use App\Services\GithubUserService;
use Illuminate\Console\Command;
class GetGithubUserCommand extends Command
{
protected $signature = 'app:github-user {username}';
@mansha99
mansha99 / GithubUserController.php
Created August 11, 2023 17:52
Http Controller as Client Component
<?php
namespace App\Http\Controllers;
use App\Http\Requests\GithubUserRequest;
use App\Services\GithubUserService;
class GithubUserController extends Controller
{
private GithubUserService $githubUserService;
@mansha99
mansha99 / GithubUserTransformer.php
Created August 11, 2023 17:51
Fractal Transformer
<?php
namespace App\Transformers;
use League\Fractal\TransformerAbstract;
class GithubUserTransformer extends TransformerAbstract
{
public function transform($record)
{
@mansha99
mansha99 / GithubUserService.php
Created August 11, 2023 17:50
Service using Repo
<?php
namespace App\Services;
use App\Contracts\GithubUserRepo;
use App\Transformers\GithubUserTransformer;
use Exception;
class GithubUserService
@mansha99
mansha99 / GithubUserRepoHttpImpl.php
Created August 11, 2023 17:49
Repository implementation
<?php
namespace App\Repos;
use App\Contracts\GithubUserRepo;
use Exception;
use Illuminate\Support\Facades\Http;
class GithubUserRepoHttpImpl implements GithubUserRepo
{
@mansha99
mansha99 / GithubUserRepo.php
Created August 11, 2023 17:48
Repository interface
<?php
namespace App\Contracts;
interface GithubUserRepo
{
public function getUser(string $username);
}
@mansha99
mansha99 / GithubUserService.php
Created August 11, 2023 17:28
Dependency injection : Interfaces
<?php
class GithubUserService
{
private GithubUserRepoInterface $githubUserRepo;
public function __construct(GithubUserRepoInterface $githubUserRepo)
{
$this->githubUserRepo = $githubUserRepo;
}
}
@mansha99
mansha99 / GithubUserController.php
Created August 11, 2023 17:27
Dependency injection via constructor
<?php
class GithubUserController extends Controller
{
private GithubUserService $githubUserService;
public function __construct(GithubUserService $githubUserService)
{
$this->githubUserService = $githubUserService;
}
}
@mansha99
mansha99 / VehicleSearchController.php
Created August 11, 2023 17:23
Exposing Implementation through interface
<?php
namespace App\Http\Controllers;
class VehicleSearchController extends Controller
{
public function searchVehicle(VehicleSearchRequest $request)
{
$data = $request->validated();
//Instantiate