Skip to content

Instantly share code, notes, and snippets.

View tentacode's full-sized avatar
🐙
tentacoding

Gabriel Pillet tentacode

🐙
tentacoding
View GitHub Profile
@tentacode
tentacode / FooRepository.php
Created July 24, 2013 08:56
Select the foreign key column value in a scalar result on Doctrine without joining with related table (Doctrine 2.2)
<?php
class FooRepository
{
public function getScalarStuffWithFK()
{
$dql = '
SELECT IDENTITY(f.bar) as bar_id, f.name, f.otherStuff
FROM MyBundle:Foo f
';
@tentacode
tentacode / XSDValidator.php
Created July 5, 2013 13:47
Super easy XML/XSD validator (require libxml)
<?php
namespace Tentacode\FilesystemBundle\XML;
use DOMDocument;
use XMLReader;
class XSDValidator
{
protected $xmlFile;
@tentacode
tentacode / behat.yml
Last active December 19, 2015 05:59
How to install a working behat (bin only) on a Symfony project
default:
formatter:
name: pretty
paths:
features: features
context:
class: Context\FeatureContext
extensions:
Behat\MinkExtension\Extension:
default_session: symfony2
@tentacode
tentacode / reload.sh
Last active December 19, 2015 05:09
A really quick script to reload a Symfony/Doctrine project, mostly for coding locally in your dev environment
#!/bin/bash
if [ "$1" == "" ]; then
set $1 'dev'
fi
app/console doctrine:schema:drop --env=$1 --force
app/console doctrine:schema:create --env=$1
app/console doctrine:fixtures:load --env=$1 --no-interaction --no-debug
app/console assets:install web --env=$1
app/console assetic:dump --env=$1

Here is what I'm trying to achieve.

I've got a ProjectBundle (Symfony2 bundle), with a Project Propel class. It represent an instance of a website, for example : two music band website share the code base, two different url, same logic but different data.

Various other Bundles (lets say "a dozen") can plug to the Project bundle, for example a BlogBundle will contain a Post and Comment Propel classes. A post is linked to a project via a foreign key (one project, several posts).

The issue is : the ProjectBundle is to remain independant, I don't want the Project class to have a Project::getPosts method because the BlogBundle might not be included in vendors.

@tentacode
tentacode / error_log
Created December 10, 2012 12:06
Fresh Symfony2 install, Zend leaks ?
[Mon Dec 10 13:08:13 2012] Script: '/Users/gabriel/Workspace/Hathor/web/app.php'
Zend/zend_language_scanner.l(2018) : Freeing 0x10E643C80 (16 bytes), script=/Users/gabriel/Workspace/Hathor/web/app.php
[Mon Dec 10 13:08:13 2012] Script: '/Users/gabriel/Workspace/Hathor/web/app.php'
/private/tmp/php54-mPF3/php-5.4.8/Zend/zend_compile.c(5261) : Freeing 0x10E646370 (32 bytes), script=/Users/gabriel/Workspace/Hathor/web/app.php
=== Total 2 memory leaks detected ===
@tentacode
tentacode / gist:4117353
Created November 20, 2012 11:17
PHP 5.4 brew Mountain Lion
~$ apachectl -t
httpd: Syntax error on line 118 of /private/etc/apache2/httpd.conf: Cannot load /usr/local/Cellar/php54/5.4.0/libexec/apache2/libphp5.so into server: dlopen(/usr/local/Cellar/php54/5.4.0/libexec/apache2/libphp5.so, 10): Symbol not found: _environ\n Referenced from: /usr/local/Cellar/php54/5.4.0/libexec/apache2/libphp5.so\n Expected in: /usr/sbin/httpd\n in /usr/local/Cellar/php54/5.4.0/libexec/apache2/libphp5.so
~$ brew install php54 --with-mysql --with-intl --with-debug
==> Downloading http://www.php.net/get/php-5.4.8.tar.bz2/from/this/mirror
Already downloaded: /Library/Caches/Homebrew/php54-5.4.8
Warning: Backing up all known pear.conf and .pearrc files
Warning: If you have a pre-existing pear install outside
of homebrew-php, or you are using a non-standard
pear.conf location, installation may fail.
@tentacode
tentacode / UserExtension.php
Created October 31, 2012 13:43
Twig Extension to grant access based on path
<?php
namespace Tentacode\Foobar\UserBundle\Twig;
use Twig_Extension;
use Twig_Function_Method;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Http\AccessMap;
@tentacode
tentacode / list.html.twig
Created October 15, 2012 12:23
Twig recursive macro
{% macro recursiveCategory(category) %}
<li>
<h4><a href="{{ path(category.route, category.routeParams) }}">{{ category }}</a></h4>
{% if category.children|length %}
<ul>
{% for child in category.children %}
{{ _self.recursiveCategory(child) }}
{% endfor %}
</ul>
<?php
class SomeObject
{
use \FooTraits\SomeTrait;
public function getSomeRequiredParameter()
{
return 'foo';
}