Skip to content

Instantly share code, notes, and snippets.

View ChubV's full-sized avatar

Volodymyr Chub ChubV

View GitHub Profile
<?php
class DateToStringTransformer implements DataTransformerInterface
{
/**
* @param mixed $value
* @return mixed|void
*/
public function transform($value)
{
if (!$value) {
@ChubV
ChubV / CroppedThumbFilterLoader.php
Created November 1, 2012 19:11
Cropped thumbnail filter
<?php
namespace ChubProduction\Bundle\SiteBundle\Imagine;
use Imagine\Image\Box;
use Imagine\Image\Point;
use Imagine\Filter\Transformation;
use Avalanche\Bundle\ImagineBundle\Imagine\Filter\Loader\LoaderInterface;
use Imagine\Image\ManipulatorInterface;
/**
<?php
namespace NSBundle\Repo;
use Symfony\Component\DependencyInjection\Container;
class MyRepository
{
public function __construct(Container $c)
{
@ChubV
ChubV / FormType.php
Created November 29, 2012 07:56
Set form values after bind
class FormType extends AbstractType
{
// ....
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('field')
->add(....)
->addEventListener(FormEvents::POST_BIND, array($this, 'postBind'));
}
@ChubV
ChubV / PaginationSubscriber.php
Last active December 11, 2015 07:08
Add DBAL QueryBuilder support for KnpPaginatorBundle
<?php
namespace ChubV\ToolkitBundle\Subscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Knp\Component\Pager\Event\ItemsEvent;
use Doctrine\DBAL\Query\QueryBuilder;
class PaginationSubscriber implements EventSubscriberInterface
{
public function items(ItemsEvent $event)
@ChubV
ChubV / twig.yml
Created June 26, 2013 04:31
Twig string
services:
mine.twig_string_loader:
class: "Twig_Loader_String"
mine.twig_string:
class: "%twig.class%"
arguments: [@mine.twig_string_loader, %twig.options% ]

Application level restrictions and domain contracts check.

Validation and all kinds of restrictions may be significant part of your application. And it is important to understand the difference between application level restrictions and domain contracts checks. So in this article I'm going to share my view on validation. It will be helpful for those who started practicing domain-driven design principles in their projects, but still too coupled in their minds to framework/application style of developing.

@ChubV
ChubV / TwigExtensionTestCase.php
Created July 10, 2013 08:57
Twig extension test case
<?php
namespace ChubProduction\Bundle\XXXBundle\Tests;
/**
* TwigExtensionTestCase
*
* @author Vladimir Chub <v@chub.com.ua>
*/
trait TwigExtensionTestCase
{
@ChubV
ChubV / Paypal.php
Created July 20, 2018 03:36
NotifyUrl workaround
<?php
$agreement = new HackAgreement();
// ...
$agreement->create($apiContext);
////////////
use PayPal\Api\Agreement;
<?php
class Foo
{
private $foo;
private $bar;
private $baz;
}
$hydrator = function(array $data) {