Removed dep on API
[ninja.git] / src / op5 / ninja_sdk / orm / ORMRootPoolGenerator.php
blobd68c46a096cef1f947127bcdf6b0bc69dd0d30a9
1 <?php
3 class ORMRootPoolGenerator extends class_generator {
5 private $structure;
6 private $objectclass;
8 public function __construct() {
9 $this->classname = 'BaseObjectPool';
10 $this->set_model();
13 public function generate($skip_generated_note = false) {
14 parent::generate($skip_generated_note);
15 $this->init_class( false, array('abstract') );
16 $this->variable('table',false,'protected');
17 $this->variable('table_classes',false,'private static');
18 $this->generate_pool();
19 $this->generate_load_table_classes();
20 $this->generate_fetch_by_key();
21 $this->finish_class();
24 private function generate_pool() {
25 $this->init_function( 'pool', array('name'), 'static' );
27 $this->write( 'if( self::$table_classes === false ) {' );
28 $this->write( 'self::$table_classes = static::load_table_classes();' );
29 $this->write( '}' );
31 $this->write( 'if( isset(self::$table_classes[$name]) ) {' );
32 $this->write( 'return new self::$table_classes[$name]["pool"]();' );
33 $this->write( '}' );
35 $this->write( 'throw new ORMException("Unknown table ".$name);' );
36 $this->finish_function();
38 private function generate_load_table_classes() {
39 $this->init_function( 'load_table_classes', array(), 'static' );
40 $this->write( 'return array();' );
41 $this->finish_function();
44 /**
45 * undocumented function
47 * @return void
48 **/
49 private function generate_fetch_by_key() {
50 $this->init_function( 'fetch_by_key', array('key'), 'static' );
51 $this->write( 'return false;' );
52 $this->finish_function();