Skip to content

Instantly share code, notes, and snippets.

View Ocramius's full-sized avatar
🔬
In your repositories, watching your code. Always watching.

Marco Pivetta Ocramius

🔬
In your repositories, watching your code. Always watching.
View GitHub Profile
@Ocramius
Ocramius / module.config.php
Created November 12, 2011 13:42
Zend\Db adapter instantiation through Zend Framework 2 Di
<?php
return array(
'di' => array(
'definition' => array(
//teaching DI to use the factory
'class' => array(
'Zend\Db\Db' => array(
'methods' => array(
'factory' => array(
'adapter' => array(
@Ocramius
Ocramius / Deneb\Session\SaveHandler.php
Created December 23, 2011 15:49
Session Savehandler based on Doctrine2
<?php
namespace Deneb\Session;
/**
* Manages sessions storage through \Doctrine\ORM\EntityManager
* @author Ocramius
*/
class SaveHandler implements \Zend_Session_SaveHandler_Interface {
const SESSION_ENTITY_NAME = 'Deneb\Entity\Session';
@Ocramius
Ocramius / SessionAwarePaginator.php
Created January 2, 2012 10:21
A simple Zend_Paginator that is capable of storing the current page number into a session
<?php
/**
* Description
*
* @author Marco Pivetta <marco.pivetta@com2-gmbh.de>
*/
class SessionAwarePaginator extends Zend_Paginator {
const DEFAULT_SESSION_NS = 'SessionAwarePaginator';
@Ocramius
Ocramius / module.config.php
Created January 18, 2012 17:28 — forked from m0ppers/gist:1634220
Zend Framework 2 view helpers overriding
'Zend\View\PhpRenderer' => array(
'parameters' => array(
'options' => array(
'script_paths' => array(
'MyModule' => __DIR__ . '/../view',
),
),
),
),
'Zend\View\HelperLoader' => array(
@Ocramius
Ocramius / bootstrap.php
Created January 21, 2012 11:42
example doctrine bootstrapper
<?php
use Doctrine\Common\ClassLoader,
Doctrine\ORM\Tools\Setup,
Doctrine\ORM\Mapping\Driver\AnnotationDriver,
Doctrine\Common\Annotations\AnnotationReader,
Doctrine\ORM\EntityManager;
// Autoloaders
require_once __DIR__ . '/../lib/doctrine/lib/Doctrine/ORM/Tools/Setup.php';
Doctrine\ORM\Tools\Setup::registerAutoloadGit(__DIR__ . '/../lib/doctrine');
@Ocramius
Ocramius / cli.php
Created January 24, 2012 17:32
My old ZF1-D2 CLI runner
<?php
define('APPLICATION_ENV', 'cli');
require_once(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'application.php');
$em = $application->getBootstrap()->getResource('em');
$cli = new \Symfony\Component\Console\Application('DENEB Command Line Interface', Doctrine\ORM\Version::VERSION);
$cli->setCatchExceptions(true);
$cli->setHelperSet(
new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
@Ocramius
Ocramius / module.config.php
Created January 26, 2012 00:38
move-routes-setup-to-di zf2
<?php
return array(
'layout' => 'layout/layout.phtml',
'display_exceptions' => true,
'di' => array(
'instance' => array(
'alias' => array(
'index' => 'Application\Controller\IndexController',
'error' => 'Application\Controller\ErrorController',
'view' => 'Zend\View\PhpRenderer',
@Ocramius
Ocramius / doctrine-mapping.xsd
Created February 3, 2012 00:00 — forked from FabioBatSilva/doctrine-mapping.xsd
doctrine-mapping.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:orm="http://doctrine-project.org/schemas/orm/doctrine-mapping"
elementFormDefault="qualified">
<xs:annotation>
<xs:documentation><![CDATA[
This is the XML Schema for the object/relational
@Ocramius
Ocramius / Bootstrap.php
Created February 14, 2012 11:23
Zend\Di experiment with LocatorAware interfaces
<?php
/**
* Sets up the locator based on the configuration provided
*
* @param AppContext $application
* @return void
*/
protected function setupLocator(AppContext $application)
{
// default configuration for the router
@Ocramius
Ocramius / PersistentCollection.php
Created February 18, 2012 18:17
Doctrine\ORM\PersistentCollection optimizations for fetch="EXTRA_LAZY" mapping
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY