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
<?php
namespace igorw\lusp;
// all functions return a pair of [val, env]
function evaluate($expr, $env = []) {
if (is_string($expr)) {
if (is_numeric($expr)) {
$val = (float) $expr;
@juriansluiman
juriansluiman / 1. Application.md
Created November 8, 2011 14:35
Modular application system for ZF2

Application system

This document describes how a system can be formed to set up modules in combination with a tree of pages stored in the database. The general idea is to have pages stored within a database in a tree structure, where every page is coupled to a module (1:n). Pages are queried and parsed to routes as a combination of the page route and the modules route(s).

Goal

Webapplications exist often with a frontend (for normal visitors) and backend (to manage the whole bunch). Also some pages might want to utilize the same module (two simple text pages as basic example). Thirdly, it should be easy for end users to create new pages, modify them or delete pages. To accomplish this, a robust system ("content management framework") should be made on top of zf2 to accomodate this.

Configuration

@beberlei
beberlei / README.md
Created February 8, 2012 08:25
Collection Filters - Readme Driven Development

Filter Language for Collections

Why?

You often need subsets of objects in a collection and want to access them efficiently in your domain model. But you certainly don't want to access the EntityManager or any other object manager here to craft a query. FilterExpressions for collections allow to go back to the database and query for all objects matching the crafted expression. Additionally they also work against in meemory ArrayCollection exactly the same. This way you don't (except for the SQL performance when it haunts you ;)) have to think about the context and can focus on your domain logic.

In Doctrine ORM this will be done by building DQL under the hood, in memory it will be done using Collection#filter(Closure $closure);

Technical Requirements:

@beriberikix
beriberikix / backbone-links.md
Created March 4, 2012 03:45
AWSUM Web Development Linkz
@Ocramius
Ocramius / CriteriaTest.php
Created August 16, 2012 09:15
Example of Criteria/Collection API usage in Doctrine 2.3
<?php
/**
* Created by JetBrains PhpStorm.
* User: Marco Pivetta
* Date: 16.08.12
* Time: 11:05
* To change this template use File | Settings | File Templates.
*/
class CriteriaTest extends \PHPUnit_Framework_TestCase
{
// Use Reflection
// if by_val === true (or by_reference === false)
extract :
$data = array();
for every elements in object
getter = getElementName
if element is scalar (object or primitive type)
@nikic
nikic / accessors.markdown
Created October 13, 2012 11:22
Analysis of getter/setter usage in Symfony and Zend Framework

In order to get a bit of "hard data" on what accessors will actually be used for once they are introduced I wrote a small script that scans through a codebase, finds all getter and setter methods and checks them for various characteristics. (The analyze.php file in this Gist.)

Here are the results of running it on a Symfony (Standard) skeleton.

absoluteTotal        => 18516 (486.6%)
total                =>  3805 (100.0%)
skipped              =>   124 (  3.3%)
@Ocramius
Ocramius / broken_php_magic.php
Created November 8, 2012 04:03
Broken PHP Magic methods
<?php
class A{
protected $b;
function __construct() {unset($this->b);}
function __get($name){
echo $name;
return $this->$name;
}
}
$a = new A;
@igorw
igorw / y.php
Created December 30, 2012 16:49
<?php
$factorial = call_user_func(
function ($le) {
return call_user_func(
function ($f) {
return $f($f);
},
function ($f) use ($le) {
return $le(function ($x) use ($f) {
@texdc
texdc / 1-Notes.md
Last active December 19, 2015 08:59
Notes on refactoring ZF2's "InputFilter"

A few notes from my personal gripes about what InputFilter is and does.

  1. InputFilter is a terrible name as the class mixes sanitation and validation. Rename to something far more appropriate (e.g. InputManager?).
  2. Data should only be processed, not stored - remove setData()

SoC Article

For example, if both raw and sanitized data are required: