Skip to content

Instantly share code, notes, and snippets.

@rufinus
rufinus / MandatorType <2.6
Last active August 29, 2015 14:12
Symfony FormType <2.6 what is the >=2.6 way? Without needing OptionsResolverInterface?
<?php
namespace Dpanel\Bundle\AdminBundle\Forms;
use Cwd\GenericBundle\Doctrine\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
@TKlement
TKlement / bootstrap.php
Created August 31, 2012 16:36 — forked from jeroenherczeg/bootstrap.php
Zend Navigation for the Twitter Bootstrap
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
protected function _initNavigation() {
// make sure the layout is loaded
$this->bootstrap('layout');
// get the view of the layout
$layout = $this->getResource('layout');
$view = $layout->getView();
@sheeep
sheeep / Platform.php
Created November 12, 2012 11:05
Doctrine Many-to-Many, Repository->findBy()
<?php
namespace Oneup\CommunityBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
// [...] other namespace stuff
/**
@rande
rande / gist:985705
Created May 22, 2011 17:48
Sonata Security - Roles definitions
sonata_admin:
access_control:
- { path: ^/admin/sonata/media/media/list$, roles: [ROLE_SONATA_MEDIA_ADMIN_MEDIA_LIST], methods: null }
- { path: ^/admin/sonata/media/media/create$, roles: [ROLE_SONATA_MEDIA_ADMIN_MEDIA_CREATE], methods: null }
- { path: ^/admin/sonata/media/media/update$, roles: [ROLE_SONATA_MEDIA_ADMIN_MEDIA_UPDATE], methods: null }
- { path: ^/admin/sonata/media/media/batch$, roles: [ROLE_SONATA_MEDIA_ADMIN_MEDIA_BATCH], methods: null }
- { path: ^/admin/sonata/media/media/(?P[^/]+?)/edit$, roles: [ROLE_SONATA_MEDIA_ADMIN_MEDIA_EDIT], methods: null }
- { path: ^/admin/sonata/media/media/(?P[^/]+?)/delete$, roles: [ROLE_SONATA_MEDIA_ADMIN_MEDIA_DELETE], methods: null }
- { path: ^/admin/sonata/media/media/(?P[^/]+?)/view$, roles: [ROLE_SONATA_MEDIA_ADMIN_MEDIA_VIEW], methods: null }
- { path: ^/admin/sonata/media/gallery/list$, roles: [ROLE_SONATA_MEDIA_ADMIN_GALLERY_LIST], methods: null }
@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)
class I18nGenerator < Rails::Generators::NamedBase
def create_files
I18n.available_locales.each do |locale|
create_locale_file( locale )
end
end
private
def namespaces
@aronkerr
aronkerr / gist:6196208
Last active December 20, 2015 21:18
Get individual form elements from ZF2 collection
<?php
// Itterate over the collection and grap the elements
foreach($form->get('collectionName')->getIterator() as $fieldset)
{
echo $this->formRow($fieldset->get('elementName'));
echo $this->formRow($fieldset->get('elementAnotherElementName'));
@chalasr
chalasr / splat_operator.php
Last active April 11, 2016 13:26
function with dynamic number of type-hinted arguments using the splat operator PHP 5.6
<?php
function splat(array ...$args) {
foreach ($args as $arg) {
print_r($arg);
}
}
splat(['firstArray'], ['secondArray']);
// Output: Array( [0] => firstArray ) Array( [0] => secondArray )
@smalot
smalot / doctrine_extensions.yml
Created August 11, 2015 22:41
Doctrine Extensions config file with both ORM and ODM support.
# services to handle doctrine extensions
# import it in config.yml
services:
# KernelRequest listener
# extension.listener:
# class: AppBundle\Listener\DoctrineExtensionListener
# calls:
# - [ setContainer, [ @service_container ] ]
# tags:
# # translatable sets locale after router processing
@Axxon
Axxon / TestCase1Test.php
Created February 21, 2016 13:38
A asynchronous command & event bus with bernard
<?php
namespace AppBundle\Tests;
use SimpleBus\Message\Bus\MessageBus;
use SimpleBus\Message\Recorder\PublicMessageRecorder;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\ConsoleOutput;