From: Andrey Kutejko Date: Thu, 11 Jul 2013 18:41:32 +0000 (+0300) Subject: generate model admin class stub X-Git-Tag: 0.5~174 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=b6079724c593bb9ce8e16c9b3b845b4217593723;p=ipf.git generate model admin class stub --- diff --git a/ipf/orm/import/builder.php b/ipf/orm/import/builder.php index 246e87b..09330d2 100644 --- a/ipf/orm/import/builder.php +++ b/ipf/orm/import/builder.php @@ -395,6 +395,8 @@ class IPF_ORM_Import_Builder $code[] = $this->buildTableDefinition($definition); $code[] = ''; $code[] = $this->buildSetUp($definition); + $code[] = ''; + $code = array_merge($code, $this->buildShortcuts($definition)); $code[] = '}'; $fileName = $this->_baseClassPrefix . $definition['className'] . '.php'; @@ -406,21 +408,49 @@ class IPF_ORM_Import_Builder throw new IPF_ORM_Exception("Couldn't write file " . $writePath); } + private function buildShortcuts(array $definition) + { + return array( + ' public static function table()', + ' {', + ' return IPF_ORM::getTable(\''.$definition['className'].'\');', + ' }', + '', + ' public static function query($alias=\'\')', + ' {', + ' return IPF_ORM::getTable(\''.$definition['className'].'\')->createQuery($alias);', + ' }', + ); + } + private function writeModelDefinition(array $definition, $targetPath) { $className = $definition['className']; + $adminClassName = $className.'Admin'; $writePath = $targetPath . DIRECTORY_SEPARATOR . $className . '.php'; if (file_exists($writePath)) return; - $code = sprintf("_baseClassPrefix, - $className); + $code = array( + '_baseClassPrefix, $className), + '{', + '}', + '', + '/*', + 'class '.$adminClassName.' extends IPF_Model_Admin', + '{', + '}', + '', + 'IPF_Model_Admin::register(\''.$className.'\', \''.$adminClassName.'\');', + '*/', + '', + ); IPF_Utils::makeDirectories($targetPath); - if (file_put_contents($writePath, $code) === false) + if (file_put_contents($writePath, implode(PHP_EOL, $code)) === false) throw new IPF_ORM_Exception("Couldn't write file " . $writePath); IPF_ORM::loadModel($className, $writePath);