当前位置: 首页>>代码示例>>PHP>>正文


PHP FormBuilder::formatCode方法代码示例

本文整理汇总了PHP中FormBuilder::formatCode方法的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilder::formatCode方法的具体用法?PHP FormBuilder::formatCode怎么用?PHP FormBuilder::formatCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在FormBuilder的用法示例。


在下文中一共展示了FormBuilder::formatCode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionSave

 public function actionSave($class)
 {
     $postdata = file_get_contents("php://input");
     $post = CJSON::decode($postdata);
     if (isset($post['list'])) {
         MenuTree::cleanMenuItems($post['list']);
         $options = MenuTree::getOptions($class);
         $code = "<?php \n\n" . MenuTree::OPTIONS_COMMENT_START . "\n\$options = " . FormBuilder::formatCode($options, '') . ";\n" . MenuTree::OPTIONS_COMMENT_END . "\n\nreturn " . FormBuilder::formatCode($post['list'], '') . ";";
         file_put_contents(Yii::getPathOfAlias($class) . ".php", $code);
     }
 }
开发者ID:reggi49,项目名称:plansys,代码行数:11,代码来源:GenMenuController.php

示例2: updateFunctionBody

    /**
     * @param string $functionName
     * @param array $fields Parameter
     * @param array $class Parameter
     * @param array $replaceString
     * @return field Fungsi ini digunakan untuk update model.
     */
    public function updateFunctionBody($functionName, $fields, $class = "", $replaceString = null)
    {
        if ($class == "") {
            $using_another_class = false;
            $class = get_class($this->model);
        } else {
            $using_another_class = true;
        }
        ## get class data
        $isNewFunc = false;
        $sourceFile = '';
        extract($this->getLineOfClass($class, $functionName));
        if (is_array($fields)) {
            $fields = FormBuilder::formatCode($fields);
            ## replace multiline string to preserve indentation
            if (is_array($replaceString)) {
                $fields = str_replace(array_keys($replaceString), $replaceString, $fields);
            }
            ## generate function
            $func = <<<EOF
    public function {$functionName}() {
        return {$fields};
    }
EOF;
        } else {
            $func = $fields;
        }
        ## put function to class
        array_splice($file, $line, $length, explode("\n", $func));
        ## adjust other methods line and length
        $newlength = count(explode("\n", $func));
        foreach ($this->methods as $k => $m) {
            if (@$m['line'] >= $line && $k != $functionName) {
                if (!$isNewFunc) {
                    $this->methods[$k]['line'] -= $length;
                }
                $this->methods[$k]['line'] += $newlength;
            }
        }
        $this->methods[$functionName]['length'] = $newlength;
        $this->methods[$functionName]['line'] = $line;
        $this->file = $file;
        $fp = @fopen($sourceFile, 'r+');
        if (!$fp) {
            return false;
        }
        ## write new function to sourceFile
        if (flock($fp, LOCK_EX)) {
            // acquire an exclusive lock
            ftruncate($fp, 0);
            // truncate file
            $buffer = implode("\n", $file);
            //TODO: fix gigantic bug, do not allow more than 200 consecutive spaces
            $buffer = preg_replace('/\\s{200,}/', ' ', $buffer);
            $buffer = str_replace('\\\\\'', '\'', $buffer);
            $file = explode("\n", $buffer);
            fwrite($fp, $buffer);
            fflush($fp);
            // flush output before releasing the lock
            flock($fp, LOCK_UN);
            // release the lock
            Yii::app()->session['FormBuilder_' . $this->originalClass] = ['sourceFile' => $this->sourceFile, 'file' => $file, 'methods' => $this->methods, 'timestamp' => $this->timestamp];
            return true;
        } else {
            echo "ERROR: Couldn't lock source file '{$sourceFile}'!";
            die;
        }
        if (!$using_another_class) {
            ## update model instance
            $this->model = new $class();
        }
    }
开发者ID:balitax,项目名称:plansys,代码行数:79,代码来源:FormBuilder.php

示例3: setOptions

 public static function setOptions($alias, $options)
 {
     $path = Asset::resolveAlias($alias . ".php");
     if (isset($path)) {
         $file = file($path);
         $foundPHP = false;
         $startPHP = 0;
         $startLine = false;
         $lineLength = false;
         foreach ($file as $k => $f) {
             $tf = trim($f);
             if (!$foundPHP) {
                 if (substr($tf, 0, 5) == "<?php") {
                     $foundPHP = true;
                     $startPHP = $k + 1;
                 }
             } else {
                 if ($tf != "") {
                     if (!$startLine) {
                         if ($tf == MenuTree::OPTIONS_COMMENT_START) {
                             $startLine = $k + 1;
                         }
                     } else {
                         if ($startLine && !$lineLength) {
                             if ($tf == MenuTree::OPTIONS_COMMENT_END) {
                                 $lineLength = $k - $startLine;
                             }
                         }
                     }
                 }
             }
         }
         $optionsCode = explode("\n", '$options = ' . FormBuilder::formatCode($options, ""));
         $optionsCode[count($optionsCode) - 1] = $optionsCode[count($optionsCode) - 1] . ";";
         if (!$startLine) {
             array_unshift($optionsCode, MenuTree::OPTIONS_COMMENT_START);
             array_push($optionsCode, MenuTree::OPTIONS_COMMENT_END);
             $lineLength = 0;
             $startLine = $startPHP;
         }
         foreach ($optionsCode as $k => $o) {
             $optionsCode[$k] = $optionsCode[$k] . "\n";
         }
         array_splice($file, $startLine, $lineLength, $optionsCode);
         return implode("", $file);
     }
 }
开发者ID:reggi49,项目名称:plansys,代码行数:47,代码来源:MenuTree.php


注:本文中的FormBuilder::formatCode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。