Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

model_loading_zend vs. pearStyle #33

Open
djungbluth opened this issue Sep 22, 2011 · 1 comment
Open

model_loading_zend vs. pearStyle #33

djungbluth opened this issue Sep 22, 2011 · 1 comment

Comments

@djungbluth
Copy link

Hi,

I'd like to integrate zf-doctrine into a ZF project with modules, but I'm stuck at the point when it comes to "generate-models-from-yaml".

Example: The schema file contains a definition for Default_Model_Mail_Template. I would expect the generated model file to be placed at

application/modules/default/models/Mail/Template.php

but instead,

application/modules/default/models/Mail_Template.php

is generated. I've tried to set resources.doctrine.generateModels.pearStyle = 1 in my application config but without effect (as it gets overwritten by some defaults in ZFDoctrine_Import_Schema).

Model loading is set to model_loading_zend.

I really need some assist, please. Thanks!

@djungbluth
Copy link
Author

I'd like to propose a patch to enable support for pear-style model class naming:

Index: library/ZFDoctrine/Import/Builder.php
===================================================================
--- library/ZFDoctrine/Import/Builder.php   (revision 28631)
+++ library/ZFDoctrine/Import/Builder.php   (working copy)
@@ -34,6 +34,10 @@
         $pos = strpos($originalClassName, 'Model_');
         $originalClassName = substr($originalClassName, $pos+6);
 
+        if ($this->_pearStyle) {
+            $originalClassName = str_replace('_', '/', $originalClassName);
+        }
+
         $file = $originalClassName . $this->_suffix;
 
         return $file;
@@ -49,7 +53,11 @@
         $className = $definition['tableClassName'];
         $pos = strpos($className, "Model_");
         $fileName = substr($className, $pos+6) . $this->_suffix;
-        $writePath = $path . DIRECTORY_SEPARATOR . $fileName;
+        if ($this->_pearStyle) {
+            $writePath = $path . DIRECTORY_SEPARATOR . str_replace('_', '/', $fileName);
+        } else {
+            $writePath = $path . DIRECTORY_SEPARATOR . $fileName;
+        }
 
         $content = $this->buildTableClassDefinition($className, $definition, $options);
 
Index: library/ZFDoctrine/Import/Schema.php
===================================================================
--- library/ZFDoctrine/Import/Schema.php    (revision 28631)
+++ library/ZFDoctrine/Import/Schema.php    (working copy)
@@ -91,7 +91,6 @@
     public function getOptions()
     {
         $options = parent::getOptions();
-        $options['pearStyle'] = false;
         $options['baseClassesDirectory'] = 'Base';
         $options['baseClassPrefix'] = '';
         $options['classPrefix'] = '';

By doing so, one can enable pearStyle in application config. In INI, for example:

resources.doctrine.generateModels.pearStyle = 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant