Skip to content

Instantly share code, notes, and snippets.

@fprochazka
Created February 27, 2012 09:37
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fprochazka/1922814 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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