Skip to content

Instantly share code, notes, and snippets.

Avatar

Wojciech Sznapka wowo

View GitHub Profile
@wowo
wowo / gender-module-installation.sh
Last active May 5, 2021
Guesing gender based on name in PHP
View gender-module-installation.sh
# install gender http://www.php.net/manual/en/book.gender.php
sudo apt-get install libpcre3-dev
sudo pecl install gender
# generate data
mkdir ~/gender
sudo pear run-scripts pecl/gender
# eneble module
echo 'extension=gender.so' >> /etc/php5/cli/php.ini
View sample-log.json
{
"time": "2020-09-13 15:45:00",
"level": "info",
"channel": "main",
"message": "Some log entry has been produced"
}
@wowo
wowo / IsolatedTestsTrait.php
Last active Sep 11, 2020
IsolatedTestsTrait helps with running functional/integration tests in isolation, with same start state for each test. It's also optimized, keeping in mind performance concerns.
View IsolatedTestsTrait.php
<?php
namespace Acme\Example\Tests;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Doctrine\DBAL\Driver\PDOSqlite\Driver as PDOSqliteDriver;
require_once(__DIR__ . IsolatedTestsTrait::$kernelRootDir . '/AppKernel.php');
View service.php
<?php
namespace Example\FooBundle\Service;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
class FooService
{
protected $fooRepository;
View repo2.php
<?php
namespace Example\FooBundle\Repository;
use Doctrine\ORM\EntityRepository;
class FooRepository extends EntityRepository
{
}
View di2.xml
<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>
View interface.php
<?php
namespace Example\FooBundle\Repository;
use Doctrine\Common\Persistence\ObjectRepository;
interface FooRepositoryInterface extends ObjectRepository
{
public function fetchLatest();
}
View class.php
<?php
namespace Example\FooBundle\Service;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
class FooService
{
protected $fooRepository;
View code.php
<?php
namespace Example\FooBundle\Repository;
use Doctrine\ORM\EntityRepository;
class FooRepository extends EntityRepository
implements FooRepositoryInterface
{
public function fetchLatest()
View di.xml
<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>