Skip to content

Instantly share code, notes, and snippets.

View afurculita's full-sized avatar
👽
Searching for intelligent life

Alexandru Furculita afurculita

👽
Searching for intelligent life
View GitHub Profile
<?php
//$em is the entity manager
$qb = $em->createQueryBuilder();
// Wasteful, will select all the properties (columns) for the entity
$qb
->select('Article')
->from('Entity\Article')
;
// Better, but won't provide a structure representing our object graph (returns a flat array)
$qb
@afurculita
afurculita / doctrine--lazy-loading-collections-best-practice.php
Created June 26, 2017 19:25
Doctrine 2 - Beware of lazy loading when querying entities with associations
<?php
//$em is the entity manager
$qb = $em->createQueryBuilder();
$qb
->select('Article', 'Comment')
->from('Entity\Article', 'Article')
->leftJoin('Article.comment', 'Comment')
;
@afurculita
afurculita / doctrine--lazy-loading-collections.php
Last active June 26, 2017 19:23
Beware of lazy loading when querying entities with associations
<?php
$articles = $article_repository->findAll();
foreach($articles as $article)
{
echo $article->getTitle();
echo count($article->getComments());
}
@afurculita
afurculita / README.md
Created December 27, 2016 17:15 — forked from chadrien/README.md
Debug PHP in Docker with PHPStorm and Xdebug

Debug your PHP in Docker with Intellij/PHPStorm and Xdebug

  1. For your local dev, create a Dockerfile that is based on your production image and simply install xdebug into it. Exemple:
FROM php:5

RUN yes | pecl install xdebug \
&amp;&amp; echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" &gt; /usr/local/etc/php/conf.d/xdebug.ini \
@afurculita
afurculita / replace-bash-with-zsh-no-root.sh
Created March 8, 2016 13:23
Making zsh default shell without root access
# Create .bash_profile in your home directory and add these lines:
export SHELL=/bin/zsh
exec /bin/zsh -l
@afurculita
afurculita / find-the-biggest-tables-in-your-mysql-db.sql
Created February 13, 2016 07:16
Find the biggest tables in your MySQL db
SELECT CONCAT(table_schema, '.', table_name),
CONCAT(ROUND(table_rows / 1000000, 2), 'M') rows,
CONCAT(ROUND(data_length / ( 1024 * 1024 * 1024 ), 2), 'G') DATA,
CONCAT(ROUND(index_length / ( 1024 * 1024 * 1024 ), 2), 'G') idx,
CONCAT(ROUND(( data_length + index_length ) / ( 1024 * 1024 * 1024 ), 2), 'G') total_size,
ROUND(index_length / data_length, 2) idxfrac
FROM information_schema.TABLES
WHERE table_schema = 'my_database_name'
ORDER BY data_length + index_length DESC
LIMIT 10;
You can reference to the Discriminator column in 2 ways:
- INSTANCE OF
- TYPE()
Examples:
SELECT u FROM Person u WHERE u INSTANCE OF User
SELECT u FROM Person u WHERE TYPE(u) = 'user'
@afurculita
afurculita / commit-msg
Created October 2, 2015 09:59 — forked from shytikov/commit-msg
commit-msg hook script
#!/bin/sh
#
# Automatically adds branch name and branch description to every commit message.
#
NAME=$(git branch | grep '*' | sed 's/* //')
DESCRIPTION=$(git config branch."$NAME".description)
TEXT=$(cat "$1" | sed '/^#.*/d')
if [ -n "$TEXT" ]
then
<?php
namespace Gitonomy\Bundle\CoreBundle\Serializer\Normalizer;
use Doctrine\Common\Persistence\ManagerRegistry;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
class EntitiesNormalizer implements NormalizerInterface, DenormalizerInterface
{
@afurculita
afurculita / CustomHandler.php
Last active August 29, 2015 14:18 — forked from baldurrensch/CustomHandler.php
This is a handler for the JMS serializer to handle parent and child type serialization. You need to set the type of your collection as `@Type("\Acme\MyBundle\Model\ChildType")`, so that the serializer picks up the handler correctly. Also remember that you need to hook up the handler as a service (and give it the correct tag).
<?php
namespace Acme\MyBundle\Serializer\Handler;
use JMS\Serializer\Handler\SubscribingHandlerInterface;
use JMS\Serializer\EventDispatcher\Event;
use JMS\Serializer\GraphNavigator;
use JMS\Serializer\XmlSerializationVisitor;
use JMS\Serializer\GenericSerializationVisitor;