Skip to content

Instantly share code, notes, and snippets.

View matej21's full-sized avatar

David Matějka matej21

View GitHub Profile
<?php
public function beforeCompile()
{
$builder = $this->getContainerBuilder();
$targetServiceDef = $builder->getDefinition($this->prefix('serviceName'));
foreach ($builder->findByTag('myTag') as $name => $attrs) {
$def = $builder->getDefinition($name);
$targetServideDef->addSetup('addFoo', array($def));
}
<?php
interface IUserAccessor
{
/**
* @return \Nette\Security\User
*/
public function get();
}
@matej21
matej21 / default.latte
Created August 2, 2014 20:41
Invalidace formularovych prvku
{snippetArea form}
{form myForm}
{inlineSnippet name}
{input name}
{/inlineSnippet}
{input ok}
{/form}
{/snippetArea}
<a n:href="redraw!" class="ajax">prekresli</a>
@matej21
matej21 / Gruntfile.js
Last active August 29, 2015 14:04
grunt + webloader
uglify: {
options: {
compress: false,
sourceMap: true
},
front: {
files: {
'./www/dist/front/output.js': [
"./www/vendor/jquery/dist/jquery.js",
"./www/vendor/nette.ajax.js/nette.ajax.js",
@matej21
matej21 / Presenter.php
Created August 7, 2014 23:27
nested snippets
<?php
$this->redrawControl('snippet-nested-sub2');
@matej21
matej21 / FooControl.php
Created August 12, 2014 10:41
komponenty
<?php
use Nette\Application\UI;
class FooControl extends UI\Control
{
public function __construct(...)
{
//predani parametru a zavislosti
}
@matej21
matej21 / config.neon
Last active August 29, 2015 14:05
Base třídy - konečné řešení
extensions:
setup: Librette\Setup\SetupExtension
setup:
#nastavi sitename na vsech presenterech, ktery dedi od BasePresenteru a jsou registrovany v DIC
-
type: [App\BasePresenter]
setup:
- setSiteName('example.com')
#zapne inject na vsech komponentach (i tech, ktere jsou vytvareny gen. tovarnickou), ktere dedi od BaseControlu
-
<?php
$route = new Route("...", array(
"presenter" => "Foo",
"action" => "default",
NULL => array(
Route::FILTER_IN => function(array $params) {
//upravim parametry jak potrebuju, pripadne muzu vratit NULL pro zamitnuti routy
return $params; //pokud vse ok
},
@matej21
matej21 / daoUsage.php
Created September 1, 2014 21:55
Kdyby\Doctrine
<?php
$dao = $em->getDao(Article::class);
$allArticles = $dao->findAll();
$filteredAndSorted = $dao->findBy(['category' => $category], ['title' => 'asc']);
$singleByFilter = $dao->findOneBy(['title' => 'Foo bar']);
$single = $dao->find(1);
@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; ?>