Skip to content

Instantly share code, notes, and snippets.

View matej21's full-sized avatar

David Matějka matej21

View GitHub Profile
<?php
class MyFormFactory
{
public function create(BusinessCard $card)
{
$form = new Form;
$form->addText(...);
$form->onSuccess[] = function ($form) use ($card) {
$this->processForm($form, $card);
<?php
class RouterFactory
{
public /* static */ function createRouter()
{
$router = new Nette\Application\Routers\RouteList();
$router[] = $adminRouter = new Nette\Application\Routers\RouteList("Admin");
@matej21
matej21 / MessageFactory.php
Created January 15, 2015 16:14
Tovarna na message
<?php
interface MessageFactory
{
/**
* @return \Nette\Mail\Message
*/
public function create();
}
@matej21
matej21 / BasePresenter.php
Last active March 14, 2024 08:32
Backlink
<?php
/** @var string @persistent */
public $_backlink;
public function link($destination, $args = [])
{
$modifiers = [];
if (($pos = strrpos($destination, ')')) !== FALSE) {
$modifiers = array_fill_keys(explode(')(', substr($destination, 1, $pos - 1)), TRUE);
$destination = substr($destination, $pos + 1);
<?php
class Foo
{
public function __construct($id, FooModel $fooModel)
{
...
}
}
@matej21
matej21 / read.lua
Last active August 29, 2015 14:07
Redis script overujici invalidace zaznamu
local key = KEYS[1]
local val = redis.call("get", key)
if val == nil then
return nil
end
local tags = redis.call('sMembers', "Nette.Journal:" .. key .. ":tags")
local expirations = redis.call("hMGet", "invalidations", unpack(tags))
local added = nil
@matej21
matej21 / Context.php
Last active August 29, 2015 14:06
Prefixovane tabulky
<?php
class Context extends \Nette\Database\Context
{
protected $prefix = "";
public function setPrefix($prefix)
{
$this->prefix = $prefix;
<?php
class SecuredPresneter extends BasePresenter
{
public function checkRequirements($element)
{
$this->user->storage->setNamespace('admin'); //stejny jako v configu
if (!$this->getUser()->isLoggedIn()) {
$this->redirect($this->getLoginPage()); //nejaka tvoje kontrola
}
}
<?php
public function beforeCompile()
{
$navigationFactory = $builder->getDefinition($this->prefix('navigationFactory'));
$priorityQueue = new \SplPriorityQueue();
foreach ($builder->findByTag(self::NAVIGATION_CONTRIBUTOR) as $name => $attrs) {
$priorityQueue->insert('@' . $name, is_array($attrs) && isset($attrs['priority']) ? $attrs['priority'] : self::DEFAULT_NAVIGATION_CONTRIBUTOR_PRIORITY);
}
@matej21
matej21 / clover.phtml
Created September 5, 2014 18:50
tester + clover format
<<?php ?>?xml version="1.0" encoding="UTF-8"?>
<coverage generated="<?php echo time(); ?>">
<project>
<?php foreach ($files as $id => $info): ?>
<file name="<?php echo htmlspecialchars($info->file); ?>">
<?php foreach ($info->lines as $line => $arg): if($arg < -1) continue; ?>
<line num="<?php echo intval($line); ?>" count="<?php echo $arg >= 1 ? 1 : 0 ?>"/>
<?php endforeach; ?>
</file>
<?php endforeach; ?>