From ae8982efe57fab6ccc02d62a1ce4005a128fb69b Mon Sep 17 00:00:00 2001 From: DmitryPuchkov Date: Wed, 3 Sep 2008 18:41:34 +0300 Subject: [PATCH] load models refactor DirectoryIterator --- ipf.php | 5 ++ ipf/admin/models/_generated/BaseAdminLog.php | 66 +++++++------- ipf/auth/models/_generated/BasePermission.php | 58 ++++++------ ipf/auth/models/_generated/BaseRole.php | 58 ++++++------ .../models/_generated/BaseRolePermission.php | 52 +++++------ ipf/auth/models/_generated/BaseUser.php | 88 +++++++++---------- .../models/_generated/BaseUserPermission.php | 52 +++++------ ipf/auth/models/_generated/BaseUserRole.php | 52 +++++------ ipf/orm.php | 51 ++++------- ipf/session/models/_generated/BaseSession.php | 30 +++---- 10 files changed, 248 insertions(+), 264 deletions(-) diff --git a/ipf.php b/ipf.php index 3ef90c4..a1bdebf 100644 --- a/ipf.php +++ b/ipf.php @@ -9,6 +9,11 @@ function __autoload( $class_name ){ $s .= '/'; $s .= strtolower( $folder ); } + if ($s=='basesession'){ + //print_r( debug_backtrace(false)); + debug_print_backtrace(); + die ('zzz'); + } require_once($s.'.php'); } diff --git a/ipf/admin/models/_generated/BaseAdminLog.php b/ipf/admin/models/_generated/BaseAdminLog.php index 930e5eb..31b037e 100644 --- a/ipf/admin/models/_generated/BaseAdminLog.php +++ b/ipf/admin/models/_generated/BaseAdminLog.php @@ -1,34 +1,34 @@ -setTableName('admin_log'); - $this->hasColumn('username', 'string', 32, array('type' => 'string', 'length' => '32')); - $this->hasColumn('user_id', 'integer', null, array('type' => 'integer')); - $this->hasColumn('object_id', 'integer', null, array('type' => 'integer')); - $this->hasColumn('object_class', 'string', 200, array('type' => 'string', 'length' => '200')); - $this->hasColumn('object_repr', 'string', 200, array('type' => 'string', 'length' => '200')); - $this->hasColumn('action_flag', 'integer', null, array('type' => 'integer')); - $this->hasColumn('change_message', 'string', 200, array('type' => 'string', 'length' => '200')); - - - $this->index('idx_object_id', array('fields' => 'object_id')); - $this->index('idx_object_class', array('fields' => 'object_class')); - $this->index('idx_created_at', array('fields' => 'created_at')); - $this->index('idx_action_flag', array('fields' => 'action_flag')); - $this->option('type', 'INNODB'); - $this->option('collate', 'utf8_unicode_ci'); - $this->option('charset', 'utf8'); - } - - public function setUp() - { - $timestampable0 = new IPF_ORM_Template_Timestampable(array('updated' => array('disabled' => true))); - $this->actAs($timestampable0); - } +setTableName('admin_log'); + $this->hasColumn('username', 'string', 32, array('type' => 'string', 'length' => '32')); + $this->hasColumn('user_id', 'integer', null, array('type' => 'integer')); + $this->hasColumn('object_id', 'integer', null, array('type' => 'integer')); + $this->hasColumn('object_class', 'string', 200, array('type' => 'string', 'length' => '200')); + $this->hasColumn('object_repr', 'string', 200, array('type' => 'string', 'length' => '200')); + $this->hasColumn('action_flag', 'integer', null, array('type' => 'integer')); + $this->hasColumn('change_message', 'string', 200, array('type' => 'string', 'length' => '200')); + + + $this->index('idx_object_id', array('fields' => 'object_id')); + $this->index('idx_object_class', array('fields' => 'object_class')); + $this->index('idx_created_at', array('fields' => 'created_at')); + $this->index('idx_action_flag', array('fields' => 'action_flag')); + $this->option('type', 'INNODB'); + $this->option('collate', 'utf8_unicode_ci'); + $this->option('charset', 'utf8'); + } + + public function setUp() + { + $timestampable0 = new IPF_ORM_Template_Timestampable(array('updated' => array('disabled' => true))); + $this->actAs($timestampable0); + } } \ No newline at end of file diff --git a/ipf/auth/models/_generated/BasePermission.php b/ipf/auth/models/_generated/BasePermission.php index 4be9891..1fabde2 100644 --- a/ipf/auth/models/_generated/BasePermission.php +++ b/ipf/auth/models/_generated/BasePermission.php @@ -1,30 +1,30 @@ -setTableName('auth_permission'); - $this->hasColumn('name', 'string', 255, array('unique' => true, 'type' => 'string', 'length' => '255')); - - $this->option('type', 'INNODB'); - $this->option('collate', 'utf8_unicode_ci'); - $this->option('charset', 'utf8'); - } - - public function setUp() - { - $this->hasMany('User as Users', array('refClass' => 'UserPermission', - 'local' => 'permission_id', - 'foreign' => 'user_id')); - - $this->hasMany('RolePermission', array('local' => 'id', - 'foreign' => 'permission_id')); - - $this->hasMany('UserPermission', array('local' => 'id', - 'foreign' => 'permission_id')); - } +setTableName('auth_permission'); + $this->hasColumn('name', 'string', 255, array('unique' => true, 'type' => 'string', 'length' => '255')); + + $this->option('type', 'INNODB'); + $this->option('collate', 'utf8_unicode_ci'); + $this->option('charset', 'utf8'); + } + + public function setUp() + { + $this->hasMany('User as Users', array('refClass' => 'UserPermission', + 'local' => 'permission_id', + 'foreign' => 'user_id')); + + $this->hasMany('RolePermission', array('local' => 'id', + 'foreign' => 'permission_id')); + + $this->hasMany('UserPermission', array('local' => 'id', + 'foreign' => 'permission_id')); + } } \ No newline at end of file diff --git a/ipf/auth/models/_generated/BaseRole.php b/ipf/auth/models/_generated/BaseRole.php index 6486330..d48cde0 100644 --- a/ipf/auth/models/_generated/BaseRole.php +++ b/ipf/auth/models/_generated/BaseRole.php @@ -1,30 +1,30 @@ -setTableName('auth_role'); - $this->hasColumn('name', 'string', 255, array('unique' => true, 'type' => 'string', 'length' => '255')); - - $this->option('type', 'INNODB'); - $this->option('collate', 'utf8_unicode_ci'); - $this->option('charset', 'utf8'); - } - - public function setUp() - { - $this->hasMany('User as Users', array('refClass' => 'UserRole', - 'local' => 'role_id', - 'foreign' => 'user_id')); - - $this->hasMany('RolePermission', array('local' => 'id', - 'foreign' => 'role_id')); - - $this->hasMany('UserRole', array('local' => 'id', - 'foreign' => 'role_id')); - } +setTableName('auth_role'); + $this->hasColumn('name', 'string', 255, array('unique' => true, 'type' => 'string', 'length' => '255')); + + $this->option('type', 'INNODB'); + $this->option('collate', 'utf8_unicode_ci'); + $this->option('charset', 'utf8'); + } + + public function setUp() + { + $this->hasMany('User as Users', array('refClass' => 'UserRole', + 'local' => 'role_id', + 'foreign' => 'user_id')); + + $this->hasMany('RolePermission', array('local' => 'id', + 'foreign' => 'role_id')); + + $this->hasMany('UserRole', array('local' => 'id', + 'foreign' => 'role_id')); + } } \ No newline at end of file diff --git a/ipf/auth/models/_generated/BaseRolePermission.php b/ipf/auth/models/_generated/BaseRolePermission.php index 807bb5b..5f49ef4 100644 --- a/ipf/auth/models/_generated/BaseRolePermission.php +++ b/ipf/auth/models/_generated/BaseRolePermission.php @@ -1,27 +1,27 @@ -setTableName('auth_role_permission'); - $this->hasColumn('role_id', 'integer', null, array('type' => 'integer', 'primary' => true)); - $this->hasColumn('permission_id', 'integer', null, array('type' => 'integer', 'primary' => true)); - - $this->option('type', 'INNODB'); - $this->option('collate', 'utf8_unicode_ci'); - $this->option('charset', 'utf8'); - } - - public function setUp() - { - $this->hasOne('Role', array('local' => 'role_id', - 'foreign' => 'id')); - - $this->hasOne('Permission', array('local' => 'permission_id', - 'foreign' => 'id')); - } +setTableName('auth_role_permission'); + $this->hasColumn('role_id', 'integer', null, array('type' => 'integer', 'primary' => true)); + $this->hasColumn('permission_id', 'integer', null, array('type' => 'integer', 'primary' => true)); + + $this->option('type', 'INNODB'); + $this->option('collate', 'utf8_unicode_ci'); + $this->option('charset', 'utf8'); + } + + public function setUp() + { + $this->hasOne('Role', array('local' => 'role_id', + 'foreign' => 'id')); + + $this->hasOne('Permission', array('local' => 'permission_id', + 'foreign' => 'id')); + } } \ No newline at end of file diff --git a/ipf/auth/models/_generated/BaseUser.php b/ipf/auth/models/_generated/BaseUser.php index 85e5e88..7f4f772 100644 --- a/ipf/auth/models/_generated/BaseUser.php +++ b/ipf/auth/models/_generated/BaseUser.php @@ -1,45 +1,45 @@ -setTableName('auth_user'); - $this->hasColumn('username', 'string', 32, array('type' => 'string', 'notblank' => true, 'notnull' => true, 'unique' => true, 'length' => '32')); - $this->hasColumn('password', 'string', 128, array('type' => 'string', 'notblank' => true, 'notnull' => true, 'length' => '128')); - $this->hasColumn('first_name', 'string', 32, array('type' => 'string', 'length' => '32')); - $this->hasColumn('last_name', 'string', 32, array('type' => 'string', 'length' => '32')); - $this->hasColumn('email', 'string', 200, array('type' => 'string', 'email' => true, 'notnull' => true, 'notblank' => true, 'unique' => true, 'length' => '200')); - $this->hasColumn('is_staff', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false)); - $this->hasColumn('is_active', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false)); - $this->hasColumn('is_superuser', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false)); - $this->hasColumn('last_login', 'timestamp', null, array('type' => 'timestamp')); - - $this->option('type', 'INNODB'); - $this->option('collate', 'utf8_unicode_ci'); - $this->option('charset', 'utf8'); - } - - public function setUp() - { - $this->hasMany('Role as Roles', array('refClass' => 'UserRole', - 'local' => 'user_id', - 'foreign' => 'role_id')); - - $this->hasMany('Permission as Permissions', array('refClass' => 'UserPermission', - 'local' => 'user_id', - 'foreign' => 'permission_id')); - - $this->hasMany('UserRole', array('local' => 'id', - 'foreign' => 'user_id')); - - $this->hasMany('UserPermission', array('local' => 'id', - 'foreign' => 'user_id')); - - $timestampable0 = new IPF_ORM_Template_Timestampable(); - $this->actAs($timestampable0); - } +setTableName('auth_user'); + $this->hasColumn('username', 'string', 32, array('type' => 'string', 'notblank' => true, 'notnull' => true, 'unique' => true, 'length' => '32')); + $this->hasColumn('password', 'string', 128, array('type' => 'string', 'notblank' => true, 'notnull' => true, 'length' => '128')); + $this->hasColumn('first_name', 'string', 32, array('type' => 'string', 'length' => '32')); + $this->hasColumn('last_name', 'string', 32, array('type' => 'string', 'length' => '32')); + $this->hasColumn('email', 'string', 200, array('type' => 'string', 'email' => true, 'notnull' => true, 'notblank' => true, 'unique' => true, 'length' => '200')); + $this->hasColumn('is_staff', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false)); + $this->hasColumn('is_active', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false)); + $this->hasColumn('is_superuser', 'boolean', null, array('type' => 'boolean', 'notnull' => true, 'default' => false)); + $this->hasColumn('last_login', 'timestamp', null, array('type' => 'timestamp')); + + $this->option('type', 'INNODB'); + $this->option('collate', 'utf8_unicode_ci'); + $this->option('charset', 'utf8'); + } + + public function setUp() + { + $this->hasMany('Role as Roles', array('refClass' => 'UserRole', + 'local' => 'user_id', + 'foreign' => 'role_id')); + + $this->hasMany('Permission as Permissions', array('refClass' => 'UserPermission', + 'local' => 'user_id', + 'foreign' => 'permission_id')); + + $this->hasMany('UserRole', array('local' => 'id', + 'foreign' => 'user_id')); + + $this->hasMany('UserPermission', array('local' => 'id', + 'foreign' => 'user_id')); + + $timestampable0 = new IPF_ORM_Template_Timestampable(); + $this->actAs($timestampable0); + } } \ No newline at end of file diff --git a/ipf/auth/models/_generated/BaseUserPermission.php b/ipf/auth/models/_generated/BaseUserPermission.php index 988247a..f8cfbd7 100644 --- a/ipf/auth/models/_generated/BaseUserPermission.php +++ b/ipf/auth/models/_generated/BaseUserPermission.php @@ -1,27 +1,27 @@ -setTableName('auth_user_permission'); - $this->hasColumn('user_id', 'integer', null, array('type' => 'integer', 'primary' => true)); - $this->hasColumn('permission_id', 'integer', null, array('type' => 'integer', 'primary' => true)); - - $this->option('type', 'INNODB'); - $this->option('collate', 'utf8_unicode_ci'); - $this->option('charset', 'utf8'); - } - - public function setUp() - { - $this->hasOne('User', array('local' => 'user_id', - 'foreign' => 'id')); - - $this->hasOne('Permission', array('local' => 'permission_id', - 'foreign' => 'id')); - } +setTableName('auth_user_permission'); + $this->hasColumn('user_id', 'integer', null, array('type' => 'integer', 'primary' => true)); + $this->hasColumn('permission_id', 'integer', null, array('type' => 'integer', 'primary' => true)); + + $this->option('type', 'INNODB'); + $this->option('collate', 'utf8_unicode_ci'); + $this->option('charset', 'utf8'); + } + + public function setUp() + { + $this->hasOne('User', array('local' => 'user_id', + 'foreign' => 'id')); + + $this->hasOne('Permission', array('local' => 'permission_id', + 'foreign' => 'id')); + } } \ No newline at end of file diff --git a/ipf/auth/models/_generated/BaseUserRole.php b/ipf/auth/models/_generated/BaseUserRole.php index 363ff01..ec5b476 100644 --- a/ipf/auth/models/_generated/BaseUserRole.php +++ b/ipf/auth/models/_generated/BaseUserRole.php @@ -1,27 +1,27 @@ -setTableName('auth_user_role'); - $this->hasColumn('user_id', 'integer', null, array('type' => 'integer', 'primary' => true)); - $this->hasColumn('role_id', 'integer', null, array('type' => 'integer', 'primary' => true)); - - $this->option('type', 'INNODB'); - $this->option('collate', 'utf8_unicode_ci'); - $this->option('charset', 'utf8'); - } - - public function setUp() - { - $this->hasOne('User', array('local' => 'user_id', - 'foreign' => 'id')); - - $this->hasOne('Role', array('local' => 'role_id', - 'foreign' => 'id')); - } +setTableName('auth_user_role'); + $this->hasColumn('user_id', 'integer', null, array('type' => 'integer', 'primary' => true)); + $this->hasColumn('role_id', 'integer', null, array('type' => 'integer', 'primary' => true)); + + $this->option('type', 'INNODB'); + $this->option('collate', 'utf8_unicode_ci'); + $this->option('charset', 'utf8'); + } + + public function setUp() + { + $this->hasOne('User', array('local' => 'user_id', + 'foreign' => 'id')); + + $this->hasOne('Role', array('local' => 'role_id', + 'foreign' => 'id')); + } } \ No newline at end of file diff --git a/ipf/orm.php b/ipf/orm.php index f930282..7a11103 100644 --- a/ipf/orm.php +++ b/ipf/orm.php @@ -242,43 +242,22 @@ final class IPF_ORM { public static function loadModels($directory, $modelLoading = null) { - $manager = IPF_ORM_Manager::getInstance(); - - $modelLoading = $modelLoading === null ? $manager->getAttribute(IPF_ORM::ATTR_MODEL_LOADING):$modelLoading; $loadedModels = array(); - if ($directory !== null) { - foreach ((array) $directory as $dir) { - if ( ! is_dir($dir)) { - throw new IPF_ORM_Exception('You must pass a valid path to a directory containing IPF_ORM models'); - } - $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::LEAVES_ONLY); - foreach ($it as $file) { - $e = explode('.', $file->getFileName()); - if (end($e) === 'php' && strpos($file->getFileName(), '.inc') === false) { - $className = $e[0]; - if ($modelLoading == IPF_ORM::MODEL_LOADING_CONSERVATIVE) { - self::loadModel($className, $file->getPathName()); - $loadedModels[$className] = $className; - } else { - //$declaredBefore = get_declared_classes(); - require_once($file->getPathName()); - $loadedModels[$className] = $className; // !!! - /* - //$declaredAfter = get_declared_classes(); - //$foundClasses = array_slice($declaredAfter, count($declaredBefore) - 1); - if ($foundClasses) { - foreach ($foundClasses as $className) { - if (self::isValidModelClass($className)) { - $loadedModels[$className] = $className; - - self::loadModel($className, $file->getPathName()); - } - } - } - */ - } - } - } + $it = new DirectoryIterator($directory.DIRECTORY_SEPARATOR.'_generated'); + foreach ($it as $file) { + $e = explode('.', $file->getFileName()); + if (end($e) === 'php') { + $className = $e[0]; + require_once($file->getPathName()); + } + } + $it = new DirectoryIterator($directory); + foreach ($it as $file) { + $e = explode('.', $file->getFileName()); + if (end($e) === 'php') { + $className = $e[0]; + require_once($file->getPathName()); + $loadedModels[$className] = $className; } } return $loadedModels; diff --git a/ipf/session/models/_generated/BaseSession.php b/ipf/session/models/_generated/BaseSession.php index b126310..4408de9 100644 --- a/ipf/session/models/_generated/BaseSession.php +++ b/ipf/session/models/_generated/BaseSession.php @@ -1,16 +1,16 @@ -setTableName('session'); - $this->hasColumn('session_key', 'string', 40, array('primary' => true, 'type' => 'string', 'length' => '40')); - $this->hasColumn('session_data', 'string', null, array('type' => 'string')); - $this->hasColumn('expire_data', 'timestamp', null, array('type' => 'timestamp')); - } - +setTableName('session'); + $this->hasColumn('session_key', 'string', 40, array('primary' => true, 'type' => 'string', 'length' => '40')); + $this->hasColumn('session_data', 'string', null, array('type' => 'string')); + $this->hasColumn('expire_data', 'timestamp', null, array('type' => 'timestamp')); + } + } \ No newline at end of file -- 2.49.0