Skip to content

Instantly share code, notes, and snippets.

@pavelkucera
pavelkucera / Extension.php
Last active December 20, 2015 22:59
How to add a factory taking parameter into Nette DIC. Both ways, using config.neon and compiler extension, have the same result.
<?php
class Extension extends \Nette\DI\CompilerExtension
{
public function loadConfiguration()
{
$container = $this->getContainerBuilder();
$container->addDefinition($this->prefix('formMapperFactory'))
->setImplement('Namespace\IFactory')
@brabijan
brabijan / DummyPresenter.php
Created July 1, 2013 16:11
Generovani odkazu mimo presentery
<?php
class DummyPresenter extends \Nette\Application\UI\Presenter
{
protected function startup()
{
parent::startup();
$this->terminate();
}
@jiripudil
jiripudil / text.md
Last active December 16, 2015 11:19
Write secure templates with Latte

Write secure templates with Latte

Writing templates can be a pain. Securing it against cross-site scripting attacks can be even worse. Sick of writing htmlspecialchars($output, ENT_QUOTES) again and again? And using htmlentities() instead when escaping input for a JavaScript snippet? Why bother when there is a templating engine that can take care of all this dirty business?

Latte is a templating engine that comes shipped as a part of Nette framework, an open-source PHP framework of Czech origin. It is dual-licensed under New BSD and GNU GPL licenses. Latte automatically secures your templates against XSS exploits using context-aware escaping. And it makes writing templates a pleasure.

So, how do you output a variable in a secure way? Simply:

{$variable}
@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!"
<?php
public function createComponent($name)
{
$ucname = ucfirst($name);
$method = 'createComponent' . $ucname;
if ($ucname !== $name && method_exists($this, $method)) {
$reflection = $this->getReflection()->getMethod($method);
if($reflection->getName() !== $method) {
return;
}
@fprochazka
fprochazka / BasePresenter.php
Created October 6, 2012 16:22
Image pipe for #nettefw templates
<?php
/**
* @author Filip Procházka <[email protected]>
*/
abstract class BasePresenter extends Nette\Application\UI\Presenter
{
/**
* @var \Img\ImagePipe
@bennadel
bennadel / index.htm
Created September 12, 2012 13:17
Mapping AngularJS Routes Onto URL Parameters And Client-Side Events
<!doctype html>
<html ng-app="Demo" ng-controller="AppController">
<head>
<meta charset="utf-8" />
<title>AngularJS Routing</title>
<style type="text/css">
a {
@vojtech-dobes
vojtech-dobes / MultiAuthenticator.php
Created August 31, 2012 12:40
Multiple ways of authentication in Nette
<?php
namespace VojtechDobes\NetteSecurity;
use Nette\InvalidArgumentException;
use Nette\Security\IAuthenticator;
use Nette\Security\IIdentity;
/**
@vojtech-dobes
vojtech-dobes / Control.php
Created August 27, 2012 08:56
Independent forms in Nette: UI\Form x UI\Control
<?php
use Nette\Application\UI;
class Form extends UI\Control
{
protected function createComponentForm()
{
$form = new UI\Form;
@mishak87
mishak87 / Router.php
Created May 24, 2012 12:01
Router for API REST like methods
<?php
namespace ApiModule;
use Nette,
Nette\Application\Request;
class Router extends Nette\Object implements Nette\Application\IRouter
{