Skip to content

Instantly share code, notes, and snippets.

{# what is the proper way to escape var in url path in html in twig? #}
{# method A #}
<a href="/foo/{{ bar }}">Link</a>
{# method B #}
<a href="/foo/{{ bar|e('url') }}">Link</a>
{# method C #}
@MacDada
MacDada / ViewItemUseCase.php
Last active November 20, 2016 20:55
Authorization and Use Cases: option 1: authorization inside Use Case
<?php
namespace Foo\Bar\Application\UseCase;
use Foo\Bar\Application\AuthorizationChecker;
use Foo\Bar\Domain\ItemRepository;
class ViewItemUseCase
{
/**
<?php
class Order
{
public $user1;
public $user2;
}
@MacDada
MacDada / AuthenticationSuccessHandler.php
Last active September 18, 2016 23:55
Symfony AuthenticationSuccessHandler
<?php
namespace AppBundle\Security;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\Common\Persistence\ObjectManager;
use AppBundle\Entity\User;
use AppBundle\Entity\UserHasLoggedIn;
<?php
public function testInterval()
{
$date = new DateTime('+1 month');
$date->add(\DateInterval::createFromDateString('3 months'));
// Tested on 2016-08-31
// Failed asserting that two DateTime objects are equal.
<?php
// warstwa aplikacji – tutaj udostępniamy co aplikacja może zrobić
namespace CalculatorCompany\CalculatorProject\Application;
class AddNumbersUseCase
{
public function handle($firstNumber, $secondNumber)
{
$result = $this->calculator->add($firstNumber, $secondNumber);
@MacDada
MacDada / steemit-stylish.css
Created July 27, 2016 16:09
Stylish for visited links on steemit.com
.PostSummary__header > h1 > a:visited, /* articles feed */
article[itemtype="http://schema.org/blogPost"] a:visited, /* article content */
.entry-content a:visited { /* comments */
color: #76B; /* kinda violet, feel free to change it */
}
@MacDada
MacDada / composition.php
Last active May 15, 2016 12:33
PHP OOP reuse with composition, inheritance and traits
<?php
class BasicStuff
{
public function foo()
{
/* does basic stuff */
}
}
<?php
$client = new GuzzleHttp\Client();
$response = $client->request('POST', 'http://localhost:8000/hello/world', [
'form_params' => [
'name' => 'Norbert',
],
'timeout' => 30,
]);
<!DOCTYPE html>
<html>
<body>
<script async src="test.js"></script>
<script>
helloFromTestJs('ok');
</script>
</body>
</html>