src/Codegen/CodegenBase.php
public function generateFile($strModuleSubPath, $strTemplateFilePath, $mixArgumentArray, $blnSave = true)
    {
        // Setup Debug/Exception Message
        if (Codegen::DEBUG_MODE) {
            echo("Evaluating $strTemplateFilePath<br/>");
        }

        // Check to see if the template file exists, and if it does, Load It
        if (!file_exists($strTemplateFilePath)) {
            throw new Caller('Template File Not Found: ' . $strTemplateFilePath);
        }

        // Evaluate the Template
        // make sure paths are set up to pick up included files from the various directories.
        // Must be the reverse of the buildTemplateArray order
        $a = array();
        foreach (static::$TemplatePaths as $strTemplatePath) {
            array_unshift($a, $strTemplatePath . $strModuleSubPath);
        }
        $strSearchPath = implode(PATH_SEPARATOR, $a) . PATH_SEPARATOR . get_include_path();
        $strOldIncludePath = set_include_path($strSearchPath);
        if ($strSearchPath != get_include_path()) {
            throw new Caller ('Can\'t override include path. Make sure your apache or server settings allow include paths to be overridden. ');
        }

        $strTemplate = $this->evaluatePHP($strTemplateFilePath, $mixArgumentArray, $templateSettings);
        set_include_path($strOldIncludePath);

        $blnOverwriteFlag = Type::cast($templateSettings['OverwriteFlag'], Type::BOOLEAN);
        $strTargetDirectory = Type::cast($templateSettings['TargetDirectory'], Type::STRING);
        $strDirectorySuffix = Type::cast($templateSettings['DirectorySuffix'], Type::STRING);
        $strTargetFileName = Type::cast($templateSettings['TargetFileName'], Type::STRING);

        if (is_null($blnOverwriteFlag) || is_null($strTargetFileName) || is_null($strTargetDirectory) || is_null($strDirectorySuffix)) {
            throw new \Exception('the template settings cannot be null');
        }

        if ($blnSave && $strTargetDirectory) {
            // Figure out the REAL target directory
            $strTargetDirectory = $strTargetDirectory . $strDirectorySuffix;

            // Create Directory (if needed)
            if (!is_dir($strTargetDirectory)) {
                if (!Folder::makeDirectory($strTargetDirectory, 0777)) {
                    throw new \Exception('Unable to mkdir ' . $strTargetDirectory);
                }
            }

            // Save to Disk
            $strFilePath = sprintf('%s/%s', $strTargetDirectory, $strTargetFileName);
            if ($blnOverwriteFlag || (!file_exists($strFilePath))) {
                $intBytesSaved = file_put_contents($strFilePath, $strTemplate);

                $this->setGeneratedFilePermissions($strFilePath);
                return ($intBytesSaved == strlen($strTemplate));
            } else // Becuase we are not supposed to overwrite, we should return "true" by default
            {
                return true;
            }
        }

        // Why Did We Not Save?
        if ($blnSave) {
            // We WANT to Save, but QCubed Configuration says that this functionality/feature should no longer be generated
            // By definition, we should return "true"
            return true;
        }
        // Running GenerateFile() specifically asking it not to save -- so return the evaluated template instead
        return $strTemplate;
    }
public function generateFile($strModuleSubPath, $strTemplateFilePath, $mixArgumentArray, $blnSave = true)
    {
        // Setup Debug/Exception Message
        if (Codegen::DEBUG_MODE) {
            echo("Evaluating $strTemplateFilePath<br/>");
        }

        // Check to see if the template file exists, and if it does, Load It
        if (!file_exists($strTemplateFilePath)) {
            throw new Caller('Template File Not Found: ' . $strTemplateFilePath);
        }

        // Evaluate the Template
        // make sure paths are set up to pick up included files from the various directories.
        // Must be the reverse of the buildTemplateArray order
        $a = array();
        foreach (static::$TemplatePaths as $strTemplatePath) {
            array_unshift($a, $strTemplatePath . $strModuleSubPath);
        }
        $strSearchPath = implode(PATH_SEPARATOR, $a) . PATH_SEPARATOR . get_include_path();
        $strOldIncludePath = set_include_path($strSearchPath);
        if ($strSearchPath != get_include_path()) {
            throw new Caller ('Can\'t override include path. Make sure your apache or server settings allow include paths to be overridden. ');
        }

        $strTemplate = $this->evaluatePHP($strTemplateFilePath, $mixArgumentArray, $templateSettings);
        set_include_path($strOldIncludePath);

        $blnOverwriteFlag = Type::cast($templateSettings['OverwriteFlag'], Type::BOOLEAN);
        $strTargetDirectory = Type::cast($templateSettings['TargetDirectory'], Type::STRING);
        $strDirectorySuffix = Type::cast($templateSettings['DirectorySuffix'], Type::STRING);
        $strTargetFileName = Type::cast($templateSettings['TargetFileName'], Type::STRING);

        if (is_null($blnOverwriteFlag) || is_null($strTargetFileName) || is_null($strTargetDirectory) || is_null($strDirectorySuffix)) {
            throw new \Exception('the template settings cannot be null');
        }

        if ($blnSave && $strTargetDirectory) {
            // Figure out the REAL target directory
            $strTargetDirectory = $strTargetDirectory . $strDirectorySuffix;

            // Create Directory (if needed)
            if (!is_dir($strTargetDirectory)) {
                if (!Folder::makeDirectory($strTargetDirectory, 0777)) {
                    throw new \Exception('Unable to mkdir ' . $strTargetDirectory);
                }
            }

            // Save to Disk
            $strFilePath = sprintf('%s/%s', $strTargetDirectory, $strTargetFileName);
            if ($blnOverwriteFlag || (!file_exists($strFilePath))) {
                $intBytesSaved = file_put_contents($strFilePath, $strTemplate);

                $this->setGeneratedFilePermissions($strFilePath);
                return ($intBytesSaved == strlen($strTemplate));
            } else // Becuase we are not supposed to overwrite, we should return "true" by default
            {
                return true;
            }
        }

        // Why Did We Not Save?
        if ($blnSave) {
            // We WANT to Save, but QCubed Configuration says that this functionality/feature should no longer be generated
            // By definition, we should return "true"
            return true;
        }
        // Running GenerateFile() specifically asking it not to save -- so return the evaluated template instead
        return $strTemplate;
    }
public function generateFile ( $ strModuleSubPath , $ strTemplateFilePath , $ mixArgumentArray , $ blnSave = true ) { // Setup Debug/Exception Message if ( Codegen :: DEBUG_MODE ) { echo ( "Evaluating $strTemplateFilePath<br/>" ) ; } // Check to see if the template file exists, and if it does, Load It if ( ! file_exists ( $ strTemplateFilePath ) ) { throw new Caller ( 'Template File Not Found: ' . $ strTemplateFilePath ) ; } // Evaluate the Template // make sure paths are set up to pick up included files from the various directories. // Must be the reverse of the buildTemplateArray order $ a = array ( ) ; foreach ( static :: $ TemplatePaths as $ strTemplatePath ) { array_unshift ( $ a , $ strTemplatePath . $ strModuleSubPath ) ; } $ strSearchPath = implode ( PATH_SEPARATOR , $ a ) . PATH_SEPARATOR . get_include_path ( ) ; $ strOldIncludePath = set_include_path ( $ strSearchPath ) ; if ( $ strSearchPath != get_include_path ( ) ) { throw new Caller ( 'Can\'t override include path. Make sure your apache or server settings allow include paths to be overridden. ' ) ; } $ strTemplate = $ this -> evaluatePHP ( $ strTemplateFilePath , $ mixArgumentArray , $ templateSettings ) ; set_include_path ( $ strOldIncludePath ) ; $ blnOverwriteFlag = Type :: cast ( $ templateSettings [ 'OverwriteFlag' ] , Type :: BOOLEAN ) ; $ strTargetDirectory = Type :: cast ( $ templateSettings [ 'TargetDirectory' ] , Type :: STRING ) ; $ strDirectorySuffix = Type :: cast ( $ templateSettings [ 'DirectorySuffix' ] , Type :: STRING ) ; $ strTargetFileName = Type :: cast ( $ templateSettings [ 'TargetFileName' ] , Type :: STRING ) ; if ( is_null ( $ blnOverwriteFlag ) || is_null ( $ strTargetFileName ) || is_null ( $ strTargetDirectory ) || is_null ( $ strDirectorySuffix ) ) { throw new \ Exception ( 'the template settings cannot be null' ) ; } if ( $ blnSave && $ strTargetDirectory ) { // Figure out the REAL target directory $ strTargetDirectory = $ strTargetDirectory . $ strDirectorySuffix ; // Create Directory (if needed) if ( ! is_dir ( $ strTargetDirectory ) ) { if ( ! Folder :: makeDirectory ( $ strTargetDirectory , 0777 ) ) { throw new \ Exception ( 'Unable to mkdir ' . $ strTargetDirectory ) ; } } // Save to Disk $ strFilePath = sprintf ( '%s/%s' , $ strTargetDirectory , $ strTargetFileName ) ; if ( $ blnOverwriteFlag || ( ! file_exists ( $ strFilePath ) ) ) { $ intBytesSaved = file_put_contents ( $ strFilePath , $ strTemplate ) ; $ this -> setGeneratedFilePermissions ( $ strFilePath ) ; return ( $ intBytesSaved == strlen ( $ strTemplate ) ) ; } else // Becuase we are not supposed to overwrite, we should return "true" by default { return true ; } } // Why Did We Not Save? if ( $ blnSave ) { // We WANT to Save, but QCubed Configuration says that this functionality/feature should no longer be generated // By definition, we should return "true" return true ; } // Running GenerateFile() specifically asking it not to save -- so return the evaluated template instead return $ strTemplate ; }
Generates a php code using a template file

@param string $strModuleSubPath
@param string $strTemplateFilePath Path to the template file
@param mixed[] $mixArgumentArray
@param boolean $blnSave whether or not to actually perform the save

@throws Caller
@throws \Exception
@return mixed returns the evaluated template or boolean save success.
Generates a php code using a template file