Skip to content

Instantly share code, notes, and snippets.

@webdevilopers
webdevilopers / ConsoleExceptionListener.php
Last active Dec 11, 2017
Configure Symfony Monolog to send error emails when exceptions are thrown in console commands
View ConsoleExceptionListener.php
<?php
namespace Acme\Foo\Infrastructure\Symfony\AppBundle\Listener;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Event\ConsoleEvent;
use Symfony\Component\Console\ConsoleEvents;
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
use Symfony\Component\Console\Event\ConsoleTerminateEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@webdevilopers
webdevilopers / mongocollection.php
Created Mar 21, 2017
Cannot pass parameter 1 by reference with MongoCollection
View mongocollection.php
#$collection->insert(['id' => 1]); // Cannot pass parameter 1 by reference
$a = ['id' => 1];
$collection->insert($a);
@webdevilopers
webdevilopers / proop.yml
Created Mar 9, 2017
Implementing Event Store and Event Sourcing with Prooph in Symfony
View proop.yml
prooph_service_bus:
command_buses:
rewotec_command_bus:
plugins:
- 'prooph_event_store_bus_bridge.transaction_manager'
router:
type: 'prooph_service_bus.command_bus_router'
routes:
'Rewotec\PersonnelManagement\Application\Employee\SignEmploymentContract': 'rewotec.command.sign_employment_contract_handler'
event_buses:
@webdevilopers
webdevilopers / query.php
Created Feb 13, 2017
OutOfMemoryException in PDOConnection using Doctrine iterate result
View query.php
<?php
// 7041 rows with content being BLOB content - total table size ~ 2.4 GB
$instructionRepository = $this->getDoctrine()->getRepository('PlusquamContractBundle:Instruction');
$instructionQueryBuilder = $instructionRepository->createQueryBuilder('i')
->where('i.content IS NOT NULL')
->orderBy('i.id', 'desc');
$instructions = $instructionQueryBuilder->getQuery()->iterate();
?>
@webdevilopers
webdevilopers / AbstractDormerPriceQuote.php
Last active Oct 2, 2020
Symfony Assert Annotations using external Class constants
View AbstractDormerPriceQuote.php
<?php
namespace Sps\Bundle\PriceQuoteBundle\Entity;
abstract class AbstractDormerPriceQuote
extends PriceQuoteRequest
{
const MIN_ROOF_PITCH = 10;
const MAX_ROOF_PITCH = 55;
}
@webdevilopers
webdevilopers / PriceQuoteRequest.php
Last active Dec 3, 2016
Doctrine Single Table Inheritance working with YAML service configuration but not XML
View PriceQuoteRequest.php
<?php
namespace Sps\Bundle\PriceQuoteBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* PriceQuoteRequest
*
* @ORM\Entity(repositoryClass="Sps\PriceQuote\Infrastructure\Persistence\Doctrine\DoctrinePriceQuoteRepository")
@webdevilopers
webdevilopers / RecordResultForm.php
Last active Aug 13, 2020
Dynamically add Elements to Symfony Form Collection without Data
View RecordResultForm.php
<?php
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
final class RecordResult extends AbstractType
@webdevilopers
webdevilopers / CustomerInformation.php
Last active Sep 27, 2016
How to pass options from resolver to Symfony Form Event
View CustomerInformation.php
<?php
class CustomerInformation extends AbstractType
{
/**
* @var Translator $translator
*/
private $translator;
public function __construct(
@webdevilopers
webdevilopers / Repository.php
Last active Jul 3, 2016
Doctrine DQL error with COUNT in CASE
View Repository.php
<?php
$dql = "SELECT NEW
Acme\DomainModel\InspectionResult\ResultDetails(
e.id, e.date,
GroupConcat(DISTINCT e.comment),
CASE WHEN COUNT(bps_ok.id) = 0 THEN 1 ELSE COUNT(bps_ok.id) / COUNT(DISTINCT bps_ok.id)
)
FROM AppBundle\Entity\Bundle e
LEFT JOIN e.parttypeStateOk bps_ok
@webdevilopers
webdevilopers / ChangeInspectionDetails.php
Last active Jun 24, 2016
Using PHP7 type hinting with Symfony Form Text Type and empty_data returning NULL
View ChangeInspectionDetails.php
<?php
class ChangeInspectionDetails extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('problemNumber', TextType::class, [
'empty_data' => '' // no effect
]);