2
0
Просмотр исходного кода

ZF-6959
- Added a LINE_FEED constant to Zend_CodeGenerator_Php_Abstract to be used in place of PHP_EOL

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@16284 44c647ce-9c0f-0410-b52a-842ac1e357ba

ralph 16 лет назад
Родитель
Сommit
72440e24bd

+ 7 - 1
library/Zend/CodeGenerator/Php/Abstract.php

@@ -33,7 +33,13 @@ require_once 'Zend/CodeGenerator/Abstract.php';
  */
 abstract class Zend_CodeGenerator_Php_Abstract extends Zend_CodeGenerator_Abstract
 {
-   
+
+    /**
+     * Line feed to use in place of EOL
+     *
+     */
+    const LINE_FEED = "\n";
+    
     /**
      * @var bool
      */

+ 4 - 4
library/Zend/CodeGenerator/Php/Class.php

@@ -463,23 +463,23 @@ class Zend_CodeGenerator_Php_Class extends Zend_CodeGenerator_Php_Abstract
             $output .= ' implements ' . implode(', ', $implemented);
         }
         
-        $output .= PHP_EOL . '{' . PHP_EOL . PHP_EOL;
+        $output .= self::LINE_FEED . '{' . self::LINE_FEED . self::LINE_FEED;
         
         $properties = $this->getProperties();
         if (!empty($properties)) {
             foreach ($properties as $property) {
-                $output .= $property->generate() . PHP_EOL . PHP_EOL;
+                $output .= $property->generate() . self::LINE_FEED . self::LINE_FEED;
             }
         }
         
         $methods = $this->getMethods();
         if (!empty($methods)) {
             foreach ($methods as $method) {
-                $output .= $method->generate() . PHP_EOL;
+                $output .= $method->generate() . self::LINE_FEED;
             }
         }
         
-        $output .= PHP_EOL . '}' . PHP_EOL;
+        $output .= self::LINE_FEED . '}' . self::LINE_FEED;
         
         return $output;
     }

+ 5 - 5
library/Zend/CodeGenerator/Php/Docblock.php

@@ -185,10 +185,10 @@ class Zend_CodeGenerator_Php_Docblock extends Zend_CodeGenerator_Php_Abstract
         
         $output  = '';
         if (null !== ($sd = $this->getShortDescription())) {
-            $output .= $sd . PHP_EOL . PHP_EOL;
+            $output .= $sd . self::LINE_FEED . self::LINE_FEED;
         }
         if (null !== ($ld = $this->getLongDescription())) {
-            $output .= $ld . PHP_EOL . PHP_EOL;
+            $output .= $ld . self::LINE_FEED . self::LINE_FEED;
         }
 
         foreach ($this->getTags() as $tag) {
@@ -207,13 +207,13 @@ class Zend_CodeGenerator_Php_Docblock extends Zend_CodeGenerator_Php_Abstract
     protected function _docCommentize($content)
     {
         $indent = $this->getIndentation();
-        $output = '/**' . PHP_EOL;
+        $output = '/**' . self::LINE_FEED;
         $content = wordwrap($content, 80, "\n");
         $lines = explode("\n", $content);
         foreach ($lines as $line) {
-            $output .= $indent . ' * ' . $line . PHP_EOL;
+            $output .= $indent . ' * ' . $line . self::LINE_FEED;
         }
-        $output .= $indent . ' */' . PHP_EOL;
+        $output .= $indent . ' */' . self::LINE_FEED;
         return $output;
     }
     

+ 3 - 3
library/Zend/CodeGenerator/Php/Docblock/Tag.php

@@ -23,7 +23,7 @@
 /**
  * @see Zend_CodeGenerator_Abstract
  */
-require_once 'Zend/CodeGenerator/Abstract.php';
+require_once 'Zend/CodeGenerator/Php/Abstract.php';
 
 /**
  * @see Zend_CodeGenerator_Php_Docblock_Tag_Param
@@ -41,7 +41,7 @@ require_once 'Zend/CodeGenerator/Php/Docblock/Tag/Return.php';
  * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  * @license    http://framework.zend.com/license/new-bsd     New BSD License
  */
-class Zend_CodeGenerator_Php_Docblock_Tag extends Zend_CodeGenerator_Abstract
+class Zend_CodeGenerator_Php_Docblock_Tag extends Zend_CodeGenerator_Php_Abstract
 {
 
     /**
@@ -178,7 +178,7 @@ class Zend_CodeGenerator_Php_Docblock_Tag extends Zend_CodeGenerator_Abstract
      */
     public function generate()
     {
-        return '@' . $this->_name . ' ' . $this->_description . PHP_EOL;
+        return '@' . $this->_name . ' ' . $this->_description . self::LINE_FEED;
     }
     
 }

+ 1 - 1
library/Zend/CodeGenerator/Php/Docblock/Tag/License.php

@@ -91,7 +91,7 @@ class Zend_CodeGenerator_Php_Docblock_Tag_License extends Zend_CodeGenerator_Php
      */
     public function generate()
     {
-        $output = '@license ' . $this->_url . ' ' . $this->_description . PHP_EOL;
+        $output = '@license ' . $this->_url . ' ' . $this->_description . self::LINE_FEED;
         return $output;
     }
     

+ 1 - 1
library/Zend/CodeGenerator/Php/Docblock/Tag/Param.php

@@ -118,7 +118,7 @@ class Zend_CodeGenerator_Php_Docblock_Tag_Param extends Zend_CodeGenerator_Php_D
      */
     public function generate()
     {
-        $output = '@param ' . $this->_datatype . ' ' . $this->_paramName . ' ' . $this->_description . PHP_EOL;
+        $output = '@param ' . $this->_datatype . ' ' . $this->_paramName . ' ' . $this->_description . self::LINE_FEED;
         return $output;
     }
     

+ 1 - 1
library/Zend/CodeGenerator/Php/Docblock/Tag/Return.php

@@ -91,7 +91,7 @@ class Zend_CodeGenerator_Php_Docblock_Tag_Return extends Zend_CodeGenerator_Php_
      */
     public function generate()
     {
-        $output = '@return ' . $this->_datatype . ' ' . $this->_description . PHP_EOL;
+        $output = '@return ' . $this->_datatype . ' ' . $this->_description . self::LINE_FEED;
         return $output;
     }
     

+ 7 - 7
library/Zend/CodeGenerator/Php/File.php

@@ -389,7 +389,7 @@ class Zend_CodeGenerator_Php_File extends Zend_CodeGenerator_Php_Abstract
         
         // start with the body (if there), or open tag
         if (preg_match('#(?:\s*)<\?php#', $this->getBody()) == false) {
-            $output = '<?php' . PHP_EOL;
+            $output = '<?php' . self::LINE_FEED;
         }
         
         // if there are markers, put the body into the output
@@ -406,22 +406,22 @@ class Zend_CodeGenerator_Php_File extends Zend_CodeGenerator_Php_Abstract
             if (preg_match('#'.$regex.'#', $output)) {
                 $output  = preg_replace('#'.$regex.'#', $docblock->generate(), $output, 1);
             } else {
-                $output .= $docblock->generate() . PHP_EOL;
+                $output .= $docblock->generate() . self::LINE_FEED;
             }
         }
         
         // newline
-        $output .= PHP_EOL;
+        $output .= self::LINE_FEED;
         
         // process required files
         // @todo marker replacement for required files
         $requiredFiles = $this->getRequiredFiles();
         if (!empty($requiredFiles)) {
             foreach ($requiredFiles as $requiredFile) {
-                $output .= 'require_once \'' . $requiredFile . '\';' . PHP_EOL;
+                $output .= 'require_once \'' . $requiredFile . '\';' . self::LINE_FEED;
             }
             
-            $output .= PHP_EOL;
+            $output .= self::LINE_FEED;
         }
         
         // process classes
@@ -433,7 +433,7 @@ class Zend_CodeGenerator_Php_File extends Zend_CodeGenerator_Php_Abstract
                 if (preg_match('#'.$regex.'#', $output)) {
                     $output = preg_replace('#'.$regex.'#', $class->generate(), $output, 1);
                 } else {
-                    $output .= $class->generate() . PHP_EOL;
+                    $output .= $class->generate() . self::LINE_FEED;
                 }
             }
             
@@ -443,7 +443,7 @@ class Zend_CodeGenerator_Php_File extends Zend_CodeGenerator_Php_Abstract
 
             // add an extra space betwee clsses and 
             if (!empty($classes)) {
-                $output .= PHP_EOL;
+                $output .= self::LINE_FEED;
             }
         
             $output .= $body;

+ 4 - 4
library/Zend/CodeGenerator/Php/Method.php

@@ -211,15 +211,15 @@ class Zend_CodeGenerator_Php_Method extends Zend_CodeGenerator_Php_Member_Abstra
             $output .= implode(', ', $parameterOuput);
         }
         
-        $output .= ')' . PHP_EOL . '    {' . PHP_EOL;
+        $output .= ')' . self::LINE_FEED . '    {' . self::LINE_FEED;
 
         if ($this->_body) {
             $output .= '        ' 
-                    .  str_replace(PHP_EOL, PHP_EOL . '        ', trim($this->_body)) 
-                    .  PHP_EOL;
+                    .  str_replace(self::LINE_FEED, self::LINE_FEED . '        ', trim($this->_body)) 
+                    .  self::LINE_FEED;
         }
         
-        $output .= '    }' . PHP_EOL;
+        $output .= '    }' . self::LINE_FEED;
         
         return $output;
     }

+ 20 - 0
tests/Zend/CodeGenerator/Php/FileTest.php

@@ -172,5 +172,25 @@ EOS;
         $this->assertEquals($expectedOutput, $codeGenFileFromDisk->generate());
         
     }
+    
+    public function testFileLineEndingsAreAlwaysLineFeed()
+    {
+        $codeGenFile = new Zend_CodeGenerator_Php_File(array(
+            'requiredFiles' => array('SampleClass.php'),
+            'class' => array(
+                'abstract' => true,
+                'name' => 'SampleClass',
+                'extendedClass' => 'ExtendedClassName',
+                'implementedInterfaces' => array('Iterator', 'Traversable')            
+                )
+            ));
+            
+        // explode by newline, this would leave CF in place if it were generated
+        $lines = explode("\n", $codeGenFile);
+        
+        $targetLength = strlen('require_once \'SampleClass.php\';');
+        $this->assertEquals($targetLength, strlen($lines[2]));
+        $this->assertEquals(';', $lines[2]{$targetLength-1});
+    }
 
 }