Skip to content

Instantly share code, notes, and snippets.

@dbu
dbu / gist:982774
Created May 20, 2011 11:45
last news
$de_index = 0;
$lastFrench = null;
foreach ($db->query('SELECT * from fluxcms_blogposts order by post_date desc') as $row) {
...
if ($row['post_lang'] == 'de') {
if ($lastFrench == null) {
$lastFrench = $de_index;
}
$de_index++;
@dbu
dbu / git-status-recursive
Created May 31, 2012 14:14
recursive git status
#!/usr/bin/php
<?php
$repos = array();
exec('find -type d -name .git | sed -e "s/\.git//"', $repos);
foreach ($repos as $repo) {
$status = shell_exec("cd $repo && git status");
if (false == strpos($status, 'nothing to commit (working directory clean)')) {
echo "$repo\n" . str_repeat('-', strlen($repo)) . "\n$status\n\n";
}
}
@dbu
dbu / UserAdmin.php
Created August 2, 2012 09:42
Use sonata ACL in list query
class UserAdmin
{
...
// i inject the security.context into the constructor to have it available
/**
* Alter list query to only see items i created
*/
public function createQuery($context = 'list')
{
@dbu
dbu / MutableAclProvider.php
Created November 1, 2012 11:49
Doctrine ACL MutableAclProvider
/**
* An implementation of the MutableAclProviderInterface using Doctrine DBAL.
*
* @author Stefan Paschke <stefan.paschke@liip.ch>
*/
class MutableAclProvider extends BaseMutableAclProvider
{
/**
* Get the entities Ids for the className that match the given role & mask
*
@dbu
dbu / Vagrantfile
Created November 13, 2012 09:26
vagrant setup
# -*- mode: ruby -*-
# vi: set ft=ruby :
this_dir = File.dirname(__FILE__) + "/"
require this_dir + "vagrant/hostmaster.rb"
Vagrant::Config.run do |config|
# define some colors for our output
def colorize(text, color_code) "#{color_code}#{text}\033[0m" end
// match method becomes
public function matchRequest(Request $request)
{
$defaults = $this->nestedMatcher->matchRequest($request);
foreach ($this->enhancers as $enhancer) {
$defaults = $enhancer->enhance($defaults, $request);
}
return $defaults;
@dbu
dbu / SynchronizeTranslationsCommand.php
Created December 5, 2012 17:21
Xliff translation updated
<?php
namespace Liip\CoreBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Translation\Loader\LoaderInterface;
use Symfony\Component\Finder\Finder;
@dbu
dbu / apache setup script
Created December 11, 2012 20:45
travis apache run
#!/bin/bash
sudo apt-get install -y --force-yes apache2
sudo a2enmod actions
sudo a2enmod rewrite
echo "export PATH=/home/vagrant/.phpenv/bin:$PATH" | sudo tee -a /etc/apache2/envvars > /dev/null
echo "$(cat scripts/travis/assets/phpconfig.txt)" | sudo tee /etc/apache2/conf.d/phpconfig > /dev/null
echo "$(cat scripts/travis/assets/vhost.txt)" | sed -e "s,PATH,`pwd`/web,g" | sudo tee /etc/apache2/sites-available/default > /dev/null
echo "date.timezone = UTC" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
sudo service apache2 restart
@dbu
dbu / ImageType.php
Created March 12, 2013 11:03
i needed a form type that determines based on the bound data if it should be required or not (to make file upload required if we create a new entity, but optional when editing the entity with the file. as this happens in a embedded sonata, i have no way of knowing the actual data when creating the form in the form builder. this is what i came up…
<?php
class ImageType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ($options['required_auto'] && ! $options['required']) {
$builder->addEventListener(\Symfony\Component\Form\FormEvents::PRE_SET_DATA, array($this, 'determineRequired'));
}
@dbu
dbu / ConfluenceUserProvider.php
Created April 23, 2013 07:05
confluence soap user provider
<?php
namespace Acme\UserBundle\Security\User;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\UserInterface as SecurityUserInterface;
use Symfony\Component\Validator\Validator;
class ConfluenceUserProvider implements UserProviderInterface