Skip to content

Instantly share code, notes, and snippets.

@juzna
juzna / constructor-experiment.php
Created May 7, 2012 19:45
PHP experiment: object construction
<?php
/**
* Experiment: constructor to have already partially initialized object, before it gets called.
*/
class Foobar {
private $a;
private $b;
private $c;
@juzna
juzna / MyTest.php
Created April 19, 2012 19:48
Nette DI container and @Inject annotation
<?php
/**
* Example of what a decent Dependency Injection Container should inject to make our life happier
*/
class MyTest {
public function __construct(\Nette\Security\User $user) { // Constructor injection
}
@juzna
juzna / RepositoryClassListener.php
Created April 16, 2012 08:49
Doctrine listener: Updates custom repository class definition if explicitly defined in parent class
<?php
use \Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Nette,
Doctrine,
Doctrine\ORM\Events;
/**
* Updates custom repository class definition if explicitly defined in parent class
@juzna
juzna / autoload.php
Created March 30, 2012 10:28
Nette skeleton autoload
<?php
/**
* Class loader for the whole application
*
* Makes sure all the classes are available when they're needed. No less, no more.
* Usually the first file to load in your app
*
* @author Jan Dolecek <juzna.cz@gmail.com>
* @author Filip Procházka (filip.prochazka@kdyby.org)
*/
@juzna
juzna / compare.php
Created March 26, 2012 18:57
PHP compare bug
<?php
$a = new ArrayObject(array(
'single' => "ahoj",
'double' => "lamo",
));
$b = new ArrayObject(array(
'single' => "zdar",
'double' => "vole",
@juzna
juzna / config.php
Created March 26, 2012 10:52
UIR-ADR update
<?
$dbHost = 'localhost';
$dbUser = '...';
$dbPass = '...';
$dbDatabase = '...';
@juzna
juzna / arraysTest.php
Created March 26, 2012 08:38
Multidimensional arrays in PHP
<?php
class Tool {
/**
* @return Tool[][]
*/
function getItems() {
return call_user_func('x'); // dummy
}
}
@juzna
juzna / MyPresenter.php
Created March 17, 2012 16:40
{if authorized} macro for nette
/**
* Handle action, only valid for a logged-in user
* @User
*/
public function handleLike($itemId) { ... }
@juzna
juzna / Object.php
Created March 14, 2012 22:05
PhpStorm inconsistent use proof
<?php
namespace MyApp;
/**
*/
class Object {
function isThisAnObject() {
}
}
@juzna
juzna / output.txt
Created February 5, 2012 18:58
PHP native object support
object(Pepa)#2 (1) {
["myObj"]=>
object(stdClass)#1 (2) {
["ahoj"]=>
int(1)
["novak"]=>
string(4) "pepa"
}
}