Skip to content

Instantly share code, notes, and snippets.

@milo
milo / nette-addon-compatibility.md
Last active August 29, 2015 14:01
Nette addon compatibility solution

How to keep a Nette addon compatibility with Nette Framework 2.0, 2.1 and 2.2? Here is my fight description:

  1. Nette 2.0 Nette\Utils\PhpGenerator\ClassType vs Nette 2.1+ Nette\PhpGenerator\ClassType strict errors and Nette\Config\CompilerExtension vs. Nette\DI\CompilerExtension. This was a difficult one:
  • Create abstract BC\Extensions like this,
  • and Nette version-dependent loader like this.
  • A target extension will inherit one of them as class Extension extends BC\Extension and
  • the Composer will class-mapping different folder and hard load version-dependent loader like this.
  1. IBarPanel is solved in the same way as 1)
@milo
milo / PersistentUploadControl.php
Created August 18, 2015 11:17
Persistent file upload control for #nettefw
<?php
namespace App\Controls;
use App\Model\Entities;
use Nette\DirectoryNotFoundException;
use Nette\Forms;
use Nette\Http;
use Nette\Utils\Html;
@milo
milo / DibiResult.php
Created August 29, 2011 21:37
$config['formatDate'] possibility
<?php
/**
* This file is part of the "dibi" - smart database abstraction layer.
*
* Copyright (c) 2005, 2010 David Grudl (http://davidgrudl.com)
*
* For the full copyright and license information, please view
* the file license.txt that was distributed with this source code.
*
@milo
milo / nette-issue-930.php
Created January 18, 2013 19:29
Nette #930 issue stress code
<?php
use Nette\Diagnostics\Debugger, Nette\Caching\Cache;
require '/home/milo/dev/nette/Nette/loader.php';
set_time_limit(0);
define('TEMP_DIR', __DIR__ . '/temp');
define('LOG_DIR', __DIR__ . '/log');
<?php
require __DIR__ . '/Nette/loader.php';
debug();
$db = new Nette\Database\Connection('pgsql:host=localhost;dbname=nette_test', 'postgres');
$db->query('DROP SCHEMA IF EXISTS issue288 CASCADE');
$db->query('CREATE SCHEMA issue288');
$db->query('SET search_path TO issue288');
@milo
milo / unexpected-closure.php
Created September 3, 2013 06:56
Unexpected PHP closure behaviour, at least for me.
<?php
$var = 'INIT';
$fGet = function() use ($var) {
echo "$var\n";
};
$fSet = function($i) use (& $var) {
$var = "I: $i";
@milo
milo / phar-extract
Created January 4, 2014 16:29
Small PHAR extract script
#!/usr/bin/env php
<?php
error_reporting(E_ALL | E_STRICT);
$opts = getOptions();
# Help
if (array_key_exists('h', $opts)) {
echo "PHAR content extract by Milo (https://github.com/milo)\n";
@milo
milo / post-merge
Created July 23, 2015 11:48
Git hook for purging cache
#!/bin/sh
# Save as .git/hooks/post-merge
# Set execute bit like: chmod ug+x .git/hooks/post-merge
purgePath="temp/cache"
echo
echo -n "HOOK [Purge cache]: "
if [ -d "$purgePath" ]; then
@milo
milo / Bootstrap3Renderer.php
Created June 3, 2015 09:01
Bootstrap3 renderer for Nette Framework forms
<?php
namespace Milo\NetteForms\Rendering;
use Nette\Forms;
use Nette\Forms\Controls;
/**
* Simple Bootstrap3 renderer for Nette Framework forms.
*
@milo
milo / .autoprepend.php
Created August 20, 2013 07:51
Handy Tracy/Nette Debugger in autoprepend file
<?php
function __nette($version = NULL) {
if ($version) {
require "/var/www/lib/nette/$version/Nette/loader.php";
} else {
require '/var/www/dev/nette/Nette/loader.php';
}
}