Skip to content

Instantly share code, notes, and snippets.

View nikolaposa's full-sized avatar

Nikola Poša nikolaposa

View GitHub Profile
@nikolaposa
nikolaposa / BeanstalkdWorker.php
Last active October 17, 2018 08:56
Beanstalkd queue worker
<?php
declare(strict_types=1);
namespace My\Queue;
use Pheanstalk\Pheanstalk;
use Exception;
class BeanstalkdWorker
@nikolaposa
nikolaposa / decoration.php
Last active December 2, 2020 16:30
New PHP language feature; favor composition over inheritance; `decorates` and `inner` keywords
<?php
declare(strict_types=1);
interface UserRepositoryInterface
{
public function find(string $id) : User;
public function findAll() : UserCollection;
}

Keybase proof

I hereby claim:

  • I am nikolaposa on github.
  • I am nikolaposa (https://keybase.io/nikolaposa) on keybase.
  • I have a public key ASBwX4wR9MDEXOGIyprtB7YMxKGlYYG1MFmxjtRAzk4Lawo

To claim this, I am signing this object:

@nikolaposa
nikolaposa / BirthDate.php
Last active June 26, 2018 15:32
Person entity with mandatory birthdate that can either be set or uknown
<?php
final class BirthDate
{
private $date;
private function __construct(\DateTimeInterface $date = null)
{
$this->date = $date;
}
@nikolaposa
nikolaposa / PaidOrdersView.php
Last active August 19, 2019 07:50
Read model View that additionaly handles events to updates its state
<?php
declare(strict_types=1);
final class PaidOrdersView implements HandlesEvents
{
private $dao;
public function __construct(OrderDao $dao)
{
@nikolaposa
nikolaposa / Dependencies.php
Last active March 5, 2019 10:38
Hand-writen DI Container
<?php
declare(strict_types=1);
namespace My;
use Psr\Container\ContainerInterface;
final class Dependencies implements ContainerInterface
{
@nikolaposa
nikolaposa / EmailAddress.php
Created March 7, 2019 18:39
Email Address VO
<?php
declare(strict_types=1);
namespace My\Model;
final class EmailAddress implements ValueObject
{
/** @var string */
private $email;
@nikolaposa
nikolaposa / rich_domain_model.php
Created August 19, 2019 07:56
Demonstrates the use of Method Injection technique to capture key bussiness logic in the entity itself.
<?php
declare(strict_types=1);
final class AnonymizeData
{
private $payload;
public function __construct(array $payload)
{