Skip to content

Instantly share code, notes, and snippets.

<?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
// singleton
class FooApiClient
{
private function __construct();
public static function getInstance(): FooApiClient;
public function getBar(): Bar;
<?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 */
}
<?php
/**
* Simpler version of
* https://github.com/dddinphp/repository-examples/blob/master/src/Infrastructure/Persistence/Doctrine/DoctrinePostRepository.php#L64
*
* Thanks to using inheritance.
*/
namespace Infrastructure\Persistence\Doctrine;
@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>
@MacDada
MacDada / ShowBlogPostsController.php
Last active April 9, 2022 21:38
PHP: Use Case architecture example
<?php
class ShowBlogPostsController
{
/**
* @param ShowBlogPostUseCase
**/
private $useCase;
/**
<?php
namespace AppBundle\Form\DataTransformer;
use AppBundle\Entity\Entity;
use AppBundle\Entity\EntityRepository;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
class EntitiesToIdsDataTransformer implements DataTransformerInterface