Skip to content

Instantly share code, notes, and snippets.

View fprochazka's full-sized avatar
🏠
Working from home

Filip Procházka fprochazka

🏠
Working from home
View GitHub Profile
@fprochazka
fprochazka / BasePresenter.php
Created April 17, 2013 14:04
Hack for lazylinks to
<?php
use Nette\Application\UI;
class BasePresenter extends UI\Presenter
{
/**
* Returns destination as Link object.
* @param string destination in format "[[module:]presenter:]view" or "signal!"
@fprochazka
fprochazka / ArraySessionStorage.php
Last active August 31, 2017 20:23
faking nette session in tests
<?php
/**
* Třída existuje, aby se vůbec neukládala session, tam kde není potřeba.
* Například v API, nebo v Cronu se různě sahá na session, i když se reálně mezi requesty nepřenáší.
*
* @internal
*/
class ArraySessionStorage extends Nette\Object implements Nette\Http\ISessionStorage
{

To je komponenta, která pouze zpracovává signál a vytváří odkazy systémovým způsobem, díky napojení na presenter.

<?php

	protected function createComponentFbLogin()
	{
		$dialog = $this->facebook->createDialog('login');
		/** @var LoginDialog $dialog */
 $dialog-&gt;onResponse[] = $this-&gt;facebookLoginResponse;
<?php
function handle($throw = FALSE)
{
try {
try {
throw new \LogicException('invalid xml');
} catch (\Exception $e) {
throw new \LogicException('', 0, $e); // wrap
@fprochazka
fprochazka / sorting-finder.php
Created December 21, 2012 19:37
Sorting finder results - directory first.
<?php
Finder::extensionMethod('sort', function (Finder $finder, $callback) {
$result = iterator_to_array($finder);
uasort($result, $callback);
return new \ArrayIterator($result);
});
$index = Finder::find('*')->in($dir)->sort(function (\SplFileInfo $a, \SplFileInfo $b) {
return $a->isDir() ? ($b->isDir() ? strnatcasecmp($a->getBasename(), $b->getBasename()) : -1)
<?php
/**
* This file is part of the Kdyby (http://www.kdyby.org)
*
* Copyright (c) 2008, 2012 Filip Procházka (filip@prochazka.su)
*
* For the full copyright and license information, please view the file license.txt that was distributed with this source code.
*/
/**
* Acquires an indexing lock if possible.
*
* @return boolean
*/
private function acquireLock()
{
$redis = $this->getRedis();
if ($redis->setNX(self::LOCK_KEY, $this->getTimeout())) {
{extends @outer.layout.latte}
{#body}
<div class="content">
{include #content}
</div>
@fprochazka
fprochazka / BasePresenter.php
Created October 6, 2012 16:22
Image pipe for #nettefw templates
<?php
/**
* @author Filip Procházka <filip@prochazka.su>
*/
abstract class BasePresenter extends Nette\Application\UI\Presenter
{
/**
* @var \Img\ImagePipe
@fprochazka
fprochazka / Nette Extension
Created October 5, 2012 09:45
Velocity http://velocity.apache.org/engine/ template for PhpStorm & #nettefw
<?php
#set( $Class_prefix = ${NAME.substring(0, $NAME.indexOf('Extension'))} )
#set( $Extension_name = ${Class_prefix.toLowerCase()} )
#parse("PHP File Header.php")
namespace Kdyby\Extension\\${Class_prefix};
use Kdyby;
use Nette;