Skip to content

Instantly share code, notes, and snippets.

View jmather's full-sized avatar

Jacob Mather jmather

View GitHub Profile
@jmather
jmather / MediaServerFilter.php
Created January 21, 2013 19:21
Media/CDN server w/ Symfony1
<?php
class MediaServerFilter extends sfFilter
{
public function execute($filterChain)
{
$filterChain->execute();
// Execute this filter only once
if ($this->isFirstCall() && sfConfig::get('app_media_filter_disable', false) == false) {
// Filters don't have direct access to the request and user objects.
@jmather
jmather / LoadWebsiteSpecificData.php
Created January 19, 2013 04:53
Load in file assets
<?php
namespace Demo\Bundle\WebsiteBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\DataFixtures\FixtureInterface;
use Application\Sonata\UserBundle\Entity\User;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
@jmather
jmather / provision.sh
Created January 9, 2013 21:38
Latest vagrant provision script
#!/bin/sh
NFSUID=`stat -c %u /vagrant/`
/usr/bin/sudo su -c "cat /etc/passwd | grep -v vagrant:x: > /etc/passwd.new"
/usr/bin/sudo su -c "echo \"vagrant:x:${NFSUID}:502::/home/vagrant:/bin/bash\" >> /etc/passwd.new"
/usr/bin/sudo su -c "chown -R ${NFSUID}:vagrant /home/vagrant"
/usr/bin/sudo su -c "mv -f /etc/passwd.new /etc/passwd"
/usr/bin/sudo su -c "chown -R vagrant:vagrant /var/lib/php/session"
/usr/bin/sudo su -c "chown vagrant:vagrant /tmp/vagrant-*"
<?php
namespace My\Bundle\BlockBundle\Block;
use Symfony\Component\HttpFoundation\Response;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\BlockBundle\Block\BaseBlockService;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
@jmather
jmather / User.php
Created December 20, 2012 17:46
How to make VichUploaderBundle change an image
public function setProfileImage($profile_image)
{
$this->profile_image = $profile_image;
if ($profile_image instanceof UploadedFile) {
$this->setUpdatedAt(new \DateTime());
}
}
<?php
use Silex\WebTestCase;
use Silex\Application;
use Silex\Provider\SessionServiceProvider;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
use Symfony\Component\HttpFoundation\Session\Storage\MockFileSessionStorage;
class unitTest extends WebTestCase
{
<?php
use Silex\WebTestCase;
use Silex\Application;
use Silex\Provider\SessionServiceProvider;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
class unitTest extends WebTestCase
{
public function testUn()
@jmather
jmather / example.php
Created December 16, 2012 02:40
Proxy Pattern Example
<?php
interface MyAPI
{
public function getThing();
}
class MyApiImplentation implements MyAPI
{
public function getThing()
@jmather
jmather / SiteListBuilder.php
Created August 14, 2011 06:43
How to link a many-to-many properly in Symfony2 with Sonata Admin Bundle
<?php
namespace Majax\PortalBundle\Builder;
use Symfony\Bundle\DoctrineBundle\Registry;
class SiteListBuilder {
/** @var \Symfony\Bundle\DoctrineBundle\Registry */
private $orm;
public function __construct($orm)
@jmather
jmather / .init.sh
Created December 4, 2012 22:41
Easily create a new project
#!/bin/bash
source /etc/profile
git init
mv base.iml $1.iml
cd .idea/
cat modules.xml | sed "s/base/$1/g" > modules.xml.new
mv modules.xml.new modules.xml