I'm attempting to enhance the method that i'm using to to database transactions inside a light framework I have built.

Information to know the question:

Here is a class I have written (where connect.php loads up database qualifications a wrapper for that PHP PDO, saved in $db and Base.php):

<?php
    require_once('connect.php');

    class Advertiser extends Base
    {
        public static function getByID($id)
        {
            global $db;
            $sql = "SELECT * FROM advertiser WHERE advertiserid=?";
            $values = array($id);
            $res = $db->qwv($sql, $values);

            return Advertiser::wrap($res);
        }

        public static function add($name)
        {
            $adv = new Advertiser(null, $name);
            $res = $adv->save();

            return $res;
        }

        public static function wrap($advs)
        {
            $advList = array();
            foreach( $advs as $adv )
            {
                array_push($advList, new Advertiser($adv['advertiserid'], $adv['name']));
            }

            return Advertiser::sendback($advList);
        }

        private $advertiserid;
        private $name;

        public function __construct($advertiserid, $name)
        {
            $this->advertiserid = $advertiserid;
            $this->name = $name;
        }

        public function __get($var)
        {
            return $this->$var;         
        }

        public function save()
        {
            global $db;
            if( !isset($this->advertiserid) )
            {
                $sql = "INSERT INTO advertisers (name) VALUES(?)";
                $values = array($this->name);
                $db->qwv($sql, $values);

                if( $db->stat() )
                {
                    $this->advertiserid = $db->last();
                    return $this;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                $sql = "UPDATE advertisers SET name=? WHERE advertiserid=?";
                $values = array ($this->name, $this->advertiserid);
                $db->qwv($sql, $values);

                return $db->stat();
            }
        }
    }
?>

As you can tell, it's fairly standard CRUD functions (Edit: Okay, so only CRU, within this implementation). Sometimes, I'll extend a category such as this with the addition of more functions, that is what these classes are meant for. For instance, I would add the next function for this class (presuming I give a column isBanned towards the database):

public static function getBanned()
{
    global $db;
    $sql = "SELECT * FROM advertiser WHERE isBanned=1";
    $res = $db->q($sql);

    return Advertiser::wrap($res);
}

The question:

How do i produce a catchall class which will also stock up custom model classes when present and necessary?

For instance, basically write the next code:

$model = new Catchall();
$banned = $model->Advertiser::getByID(4);

I'd expect my catchall class to change its queries to ensure that all of the references towards the tables/posts are whatever title I selected (Advertiser, within this situation), however in lower situation.

Additionally, basically wanted to produce a custom function such as the one I authored above, I'd expect my catchall class to find out that the file is available in the path (formerly defined, obviously) using the title that I have specified (Advertisers.php, within this situation) and load it.

Advertisers.php would extends Catchall and would contain only my custom function.

In by doing this, I will have a single Catchall class that will work with all CRUD functions, and have the ability to easily expand arbitrary classes as necessary.

  1. Do you know the ideas / concepts that I have to understand to get this done?
  2. How can i find good examples of the already within the wild, without digging through lots of CodeIgniter or Zend sourcecode?
  3. What's what I am attempting to do known as?