1. Go to this page and download the library: Download krasnikov/ddd-core library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
krasnikov / ddd-core example snippets
declare(strict_types=1);
namespace App\Domain\Auth;
use Krasnikov\DDDCore\BaseModel;
class AuthToken extends BaseModel
{
}
declare(strict_types=1);
namespace App\Domain\User;
use Illuminate\Database\Eloquent\Model;use Krasnikov\DDDCore\BaseModel;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Krasnikov\DDDCore\Uuid;
use Laravel\Lumen\Auth\Authorizable;
use Spatie\Permission\Traits\HasRoles;
class User extends Model implements AuthenticatableContract, AuthorizableContract
{
use Authenticatable;
use Authorizable;
use HasRoles;
use Uuid;
}
namespace App\Http\Controllers;
use Krasnikov\DDDCore\Command;
use Krasnikov\DDDCore\CommandBusInterface;
use Laravel\Lumen\Routing\Controller as BaseController;
/**
* Class Controller
* @package App\Http\Controllers
*/
class Controller extends BaseController
{
/**
* @var CommandBusInterface
*/
private $dispatcher;
/**
* Controller constructor.
* @param CommandBusInterface $dispatcher
*/
public function __construct(CommandBusInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
}
/**
* @param Command $command
* @return mixed
*/
public function execute(Command $command)
{
return $this->dispatcher->dispatch($command);
}
}
declare(strict_types=1);
namespace App\Application\Dashboard\Role\GetRoleList;
use Krasnikov\DDDCore\Command;
/**
* Class GetRoleList
* @package App\Application\Dashboard\Role
*/
class GetRoleList implements Command
{}
declare(strict_types=1);
namespace App\Application\Dashboard\Role\GetRoleList;
use Krasnikov\DDDCore\Command;
use Krasnikov\DDDCore\Handler;
/**
* Class GetRoleListHandler
* @package App\Application\Dashboard\Role\GetRoleList
*/
class GetRoleListHandler implements Handler
{
/**
* @param Command|GetRoleList $command
*/
public function handle(Command $command): void
{
// same code
}
}
/**
* @param Request $request
* @return JsonResponse
* @throws ValidationException
*/
public function index(Request $request): JsonResponse
{
$res = $this->execute(GetRoleList::fromRequest($request));
return new JsonResponse($res);
}
declare(strict_types=1);
namespace App\Domain\Auth;
use Krasnikov\DDDCore\RepositoryInterface;
use Krasnikov\DDDCore\Sorting;
use App\Domain\User\UserRepositoryInterface;
/**
* Class AuthTokenRepositoryInterface
* @package App\Domain\Auth
*/
interface AuthTokenRepositoryInterface extends RepositoryInterface
{
/**
* @param AuthTokenFilter $filter
* @return $this
*/
public function filter(AuthTokenFilter $filter): self;
}
declare(strict_types=1);
namespace App\Infrastructure\Persists\PostgresRepository;
use App\Domain\Auth\AuthToken;
use App\Domain\Auth\AuthTokenFilter;
use App\Domain\Auth\AuthTokenNotFoundException;
use App\Domain\Auth\AuthTokenRepositoryInterface;
use Krasnikov\DDDCore\AbstractPostgresRepository;
/**
* Class EloquentAuthTokenRepository
* @package App\Infrastructure\Persists\EloquentRepository
*/
class PostgresAuthTokenRepository extends AbstractPostgresRepository implements AuthTokenRepositoryInterface
{
/**
* PostgresAuthTokenRepository constructor.
*/
public function __construct()
{
$this->model = new AuthToken();
$this->exceptionNotFound = AuthTokenNotFoundException::class;
}
/**
* @inheritDoc
*/
public function filter(AuthTokenFilter $filter): AuthTokenRepositoryInterface
{
$this->makeBuilder();
//some code
return $this;
}
}
declare(strict_types=1);
namespace App\Infrastructure\Persists\ArrayRepository;
use App\Domain\{Auth\AuthTokenFilter,Auth\AuthTokenRepositoryInterface};
use Krasnikov\DDDCore\AbstractArrayRepository;
/**
* Class ArrayAuthTokenRepository
* @package App\Infrastructure\Persists\ArrayRepository
*/
class ArrayAuthTokenRepository extends AbstractArrayRepository implements AuthTokenRepositoryInterface
{
/**
* ArrayAuthTokenRepository constructor.
*/
public function __construct()
{
parent::__construct();
$this->exceptionNotFound = AuthTokenNotFoundException::class;
}
/**
* @inheritDoc
*/
public function filter(AuthTokenFilter $filter): AuthTokenRepositoryInterface
{
$result = $this->seed;
if ($this->result->count()) {
$result = $this->result;
}
//some code
$this->result = $result;
return $this;
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.