Skip to content

Instantly share code, notes, and snippets.

webDEVILopers webdevilopers

Block or report user

Report or block webdevilopers

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@webdevilopers
webdevilopers / DefaultGridFSRepository.php
Last active Jan 18, 2020
Uploading Files with Metadata using MongoDB GridFS in a PHP Domain-Driven Design application
View DefaultGridFSRepository.php
<?php
class DefaultGridFSRepository extends DocumentRepository implements GridFSRepository
{
public function uploadFromStream(string $filename, $source, ?UploadOptions $uploadOptions = null)
{
$options = $this->prepareOptions($uploadOptions);
$databaseIdentifier = $this->getDocumentBucket()->uploadFromStream($filename, $source, $options);
$documentIdentifier = $this->class->getPHPIdentifierValue($databaseIdentifier);
@webdevilopers
webdevilopers / functions.php
Created Jan 11, 2020
How to convert PHP MongoDB BSON Binary to (L)UUID or ObjectId
View functions.php
<?php
use MongoDB\BSON\Binary;
use MongoDB\BSON\ObjectId;
function mongoBinaryToUuid(Binary $bin): string
{
$hex = bin2hex($bin->getData());
return substr($hex, 0, 32);
@webdevilopers
webdevilopers / MaterialQuantityDto.php
Created Nov 29, 2019
Dynamic form validation groups with callback in Symfony 2.8
View MaterialQuantityDto.php
<?php
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
class MaterialQuantityDto
{
/**
* @var string
* @Assert\NotNull(groups={"available_material"})
@webdevilopers
webdevilopers / JsonObject.php
Created Apr 15, 2019
UPDATE and INSERT statements with Doctrine DBAL and MySQL JSON type
View JsonObject.php
<?php
class JsonObject
{
/** @var string $result */
private $result;
private function __construct(string $result)
{
$this->result = $result;
@webdevilopers
webdevilopers / DoctrineGutterColorRepository.php
Last active Mar 10, 2019
Using Value Objects as Custom Doctrine DBAL Type as Identifier in Symfony
View DoctrineGutterColorRepository.php
<?php
namespace Sps\DormerCalculation\Infrastructure\Persistence\Doctrine;
use Doctrine\ORM\EntityRepository;
/**
* Class DoctrineGutterColorRepository
* @package Sps\DormerCalculation\Infrastructure\Persistence\Doctrine
*/
@webdevilopers
webdevilopers / DormerType.php
Created Feb 25, 2019
Using Entity as Factory for Value Object
View DormerType.php
<?php
abstract class DormerType implements DormerTypeInterface
{}
@webdevilopers
webdevilopers / OfferFactory_v1.php
Last active Feb 20, 2019
DDD Domain Service vs Domain Factory vs. Double Dispatch
View OfferFactory_v1.php
<?php
final class OfferFactory
{
/** @var ChargeRatesFactory $chargeRatesFactory */
private $chargeRatesFactory;
/** @var PricesCalculator $pricesCalculator */
private $pricesCalculator;
@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();
}
You can’t perform that action at this time.