Skip to content

Instantly share code, notes, and snippets.

Avatar
🔬
In your repositories, watching your code. Always watching.

Marco Pivetta Ocramius

🔬
In your repositories, watching your code. Always watching.
View GitHub Profile
@Ocramius
Ocramius / quick-doctrine-orm-zf2-sql-logging.local.php
Last active Oct 19, 2021
SQL Logger in Doctrine 2 ORM and ZF2
View quick-doctrine-orm-zf2-sql-logging.local.php
<?php
use Zend\ServiceManager\ServiceLocatorInterface;
return [
'service_manager' => [
'delegator' => [
'doctrine.entitymanager.orm_default' => [
function (ServiceLocatorInterface $sl, $name, $requestedName, $callback) {
/* @var $em \Doctrine\ORM\EntityManager */
@Ocramius
Ocramius / psalm-compendium.php
Last active Oct 17, 2021
A small compendium of what is possible with `vimeo/psalm` 3.9.x to add some decent type system features to PHP
View psalm-compendium.php
<?php
// -- types are a compile-time propagated concept
// https://psalm.dev/r/338f74a96c
class TheType
{
/** @var string */
public $foo = 'bar';
}
@Ocramius
Ocramius / README.md
Last active Aug 27, 2021
`__invoke` vs `function` vs `Closure`
View README.md
@Ocramius
Ocramius / User.php
Last active Aug 20, 2021
Doctrine 2 ManyToMany - the correct way
View User.php
<?php
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity()
* @ORM\Table(name="user")
*/
class User
@Ocramius
Ocramius / Caddyfile
Last active Jun 4, 2021
Example docker + docker-compose + caddy + traefik setup that routes to multiple apps from one exposed HTTP port
View Caddyfile
:80 {
root /serve
}
@Ocramius
Ocramius / Foo.php
Last active Mar 12, 2021
Self hydrating object proxy in PHP Provides faster hydration by removing the need for reflection.
View Foo.php
<?php
class Foo
{
protected $foo;
protected $bar;
protected $baz;
}
View User.php
<?php
namespace HelloWorld;
use InvalidArgumentException;
/**
* This class is somewhere in your library
* @Entity
* @Table(name="users")
*/
@Ocramius
Ocramius / BrutalForeignKeyDisablingMySQLPurger.php
Created Mar 4, 2015
Brutal ORM Purger for doctrine/data-fixtures
View BrutalForeignKeyDisablingMySQLPurger.php
<?php
namespace FixturesStuff
use Doctrine\Common\DataFixtures\Purger\ORMPurger;
use Doctrine\ORM\EntityManagerInterface;
/**
* @TODO this has to go once we implement correct purging of entities
*/
@Ocramius
Ocramius / .gitignore
Last active Aug 26, 2020
`in_array` vs `array_unique` performance example (just a test, not really interesting data)
View .gitignore
tests
composer.lock
composer.phar
vendor
View .gitlab-ci.yml
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
build-test-containers:
image: tiangolo/docker-with-compose
before_script:
- docker info