Skip to content

Instantly share code, notes, and snippets.

@toopay
Created June 20, 2013 15:35
Show Gist options
  • Save toopay/5823830 to your computer and use it in GitHub Desktop.
Save toopay/5823830 to your computer and use it in GitHub Desktop.
Base Model Example
<?php namespace Model;
use \Gas\ORM;
use \Gas\Core;
class Base extends ORM {
/**
* Initial _init, that should be overided by sub-classes
*/
public function _init()
{
throw new \Exception(__CLASS__.' should have '.__METHOD__);
}
/**
* Overloading method triggered when invoking special method.
*
* @param string
* @param array
* @return mixed
*/
public function __call($name, $arguments)
{
if ($name == 'all')
{
// Here you could hook into gas instance
}
return parent::__call($name,$arguments);
}
/**
* Overloading static method triggered when invoking special method.
*
* @param string
* @param array
* @return mixed
*/
public static function __callStatic($name, $arguments)
{
$gas = self::make();
$arguments = self::validate_method($name, $arguments);
if ($name == 'with')
{
// Mark necessary entities
foreach ($arguments as $index => $entity)
{
$gas->related->set('include.'.$index, $entity);
}
// Eager loaded entities has been marker
return $gas;
}
elseif (class_exists('\\Gas\\Extension\\'.ucfirst($name)))
{
// We need to mark the extension property
// Assign the extension
$extension_name = '\\Gas\\Extension\\'.ucfirst($name);
$gas->extension = new $extension_name();
// Return for further process
return $gas;
}
if ($name == 'all')
{
// Here you could hook into gas instance
}
return Core::compile($gas, $name, $arguments);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment