Skip to content

Instantly share code, notes, and snippets.

@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();
@jmather
jmather / User.orm.xml
Created September 17, 2012 18:41
How to extend the Sonata User Bundle's User
<!-- Application/Sonata/UserBundle/Resources/config/doctrine/User.orm.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Application\Sonata\UserBundle\Entity\User" table="fos_user_user">
<id name="id" column="id" type="integer">
@ludekstepan
ludekstepan / MigrationExample.php
Created September 20, 2012 11:19
Example of container aware migration
<?php
namespace Application\Migrations;
use Doctrine\DBAL\Migrations\AbstractMigration,
Doctrine\DBAL\Schema\Schema;
class Version20120920130854 extends AbstractMigration
{
public function up(Schema $schema)
@akrabat
akrabat / UnauthorizedStrategy.php
Created September 25, 2012 19:27
bjyAuthorise view strategy to redirect to login page on auth failure
<?php
namespace Application\View;
use BjyAuthorize\Service\Authorize;
use Zend\EventManager\EventManagerInterface;
use Zend\EventManager\ListenerAggregateInterface;
use Zend\Http\Response as HttpResponse;
use Zend\Mvc\MvcEvent;
use Zend\Stdlib\ResponseInterface as Response;
@nikcub
nikcub / README.md
Created October 4, 2012 13:06
Facebook PHP Source Code from August 2007
@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
/**
@bjo3rnf
bjo3rnf / EntityHiddenType.php
Last active November 19, 2021 17:19
Hidden field for Symfony2 entities
<?php
namespace Dpn\ToolsBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Dpn\ToolsBundle\Form\DataTransformer\EntityToIdTransformer;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Doctrine\Common\Persistence\ObjectManager;
@nikic
nikic / objects_arrays.md
Last active April 12, 2024 17:05
Post explaining why objects often use less memory than arrays (in PHP)

Why objects (usually) use less memory than arrays in PHP

This is just a small post in response to [this tweet][tweet] by Julien Pauli (who by the way is the release manager for PHP 5.5). In the tweet he claims that objects use more memory than arrays in PHP. Even though it can be like that, it's not true in most cases. (Note: This only applies to PHP 5.4 or newer.)

The reason why it's easy to assume that objects are larger than arrays is because objects can be seen as an array of properties and a bit of additional information (like the class it belongs to). And as array + additional info > array it obviously follows that objects are larger. The thing is that in most cases PHP can optimize the array part of it away. So how does that work?

The key here is that objects usually have a predefined set of keys, whereas arrays don't:

@lukemorton
lukemorton / README.md
Last active August 24, 2022 15:17
Providing an interface in PHP for RFC 6570 and a little more based on addressable (a ruby gem).

URI

uri-template interface for PHP.

Classes

  • URI\Template::expand()
  • URI\Regex::from_template()
  • URI\Parser::parse() (only if needed)
class I18nGenerator < Rails::Generators::NamedBase
def create_files
I18n.available_locales.each do |locale|
create_locale_file( locale )
end
end
private
def namespaces