Skip to content

Instantly share code, notes, and snippets.

View wowo's full-sized avatar

Wojciech Sznapka wowo

View GitHub Profile
<?php
final class EmailValueObject
{
private $mailbox;
private $host;
public function __construct($email)
{
if (false === strpos($email, '@')) {
@wowo
wowo / pre-commit
Last active February 3, 2025 14:43
Basic pre-commit git hook
#!/bin/bash
exec < /dev/tty
phpunit
rc=$?
if [[ $rc != 0 ]] ; then
echo -n "It looks like some of your tests failed. "
exit $rc;
fi
@wowo
wowo / api.php
Created August 28, 2015 12:52
Simple api to capture and test API callbacks
<?php
$log = __DIR__ . '/api.log';
if ('POST' == $_SERVER['REQUEST_METHOD']) {
$payload = json_decode(file_get_contents('php://input'), true) ?: $_POST;
file_put_contents(
$log,
sprintf(
"[%s] (%s - %s) %s\n",
(new \DateTime())->format('Y-m-d H:i:s'),
$poundToEuro = (float) simplexml_load_file('https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml')->xpath("//*[@currency='GBP']")[0]['rate'];
@wowo
wowo / composer.json
Last active September 3, 2019 19:38
log-demo
{
"name": "wowo/log-demo",
"type": "project",
"require": {
"monolog/monolog": "^2.0"
},
"authors": [
{
"name": "Wojciech Sznapka",
"email": "[email protected]"
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="[..]">
<parameters>
<parameter key="example.foo.repository.class">
Example\FooBundle\Repository\FooRepository</parameter>
<parameter key="example.foo.service.class">
Example\FooBundle\Service\FooService</parameter>
</parameters>
<?php
namespace Example\FooBundle\Repository;
use Doctrine\ORM\EntityRepository;
class FooRepository extends EntityRepository
implements FooRepositoryInterface
{
public function fetchLatest()
<?php
namespace Example\FooBundle\Service;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
class FooService
{
protected $fooRepository;
<?php
namespace Example\FooBundle\Repository;
use Doctrine\Common\Persistence\ObjectRepository;
interface FooRepositoryInterface extends ObjectRepository
{
public function fetchLatest();
}
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="[..]">
<parameters>
<parameter key="example.foo.repository.class">
Example\FooBundle\Repository\FooRepository</parameter>
<parameter key="example.foo.service.class">
Example\FooBundle\Service\FooService</parameter>
</parameters>