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


PHP Utils::checkAndWriteIfNeeded方法代码示例

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


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

示例1: createProjectFiles


//.........这里部分代码省略.........
     } else {
         $safeProject = $project;
     }
     /**
      * Round 4. Process extension info
      */
     $phpInfo = $this->processExtensionInfo();
     /**
      * Round 5. Generate Function entries (FE)
      */
     list($feHeader, $feEntries) = $this->generateFunctionInformation();
     /**
      * Check if there are module/request/global destructors
      */
     $destructors = $this->config->get('destructors');
     if (is_array($destructors)) {
         $invokeDestructors = $this->processCodeInjection($destructors);
         $includes = $invokeDestructors[0];
         $destructors = $invokeDestructors[1];
     }
     /**
      * Check if there are module/request/global initializers
      */
     $initializers = $this->config->get('initializers');
     if (is_array($initializers)) {
         $invokeInitializers = $this->processCodeInjection($initializers);
         $includes = $invokeInitializers[0];
         $initializers = $invokeInitializers[1];
     }
     /**
      * Append extra details
      */
     $extraClasses = $this->config->get('extra-classes');
     if (is_array($extraClasses)) {
         foreach ($extraClasses as $value) {
             if (isset($value['init'])) {
                 $completeClassInits[] = 'ZEPHIR_INIT(' . $value['init'] . ')';
             }
             if (isset($value['entry'])) {
                 $completeClassEntries[] = 'zend_class_entry *' . $value['entry'] . ';';
             }
         }
     }
     $toReplace = array('%PROJECT_LOWER_SAFE%' => strtolower($safeProject), '%PROJECT_LOWER%' => strtolower($project), '%PROJECT_UPPER%' => strtoupper($project), '%PROJECT_CAMELIZE%' => ucfirst($project), '%CLASS_ENTRIES%' => implode(PHP_EOL, array_merge($completeInterfaceEntries, $completeClassEntries)), '%CLASS_INITS%' => implode(PHP_EOL . "\t", array_merge($completeInterfaceInits, $completeClassInits)), '%INIT_GLOBALS%' => $globalsDefault, '%EXTENSION_INFO%' => $phpInfo, '%EXTRA_INCLUDES%' => $includes, '%DESTRUCTORS%' => $destructors, '%INITIALIZERS%' => implode(PHP_EOL, array_merge($this->internalInitializers, array($initializers))), '%FE_HEADER%' => $feHeader, '%FE_ENTRIES%' => $feEntries, '%PROJECT_INI_ENTRIES%' => implode(PHP_EOL . "\t", $initEntries));
     foreach ($toReplace as $mark => $replace) {
         $content = str_replace($mark, $replace, $content);
     }
     /**
      * Round 5. Generate and place the entry point of the project
      */
     Utils::checkAndWriteIfNeeded($content, 'ext/' . $safeProject . '.c');
     unset($content);
     /**
      * Round 6. Generate the project main header
      */
     $content = file_get_contents($templatePath . '/project.h');
     if (empty($content)) {
         throw new Exception("Template project.h doesn't exists");
     }
     $includeHeaders = array();
     foreach ($this->compiledFiles as $file) {
         if ($file) {
             $fileH = str_replace(".c", ".zep.h", $file);
             $include = '#include "' . $fileH . '"';
             $includeHeaders[] = $include;
         }
     }
     /**
      * Append extra headers
      */
     $extraClasses = $this->config->get('extra-classes');
     if (is_array($extraClasses)) {
         foreach ($extraClasses as $value) {
             if (isset($value['header'])) {
                 $include = '#include "' . $value['header'] . '"';
                 $includeHeaders[] = $include;
             }
         }
     }
     $toReplace = array('%INCLUDE_HEADERS%' => implode(PHP_EOL, $includeHeaders));
     foreach ($toReplace as $mark => $replace) {
         $content = str_replace($mark, $replace, $content);
     }
     Utils::checkAndWriteIfNeeded($content, 'ext/' . $safeProject . '.h');
     unset($content);
     /**
      * Round 7. Create php_project.h
      */
     $content = file_get_contents($templatePath . '/php_project.h');
     if (empty($content)) {
         throw new Exception('Template php_project.h doesn`t exist');
     }
     $toReplace = array('%PROJECT_LOWER_SAFE%' => strtolower($safeProject), '%PROJECT_LOWER%' => strtolower($project), '%PROJECT_UPPER%' => strtoupper($project), '%PROJECT_EXTNAME%' => strtolower($project), '%PROJECT_NAME%' => utf8_decode($this->config->get('name')), '%PROJECT_AUTHOR%' => utf8_decode($this->config->get('author')), '%PROJECT_VERSION%' => utf8_decode($this->config->get('version')), '%PROJECT_DESCRIPTION%' => utf8_decode($this->config->get('description')), '%PROJECT_ZEPVERSION%' => self::VERSION, '%EXTENSION_GLOBALS%' => $globalCode, '%EXTENSION_STRUCT_GLOBALS%' => $globalStruct);
     foreach ($toReplace as $mark => $replace) {
         $content = str_replace($mark, $replace, $content);
     }
     Utils::checkAndWriteIfNeeded($content, 'ext/php_' . $safeProject . '.h');
     unset($content);
     return $needConfigure;
 }
开发者ID:chet0xhenry,项目名称:zephir,代码行数:101,代码来源:Compiler.php

示例2: genFcallCode

 public function genFcallCode()
 {
     $codePrinter = new CodePrinter();
     $codePrinter->output('#ifndef ZEPHIR_KERNEL_FCALL_INTERNAL_H');
     $codePrinter->output('#define ZEPHIR_KERNEL_FCALL_INTERNAL_H');
     $codePrinter->increaseLevel();
     ksort($this->requiredMacros);
     foreach ($this->requiredMacros as $name => $info) {
         list($scope, $mode, $paramCount) = $info;
         $paramsStr = '';
         $retParam = '';
         $retValueUsed = '0';
         $params = array();
         $zvals = array();
         $initStatements = array();
         $postStatements = array();
         for ($i = 0; $i < $paramCount; ++$i) {
             $params[] = 'p' . $i;
         }
         if ($paramCount) {
             $paramsStr = ', ' . implode(', ', $params);
         }
         if ($mode == 'CALL_INTERNAL_METHOD_P') {
             $retValueUsed = '1';
             $retParam = 'return_value_ptr';
             $initStatements[] = 'ZEPHIR_INIT_NVAR(*(return_value_ptr)); \\';
         }
         $objParam = $scope ? 'scope_ce, ' : 'object, ';
         $macroName = $name . '(' . ($retParam ? $retParam . ', ' : '') . $objParam . 'method' . $paramsStr . ')';
         $codePrinter->output('#define ' . $macroName . ' \\');
         if (!$retParam) {
             $retParam = 'return_value';
         }
         $codePrinter->increaseLevel();
         $codePrinter->output('do { \\');
         $codePrinter->increaseLevel();
         if ($mode == 'CALL_INTERNAL_METHOD_NORETURN_P') {
             $codePrinter->output('zval *rv = NULL; \\');
             $codePrinter->output('zval **rvp = &rv; \\');
             $codePrinter->output('ALLOC_INIT_ZVAL(rv); \\');
             $retParam = 'rvp';
         }
         $codePrinter->output('ZEPHIR_BACKUP_SCOPE() \\');
         $codePrinter->output('ZEPHIR_BACKUP_THIS_PTR() \\');
         if (!$scope) {
             $codePrinter->output('ZEPHIR_SET_THIS(object); \\');
             $codePrinter->output('ZEPHIR_SET_SCOPE((Z_TYPE_P(object) == IS_OBJECT ? Z_OBJCE_P(object) : NULL), (Z_TYPE_P(object) == IS_OBJECT ? Z_OBJCE_P(object) : NULL)); \\');
         } else {
             $codePrinter->output('ZEPHIR_SET_THIS(NULL); \\');
             $codePrinter->output('ZEPHIR_SET_SCOPE(scope_ce, scope_ce); \\');
         }
         /* Create new zval's for parameters */
         for ($i = 0; $i < $paramCount; ++$i) {
             //$zv = '_' . $params[$i];
             //$zvals[] = $zv;
             //$initStatements[] = 'ALLOC_ZVAL(' . $zv . '); \\';
             //$initStatements[] = 'INIT_PZVAL_COPY(' . $zv . ', ' . $params[$i] . '); \\';
             //$postStatements[] = 'zval_ptr_dtor(&' . $zv . '); \\';
             $zv = $params[$i];
             $zvals[] = $zv;
             $initStatements[] = 'Z_ADDREF_P(' . $zv . '); \\';
             $postStatements[] = 'Z_DELREF_P(' . $zv . '); \\';
         }
         if ($i) {
             //$codePrinter->output('zval *' . implode(', *', $zvals) . '; \\');
         }
         foreach ($initStatements as $statement) {
             $codePrinter->output($statement);
         }
         $zvalStr = $i ? ', ' . implode(', ', $zvals) : '';
         $retExpr = '';
         if ($retParam) {
             if ($retParam == 'return_value') {
                 $retExpr = ', return_value, return_value_ptr';
             } else {
                 $retExpr = ', *' . $retParam . ', ' . $retParam;
             }
         }
         $codePrinter->output('method(0' . $retExpr . ', ' . ($scope ? 'NULL, ' : $objParam) . $retValueUsed . $zvalStr . ' TSRMLS_CC); \\');
         if ($mode == 'CALL_INTERNAL_METHOD_NORETURN_P') {
             $postStatements[] = 'zval_ptr_dtor(rvp); \\';
         }
         foreach ($postStatements as $statement) {
             $codePrinter->output($statement);
         }
         $codePrinter->output('ZEPHIR_LAST_CALL_STATUS = EG(exception) ? FAILURE : SUCCESS; \\');
         $codePrinter->output('ZEPHIR_RESTORE_THIS_PTR(); \\');
         $codePrinter->output('ZEPHIR_RESTORE_SCOPE(); \\');
         $codePrinter->decreaseLevel();
         $codePrinter->output('} while (0)');
         $codePrinter->decreaseLevel();
         $codePrinter->output('');
     }
     $codePrinter->decreaseLevel();
     $codePrinter->output("#endif");
     Utils::checkAndWriteIfNeeded($codePrinter->getOutput(), 'ext/kernel/fcall_internal.h');
 }
开发者ID:chet0xhenry,项目名称:zephir,代码行数:97,代码来源:FcallManager.php

示例3: createProjectFiles


//.........这里部分代码省略.........
             $dependencyRank = $classDefinition->getDependencyRank();
             if ($classDefinition->getType() == 'class') {
                 if (!isset($classInits[$dependencyRank])) {
                     $classEntries[$dependencyRank] = array();
                     $classInits[$dependencyRank] = array();
                 }
                 $classEntries[$dependencyRank][] = 'zend_class_entry *' . $classDefinition->getClassEntry() . ';';
                 $classInits[$dependencyRank][] = 'ZEPHIR_INIT(' . $classDefinition->getCNamespace() . '_' . $classDefinition->getName() . ');';
             } else {
                 if (!isset($interfaceInits[$dependencyRank])) {
                     $interfaceEntries[$dependencyRank] = array();
                     $interfaceInits[$dependencyRank] = array();
                 }
                 $interfaceEntries[$dependencyRank][] = 'zend_class_entry *' . $classDefinition->getClassEntry() . ';';
                 $interfaceInits[$dependencyRank][] = 'ZEPHIR_INIT(' . $classDefinition->getCNamespace() . '_' . $classDefinition->getName() . ');';
             }
         }
     }
     krsort($classInits);
     krsort($classEntries);
     krsort($interfaceInits);
     krsort($interfaceEntries);
     $completeInterfaceInits = array();
     foreach ($interfaceInits as $rankInterfaceInits) {
         asort($rankInterfaceInits, SORT_STRING);
         $completeInterfaceInits = array_merge($completeInterfaceInits, $rankInterfaceInits);
     }
     $completeInterfaceEntries = array();
     foreach ($interfaceEntries as $rankInterfaceEntries) {
         asort($rankInterfaceEntries, SORT_STRING);
         $completeInterfaceEntries = array_merge($completeInterfaceEntries, $rankInterfaceEntries);
     }
     $completeClassInits = array();
     foreach ($classInits as $rankClassInits) {
         asort($rankClassInits, SORT_STRING);
         $completeClassInits = array_merge($completeClassInits, $rankClassInits);
     }
     $completeClassEntries = array();
     foreach ($classEntries as $rankClassEntries) {
         asort($rankClassEntries, SORT_STRING);
         $completeClassEntries = array_merge($completeClassEntries, $rankClassEntries);
     }
     /**
      * Round 3. Process extension globals
      */
     list($globalCode, $globalStruct, $globalsDefault) = $this->processExtensionGlobals($project);
     if ($project == 'zend') {
         $safeProject = 'zend_';
     } else {
         $safeProject = $project;
     }
     /**
      * Round 4. Process extension info
      */
     $phpInfo = $this->processExtensionInfo();
     $toReplace = array('%PROJECT_LOWER_SAFE%' => strtolower($safeProject), '%PROJECT_LOWER%' => strtolower($project), '%PROJECT_UPPER%' => strtoupper($project), '%PROJECT_CAMELIZE%' => ucfirst($project), '%CLASS_ENTRIES%' => implode(PHP_EOL, array_merge($completeInterfaceEntries, $completeClassEntries)), '%CLASS_INITS%' => implode(PHP_EOL . "\t", array_merge($completeInterfaceInits, $completeClassInits)), '%INIT_GLOBALS%' => $globalsDefault, '%EXTENSION_INFO%' => $phpInfo);
     foreach ($toReplace as $mark => $replace) {
         $content = str_replace($mark, $replace, $content);
     }
     /**
      * Round 5. Generate and place the entry point of the project
      */
     Utils::checkAndWriteIfNeeded($content, 'ext/' . $safeProject . '.c');
     unset($content);
     /**
      * Round 6. Generate the project main header
      */
     $content = file_get_contents(__DIR__ . '/../templates/project.h');
     if (empty($content)) {
         throw new Exception("Template project.h doesn't exists");
     }
     $includeHeaders = array();
     foreach ($this->compiledFiles as $file) {
         if ($file) {
             $fileH = str_replace(".c", ".zep.h", $file);
             $include = '#include "' . $fileH . '"';
             $includeHeaders[] = $include;
         }
     }
     $toReplace = array('%INCLUDE_HEADERS%' => implode(PHP_EOL, $includeHeaders));
     foreach ($toReplace as $mark => $replace) {
         $content = str_replace($mark, $replace, $content);
     }
     Utils::checkAndWriteIfNeeded($content, 'ext/' . $safeProject . '.h');
     unset($content);
     /**
      * Round 7. Create php_project.h
      */
     $content = file_get_contents(__DIR__ . '/../templates/php_project.h');
     if (empty($content)) {
         throw new Exception('Template php_project.h doesn`t exist');
     }
     $toReplace = array('%PROJECT_LOWER_SAFE%' => strtolower($safeProject), '%PROJECT_LOWER%' => strtolower($project), '%PROJECT_UPPER%' => strtoupper($project), '%PROJECT_EXTNAME%' => strtolower($project), '%PROJECT_NAME%' => utf8_decode($this->config->get('name')), '%PROJECT_AUTHOR%' => utf8_decode($this->config->get('author')), '%PROJECT_VERSION%' => utf8_decode($this->config->get('version')), '%PROJECT_DESCRIPTION%' => utf8_decode($this->config->get('description')), '%PROJECT_ZEPVERSION%' => self::VERSION, '%EXTENSION_GLOBALS%' => $globalCode, '%EXTENSION_STRUCT_GLOBALS%' => $globalStruct);
     foreach ($toReplace as $mark => $replace) {
         $content = str_replace($mark, $replace, $content);
     }
     Utils::checkAndWriteIfNeeded($content, 'ext/php_' . $safeProject . '.h');
     unset($content);
     return $needConfigure;
 }
开发者ID:NumbDai,项目名称:zephir,代码行数:101,代码来源:Compiler.php

示例4: genConcatCode


//.........这里部分代码省略.........
            $sparams = array();
            $lparams = array();
            for ($i = 0; $i < $len; $i++) {
                $n = $i + 1;
                $t = substr($key, $i, 1);
                $sparams[] = 'op' . $n;
                if ($t == 's') {
                    $params[] = 'const char *op' . $n . ', zend_uint op' . $n . '_len';
                    $lparams[] = 'op' . $n . ', sizeof(op' . $n . ')-1';
                    $lengths[] = 'op' . $n . '_len';
                    $svars[] = $n;
                    $avars[$n] = 's';
                } else {
                    $params[] = 'zval *op' . $n;
                    $lparams[] = 'op' . $n;
                    $zvalCopy[] = 'op' . $n . '_copy';
                    $useCopy[] = 'use_copy' . $n . ' = 0';
                    $lengths[] = 'Z_STRLEN_P(op' . $n . ')';
                    $zvars[] = $n;
                    $avars[$n] = 'v';
                }
            }
            $macros[] = '#define ZEPHIR_CONCAT_' . strtoupper($key) . '(result, ' . join(', ', $sparams) . ') \\' . PHP_EOL . "\t" . ' zephir_concat_' . $key . '(result, ' . join(', ', $lparams) . ', 0);';
            $macros[] = '#define ZEPHIR_SCONCAT_' . strtoupper($key) . '(result, ' . join(', ', $sparams) . ') \\' . PHP_EOL . "\t" . ' zephir_concat_' . $key . '(result, ' . join(', ', $lparams) . ', 1);';
            $macros[] = '';
            $proto = 'void zephir_concat_' . $key . '(zval *result, ' . join(', ', $params) . ', int self_var)';
            $proto = 'void zephir_concat_' . $key . '(zval *result, ' . join(', ', $params) . ', int self_var)';
            $codeh .= '' . $proto . ';' . PHP_EOL;
            $code .= $proto . '{' . PHP_EOL . PHP_EOL;
            if (count($zvalCopy)) {
                $code .= "\t" . 'zval result_copy, ' . join(', ', $zvalCopy) . ';' . PHP_EOL;
                $code .= "\t" . 'int use_copy = 0, ' . join(', ', $useCopy) . ';' . PHP_EOL;
            } else {
                $code .= "\t" . 'zval result_copy;' . PHP_EOL;
                $code .= "\t" . 'int use_copy = 0;' . PHP_EOL;
            }
            $code .= "\t" . 'uint offset = 0, length;' . PHP_EOL . PHP_EOL;
            foreach ($zvars as $zvar) {
                $code .= "\t" . 'if (Z_TYPE_P(op' . $zvar . ') != IS_STRING) {' . PHP_EOL;
                $code .= "\t" . '   use_copy' . $zvar . ' = zend_make_printable_zval(op' . $zvar . ', &op' . $zvar . '_copy);' . PHP_EOL;
                $code .= "\t" . '   if (use_copy' . $zvar . ') {' . PHP_EOL;
                $code .= "\t" . '       op' . $zvar . ' = &op' . $zvar . '_copy;' . PHP_EOL;
                $code .= "\t" . '   }' . PHP_EOL;
                $code .= "\t" . '}' . PHP_EOL . PHP_EOL;
            }
            $code .= "\t" . 'length = ' . join(' + ', $lengths) . ';' . PHP_EOL;
            $code .= "\t" . 'if (self_var) {' . PHP_EOL;
            $code .= '' . PHP_EOL;
            $code .= "\t\t" . 'if (Z_TYPE_P(result) != IS_STRING) {' . PHP_EOL;
            $code .= "\t\t\t" . 'use_copy = zend_make_printable_zval(result, &result_copy);' . PHP_EOL;
            $code .= "\t\t\t" . 'if (use_copy) {' . PHP_EOL;
            $code .= "\t\t\t\t" . 'ZEPHIR_CPY_WRT_CTOR(result, (&result_copy));' . PHP_EOL;
            $code .= "\t\t\t" . '}' . PHP_EOL;
            $code .= "\t\t" . '}' . PHP_EOL . PHP_EOL;
            $code .= "\t\t" . 'offset = Z_STRLEN_P(result);' . PHP_EOL;
            $code .= "\t\t" . 'length += offset;' . PHP_EOL;
            $code .= "\t\t" . 'Z_STR_P(result) = zend_string_realloc(Z_STR_P(result), length, 0);' . PHP_EOL;
            $code .= '' . PHP_EOL;
            $code .= "\t" . '} else {' . PHP_EOL;
            $code .= "\t\t" . 'ZVAL_STR(result, zend_string_alloc(length, 0));' . PHP_EOL;
            $code .= "\t" . '}' . PHP_EOL . PHP_EOL;
            $position = '';
            foreach ($avars as $n => $type) {
                if ($type == 's') {
                    $code .= "\t" . 'memcpy(Z_STRVAL_P(result) + offset' . $position . ', op' . $n . ', op' . $n . '_len);' . PHP_EOL;
                    $position .= ' + op' . $n . '_len';
                } else {
                    $code .= "\t" . 'memcpy(Z_STRVAL_P(result) + offset' . $position . ', Z_STRVAL_P(op' . $n . '), Z_STRLEN_P(op' . $n . '));' . PHP_EOL;
                    $position .= ' + Z_STRLEN_P(op' . $n . ')';
                }
            }
            $code .= "\t" . 'Z_STRVAL_P(result)[length] = 0;' . PHP_EOL;
            $code .= "\t" . 'zend_string_forget_hash_val(Z_STR_P(result));' . PHP_EOL;
            foreach ($zvars as $zvar) {
                $code .= "\t" . 'if (use_copy' . $zvar . ') {' . PHP_EOL;
                $code .= "\t" . '   zval_dtor(op' . $zvar . ');' . PHP_EOL;
                $code .= "\t" . '}' . PHP_EOL . PHP_EOL;
            }
            $code .= "\t" . 'if (use_copy) {' . PHP_EOL;
            $code .= "\t" . '   zval_dtor(&result_copy);' . PHP_EOL;
            $code .= "\t" . '}' . PHP_EOL . PHP_EOL;
            $code .= "}" . PHP_EOL . PHP_EOL;
        }
        $code .= <<<EOF
void zephir_concat_function(zval *result, zval *op1, zval *op2) /* {{{ */
{
    zval tmp;
    /* Force separate zval, if op2=result will be reallocated */
    if (unlikely(result == op2)) {
        ZVAL_COPY_VALUE(&tmp, op2);
        op2 = &tmp;
    }

    concat_function(result, op1, op2 TSRMLS_CC);
}
EOF;
        $codeh .= "void zephir_concat_function(zval *result, zval *op1, zval *op2);\n#endif /* ZEPHIR_KERNEL_CONCAT_H */\n";
        Utils::checkAndWriteIfNeeded($pcodeh . join(PHP_EOL, $macros) . PHP_EOL . PHP_EOL . $codeh, 'ext/kernel/concat.h');
        Utils::checkAndWriteIfNeeded($code, 'ext/kernel/concat.c');
    }
开发者ID:chet0xhenry,项目名称:zephir,代码行数:101,代码来源:StringsManager.php


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