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 / Doctrine2-hello-world.php
Created March 25, 2011 19:33
Doctrine 2 "Hello World" sample
<?php
/* ORM CONFIG HERE, LIKE IN SAMPLE BOOTSTRAP */
/** @var $em \Doctrine\ORM\EntityManager */
$em = Doctrine\ORM\EntityManager::create($options, $config);
$greeting = new Greeting();
$greeting->setGreeting('Hello World!');
$em->persist($greeting);
$greeting2 = new Greeting();
$greeting2->setGreeting('Hello again! This is another greeting!');
@Ocramius
Ocramius / Rand.php
Created April 14, 2011 13:23
MySQL RAND() function in Doctrine2 DQL
<?php
namespace My\Custom\Doctrine2\Function;
/**
* RandFunction ::= "RAND" "(" ")"
*/
class Rand extends FunctionNode
{
public function parse(\Doctrine\ORM\Query\Parser $parser)
@Ocramius
Ocramius / Doctrine.php
Created April 18, 2011 08:58
Application_Model_Resource_Doctrine Doctrine2 EntityManager generator resource
<?php
class Application_Model_Resource_Doctrine extends Zend_Application_Resource_ResourceAbstract {
/**
*
* @var \Application_Model_Resource_Doctrine
*/
protected static $instance = null;
@Ocramius
Ocramius / Unique.php
Created April 25, 2011 14:04
Doctrine2 Zend_Validate_DbRecord_NotExists (Gamempire\Validate\Entity\Field\Unique) implementation
<?php
namespace Gamempire\Validate\Entity\Field;
/**
* Validates input entity field to check if it is unique
*
* @author Ocramius
*/
class Unique extends \Zend_Validate_Abstract {
@Ocramius
Ocramius / LockableFieldSubForm.php
Created July 15, 2011 16:14
A sample integration of Doctrine 2 and Zend_Form
<?php
namespace Deneb\Form;
/**
* Manages scalar fields of an entity
*/
class Entity extends ListDecorated {
const DEFAULT_DISPLAY_GROUP = 'default';
@Ocramius
Ocramius / Notes
Created October 15, 2011 20:09
PHP Benchmark for array_search against foreach
Tested on PHP 5.3.8 on Mac OS 10.6.8.
These results are just micro-optimization, which is quite useless, but the foreach construct seems to be always slower than array_search.
I expected much better results, but I frankly don't know why I didn't get them this time. Unfortunately I don't have the previous benchmark anymore.
@Ocramius
Ocramius / User.php
Created October 23, 2011 14:22
Doctrine 2 @OneToMany @manytoone example
<?php
namespace HelloWorld;
use InvalidArgumentException;
/**
* This class is somewhere in your library
* @Entity
* @Table(name="users")
*/
@Ocramius
Ocramius / Workers.php
Created October 30, 2011 17:43
[doctrine-user] Auto create date - annoation - Codeigniter 2 and Doctrine 2
<?php
namespace models;
/**
* @Entity
* @Table(name="workers")
* @HasLifecycleCallback
*/
class Workers {
/**
@Ocramius
Ocramius / CompiledDi.php
Created November 10, 2011 00:22
Exploring Zend\Di caching
<?php
namespace My\Di\Cache;
use Zend\Di\Di as ZendDi;
class CompiledDi extends ZendDi {
public function get($name, $params = array()) {
if($params) {
return parent::get($name, $params);
}
@Ocramius
Ocramius / Session.php
Created November 11, 2011 10:10
Auth Storage adapter for Zend Framework and Doctrine 2
<?php
namespace Ocramius\Auth\Storage;
use Entity\Ocramius\Admin as AdminEntity,
Doctrine\ORM\EntityManager;
/**
* An @see \Zend_Auth_Storage_Session that handles @see AdminEntity items
* @author Marco Pivetta <ocramius@gmail.com>
*/