Skip to content

Instantly share code, notes, and snippets.

@teklakct
teklakct / Controller.php
Last active May 15, 2017 18:26
Symfony 2.5 profiler a Behat 3
<?php
namespace Bundle\WebsiteBundle\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouterInterface;
@teklakct
teklakct / gist:17c6e94fddfb8ab0a86a
Created January 8, 2015 07:57
fosrest i nelmiocors
fos_rest:
routing_loader:
default_format: json
include_format: false
param_fetcher_listener: true
body_converter:
enabled: true
serializer:
groups: ['Default']
body_listener: true
<?php
namespace Acme\DemoBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class AcmeDemoBundle extends Bundle
{
}
@teklakct
teklakct / StringsCompare.php
Created July 17, 2015 07:57
Strings comparision and check variable is set
<?php
class StringsCompare
{
public function compareStringsStrtoupper($method, $options)
{
if (strtoupper($method) == 'POST'
&& !isset($options['body'])
&& !isset($options['json'])
) {
@teklakct
teklakct / Person.php
Last active January 16, 2016 15:16
Przykładowa specyfikacja do opisania zachowania Named Constructors wykorzystując PHPSpec
<?php
class Person
{
private $name;
private $surname;
private function __construct($name, $surname)
{
$this->name = $name;
@teklakct
teklakct / MySubscriber.php
Created August 2, 2016 09:57
Subscriber for Sculpin
<?php
namespace Bundle\MyBundle;
use Sculpin\Core\Event\SourceSetEvent;
use Sculpin\Core\Sculpin;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class MySubscriber implements EventSubscriberInterface
{
/**
@teklakct
teklakct / exceptionHandler.php
Created June 1, 2017 10:46
GuzzleRequestExceptionHandler
<?php
private function exceptionHandler(GuzzleRequestException $e)
{
if ($e->hasResponse()) {
if ($e->getResponse()->getStatusCode() >= 500) {
throw $e;
}
$error = json_decode($e->getResponse()->getBody()->getContents(), true);
if (isset($error['errors'])) {
@teklakct
teklakct / CommandValidator.php
Created September 26, 2017 10:50
Symfony callback validator
<?php
namespace Acme;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
class CommandValidator
{
public static function validate($object, ExecutionContextInterface $context)
@teklakct
teklakct / Clock.php
Last active November 1, 2018 19:31
Simple example why you should make an interface over DateTime
<?php
declare(strict_types=1);
interface Clock
{
public function now(): \DateTimeInterface;
}
<?php
declare(strict_types=1);
namespace My\Infrastructure\DoctrineAdapter;
use Doctrine\Common\Persistence\ObjectRepository;
use Doctrine\ORM\EntityManagerInterface;
use My\Domain\FinalGreetingRepository;
use My\Domain\Model\FinalGreeting;