Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
webdevilopers / DormerCalculationController.php
Last active Feb 3, 2019
Catching domain exceptions when using value objects with data transformers in Symfony forms
View DormerCalculationController.php
<?php
namespace Acme\DormerCalculation\Infrastructure\Symfony\DormerCalculationBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Acme\DormerCalculation\Infrastructure\Symfony\DormerCalculationBundle\Form\DormerCalculation as CalculationForm;
use Acme\DormerCalculation\Domain\Model\DormerCalculation\Command\CalculateDormerCommand;
use Symfony\Component\Form\FormError;
@webdevilopers
webdevilopers / ResourceProjection.php
Last active May 20, 2018
Prooph Event Sourcing with Symfony Flex
View ResourceProjection.php
<?php
namespace Acme\Infrastructure\Projection\Resource;
use Prooph\Bundle\EventStore\Projection\ReadModelProjection;
use Prooph\EventStore\Projection\ReadModelProjector;
use Acme\Domain\Model\Resource\Event\PhotoUploaded;
use Acme\Domain\Model\Resource\Event\ResourceAcquired;
/**
@webdevilopers
webdevilopers / placeholder.js
Last active May 8, 2018
Prevent extra space from line break when adding text at then end of a too small textarea
View placeholder.js
function placeholder2text(textElementId, text)
{
var textElement = document.getElementById(textElementId);
if(textElement.createTextRange && textElement.caretPos)
{
var caretPos = textElement.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
textElement.focus();
}
@webdevilopers
webdevilopers / DefaultController.php
Last active Oct 31, 2020
Sending JWT Token in Guzzle POST with LexikJWTAuthenticationBundle
View DefaultController.php
<?php
namespace AppBundle\Controller;
class DefaultController extends Controller
{
/**
* @Route("/gettoken")
*/
public function getToken()
@webdevilopers
webdevilopers / Photo.mongodb.xml
Created Mar 16, 2018
Mapping file uploads with Doctrine MongoDB ODM
View Photo.mongodb.xml
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mongo-mapping xmlns="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping
http://doctrine-project.org/schemas/odm/doctrine-mongo-mapping.xsd">
<document name="Acme\Domain\Model\Photo\Photo" collection="photos">
<field fieldName="_id" id="true" />
<field fieldName="galleryId" type="string" />
<field fieldName="description" type="string" />
@webdevilopers
webdevilopers / composer.json
Created Mar 12, 2018
Custom Acme namespaces with Symfony Flex
View composer.json
{
"type": "project",
"license": "proprietary",
"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"symfony/console": "^4.0",
"symfony/flex": "^1.0",
"symfony/framework-bundle": "^4.0",
"symfony/lts": "^4@dev",
@webdevilopers
webdevilopers / OfferNumberGenerator.php
Created Mar 3, 2018
Making domain services testable
View OfferNumberGenerator.php
<?php
namespace Sps\Intranet\Domain\Model\Offer;
use Sps\Intranet\Domain\Model\Partner\PartnerId;
use Sps\Intranet\Infrastructure\Projection\Mongo\OfferReadModelFinder;
/**
* Class OfferNumberGenerator
* @package Sps\Intranet\Domain\Model\Offer
View Partner.php
<?php
/*
* @ORM\Entity()
*/
class Partner
{
/**
* @var PartnerOfferItem[] $offerItems
* @ORM\OneToMany(targetEntity="Sps\Bundle\BaseBundle\Entity\PartnerOfferItem", mappedBy="partner", indexBy="price_id", fetch="EAGER", orphanRemoval=true)
@webdevilopers
webdevilopers / AssignEmployeeHandler.php
Created Jan 12, 2018
Command Handling Policy / Strategy Pattern in Application Services
View AssignEmployeeHandler.php
<?php
namespace Rewotec\TimeTracking\Application\Employee;
use Rewotec\TimeTracking\Domain\Model\Employee\AssignableJobFunctionPolicy;
use Rewotec\TimeTracking\Domain\Model\Employee\Employee;
use Rewotec\TimeTracking\Domain\Model\Employee\EmployeeRepository;
/**
* Class AssignEmployeeHandler
@webdevilopers
webdevilopers / LookupService.php
Last active Jan 4, 2018
Run ReactPHP Event Loop with database query and return Promise
View LookupService.php
<?php
namespace Acme\FooApplication\OfferLetter;
use React\EventLoop\Timer\Timer;
use React\Promise\Deferred;
use Acme\Foo\Domain\Model\Offer\OfferId;
use React\EventLoop\Factory;
use Acme\Foo\Infrastructure\Projection\Mongo\OfferOverviewFinder;