Initializer fails on dynamic code generation

Issue #5 new
Former user created an issue

If you run make for the PHP api the dynamic classes will be generated but the variables containing the constants, the classnames e.g. are not interpreted because single quotes are used and strings in single quotes won't be interpreted.

I wanted to make a pull request but that was not possible. So here the git diff for the working version.

diff --git a/php/idoit/Lib/Initialize.php b/php/idoit/Lib/Initialize.php
index 34954be..cf83980 100644
--- a/php/idoit/Lib/Initialize.php
+++ b/php/idoit/Lib/Initialize.php
@@ -115,14 +115,14 @@ try {
      */
     $year = date('Y');

-    $phpHeader = '<?php
+    $phpHeader = "<?php
 /**
  * i-doit PHP API Client
  *
  * Copyright (c) $year Dennis Stücken
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
+ * of this software and associated documentation files (the \"Software\"), to deal
  * in the Software without restriction, including without limitation the rights
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  * copies of the Software, and to permit persons to whom the Software is
@@ -131,7 +131,7 @@ try {
  * The above copyright notice and this permission notice shall be included in
  * all copies or substantial portions of the Software.
  *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
@@ -146,7 +146,7 @@ try {
  * @license   http://opensource.org/licenses/MIT The MIT License (MIT)
  *
  */
-';
+";

     /**
      * Write ObjectTypeConstants.php content
@@ -159,7 +159,7 @@ try {
         }
     }

-    $objectTypeFileContent = $phpHeader . '
+    $objectTypeFileContent = $phpHeader . "

 namespace idoit\Api\CMDB;

@@ -170,7 +170,7 @@ namespace idoit\Api\CMDB;
 class ObjectTypeConstants
 { $exportedConstants
 }
-';
+";

     /**
      * Write CategoryConstants.php content
@@ -249,7 +249,7 @@ class ObjectTypeConstants
         }
     }

-    $categoryFileContent = $phpHeader . '
+    $categoryFileContent = $phpHeader . "

 namespace idoit\Api\CMDB;

@@ -260,7 +260,7 @@ namespace idoit\Api\CMDB;
 class CategoryConstants
 { $exportedConstants
 }
-';
+";

     /**
      * ------------------------------------------------------------------------------------------------------------------------------
@@ -337,7 +337,7 @@ function categoryDataHeader($categoryTitle, $categoryType = 'Global', $data, $co

     $propertiesDefinition = str_replace('  );', ');', str_replace('array (', 'array(', str_replace("\n", "\n      ", var_export($propertiesArray, true))));

-    return $phpHeader . '
+    return $phpHeader . "

 namespace idoit\Api\CMDB\Category\\$categoryType;

@@ -366,10 +366,10 @@ class $categoryTitle
      *
      * @var string
      */
-    protected \$Identifier = \'$const\';
+    protected \$Identifier = '$const';


-';
+";
 }

 /**
@@ -403,7 +403,7 @@ function categoryDataContent($data, $categoryTitle, $constant)
                     $type = 'int';

                     if ($keyReadable) {
-                        $l_content .= '
+                        $l_content .= "
     /**
      * Get property $title
      *
@@ -414,9 +414,9 @@ function categoryDataContent($data, $categoryTitle, $constant)
      */
     public function getDialog$keyReadable(\$apiclient)
     {
-        return Dialog::factory(\$apiclient)->get(\$this->Identifier, \'$key\');
+        return Dialog::factory(\$apiclient)->get(\$this->Identifier, '$key');
     }
-';
+";
                         $l_content .= "\n\n";
                     }

@@ -441,7 +441,7 @@ function categoryDataContent($data, $categoryTitle, $constant)
                 $additional .= "\n\t  * @objectTypeFilter " . $prop['objectTypeFilter'];
             }

-            $l_content .= '
+            $l_content .= "
     /**
      * Get property $title
      *
@@ -453,7 +453,7 @@ function categoryDataContent($data, $categoryTitle, $constant)
      */
     public function get$keyReadable()
     {
-        return isset(\$this->Content[\'$key\']) ? \$this->Content[\'$key\'] : $defaultReturnVal;
+        return isset(\$this->Content['$key']) ? \$this->Content['$key'] : $defaultReturnVal;
     }

     /**
@@ -467,10 +467,10 @@ function categoryDataContent($data, $categoryTitle, $constant)
      */
     public function set$keyReadable($typeHint\$value)
     {
-        \$this->Content[\'$key\'] = $value;
+        \$this->Content['$key'] = \$value;
         return \$this;
     }
-';
+";
             $l_content .= "\n\n";
         }

@@ -539,4 +539,4 @@ function writeCategory($category, $type, $data, $constant)
     } else {
         throw new \Exception(sprintf('Error: Directory %s does not exist or is not writable.', $categoryDataDirectory));
     }
-}
\ No newline at end of file
+}

Comments (0)

  1. Log in to comment