Instantly share code, notes, and snippets.

Embed
What would you like to do?
Idea for NotORM named queries
<?php
namespace My;
class NotORM extends \NotORM
{
public static function getReflection()
{
return new Nette\Reflection\ClassType(get_called_class());
}
public function __call($name, $args)
{
// extension methods
if ($cb = $this->getReflection()->getExtensionMethod($name)) {
array_unshift($args, $this);
return $cb->invokeArgs($args);
}
return parent::__call($name, $args);
}
public function setNamedQuery($name, $query)
{
$this->getReflection()->setExtensionMethod($name, $query);
}
}
$notOrm = new NotORM(...);
$notOrm->setNamedQuery('someQuery', function ($NotORM, $param1, $param2, ...) {
return $NotORM->page('id', $NotORM->page()->select('MAX(id) id')->group('parent, url');
});
$notOrm->someQuery($param1, $param2)->...
@fprochazka

This comment has been minimized.

Owner

fprochazka commented Feb 27, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment